mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-11-24 00:48:03 +01:00
Always display wifi info
This commit is contained in:
parent
80373ae5fb
commit
b640bce997
4 changed files with 54 additions and 20 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -36,7 +36,8 @@
|
||||||
.LSOverride
|
.LSOverride
|
||||||
|
|
||||||
# Icon must end with two \r
|
# Icon must end with two \r
|
||||||
Icon
|
Icon
|
||||||
|
|
||||||
|
|
||||||
# Thumbnails
|
# Thumbnails
|
||||||
._*
|
._*
|
||||||
|
@ -58,4 +59,5 @@ Temporary Items
|
||||||
.apdisk
|
.apdisk
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/osx
|
# End of https://www.toptal.com/developers/gitignore/api/osx
|
||||||
creds.h
|
creds*.h
|
||||||
|
!creds.dist.h
|
||||||
|
|
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
@ -8,6 +8,8 @@
|
||||||
"vector": "cpp",
|
"vector": "cpp",
|
||||||
"string_view": "cpp",
|
"string_view": "cpp",
|
||||||
"initializer_list": "cpp",
|
"initializer_list": "cpp",
|
||||||
"regex": "cpp"
|
"regex": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"system_error": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
// Copy to creds.h and edit
|
// Copy to creds.h or creds_ap.h and edit
|
||||||
const char *ssid = "buzzer";
|
const char *ssid = "buzzer";
|
||||||
const char *password = "123456789";
|
const char *password = "123456789";
|
||||||
|
|
62
src/main.cpp
62
src/main.cpp
|
@ -7,9 +7,16 @@
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
#include "creds.h"
|
|
||||||
|
|
||||||
// #define B_WIFI_AP
|
// Toggle on to switch to AP mode.
|
||||||
|
// Leave commented for wifi station mode.
|
||||||
|
//#define B_WIFI_AP
|
||||||
|
|
||||||
|
#ifdef B_WIFI_AP
|
||||||
|
#include "creds_ap.h"
|
||||||
|
#else
|
||||||
|
#include "creds.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define I2S_DOUT 32
|
#define I2S_DOUT 32
|
||||||
#define I2S_BCLK 25
|
#define I2S_BCLK 25
|
||||||
|
@ -29,6 +36,12 @@
|
||||||
#define OLED_RESET -1
|
#define OLED_RESET -1
|
||||||
#define SCREEN_ADDRESS 0x3C
|
#define SCREEN_ADDRESS 0x3C
|
||||||
|
|
||||||
|
#define SCREEN_MSG_X 0
|
||||||
|
#define SCREEN_MSG_Y 24
|
||||||
|
|
||||||
|
#define VOLUME_MIN 0
|
||||||
|
#define VOLUME_MAX 21
|
||||||
|
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
String selectedFile = "";
|
String selectedFile = "";
|
||||||
|
@ -37,17 +50,22 @@ AsyncWebServer server(80);
|
||||||
Audio audio;
|
Audio audio;
|
||||||
|
|
||||||
byte buttonLastState = HIGH;
|
byte buttonLastState = HIGH;
|
||||||
byte currentVolume = 15;
|
byte currentVolume = 2;
|
||||||
|
|
||||||
bool fileIsValid(String fileName) {
|
bool fileIsValid(String fileName) {
|
||||||
return !fileName.startsWith(".") && (fileName.endsWith(".mp3") || fileName.endsWith(".aac") || fileName.endsWith(".wav"));
|
return !fileName.startsWith(".") && (fileName.endsWith(".mp3") || fileName.endsWith(".aac") || fileName.endsWith(".wav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearMessageArea() {
|
||||||
|
display.drawRect(SCREEN_MSG_X, SCREEN_MSG_Y, SCREEN_WIDTH - SCREEN_MSG_X, SCREEN_HEIGHT - SCREEN_MSG_Y, BLACK);
|
||||||
|
display.display();
|
||||||
|
display.setCursor(SCREEN_MSG_X, SCREEN_MSG_Y);
|
||||||
|
}
|
||||||
|
|
||||||
void displayText(String text) {
|
void displayText(String text) {
|
||||||
display.clearDisplay();
|
clearMessageArea();
|
||||||
display.setCursor(0, 0);
|
display.println(text);
|
||||||
display.println(text);
|
display.display();
|
||||||
display.display();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void play()
|
void play()
|
||||||
|
@ -113,13 +131,16 @@ void onChangeVolume(AsyncWebServerRequest *request)
|
||||||
String s_modifier = request->getParam("modifier", true)->value();
|
String s_modifier = request->getParam("modifier", true)->value();
|
||||||
int modifier = s_modifier.toInt();
|
int modifier = s_modifier.toInt();
|
||||||
currentVolume += modifier;
|
currentVolume += modifier;
|
||||||
if (currentVolume > 21)
|
if (currentVolume > VOLUME_MAX)
|
||||||
currentVolume = 21;
|
currentVolume = VOLUME_MAX;
|
||||||
else if (currentVolume < 0)
|
else if (currentVolume < VOLUME_MIN)
|
||||||
currentVolume = 0;
|
currentVolume = VOLUME_MIN;
|
||||||
audio.setVolume(currentVolume);
|
audio.setVolume(currentVolume);
|
||||||
Serial.print(currentVolume);
|
Serial.print(currentVolume);
|
||||||
displayText("Volume : " + currentVolume);
|
clearMessageArea();
|
||||||
|
display.print("Volume : ");
|
||||||
|
display.println(currentVolume);
|
||||||
|
display.display();
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
onStatus(request);
|
onStatus(request);
|
||||||
|
@ -140,7 +161,7 @@ void setup()
|
||||||
}
|
}
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(WHITE);
|
display.setTextColor(WHITE, BLACK);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println("Chargement...");
|
display.println("Chargement...");
|
||||||
display.display();
|
display.display();
|
||||||
|
@ -185,12 +206,18 @@ void setup()
|
||||||
file = root.openNextFile();
|
file = root.openNextFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setCursor(0, 0);
|
||||||
// Wifi
|
// Wifi
|
||||||
#ifdef B_WIFI_AP
|
#ifdef B_WIFI_AP
|
||||||
Serial.println("Setting up AP...");
|
Serial.println("Setting up AP...");
|
||||||
WiFi.softAP(ssid, password);
|
WiFi.softAP(ssid, password);
|
||||||
String wifiIP = WiFi.softAPIP().toString();
|
String wifiIP = WiFi.softAPIP().toString();
|
||||||
String wifiMode = "AP";
|
String wifiMode = "AP";
|
||||||
|
display.print("Wifi: ");
|
||||||
|
display.println(ssid);
|
||||||
|
display.print("Pass: ");
|
||||||
|
display.println(password);
|
||||||
#else
|
#else
|
||||||
Serial.print("Connecting to wifi...");
|
Serial.print("Connecting to wifi...");
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
@ -205,7 +232,8 @@ void setup()
|
||||||
#endif
|
#endif
|
||||||
String wifiMessage = wifiMode + " IP: " + wifiIP;
|
String wifiMessage = wifiMode + " IP: " + wifiIP;
|
||||||
Serial.println(wifiMessage);
|
Serial.println(wifiMessage);
|
||||||
display.println(wifiMessage);
|
display.print("IP: ");
|
||||||
|
display.println(wifiIP);
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
|
@ -219,11 +247,13 @@ void setup()
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
Serial.println("Server ready!");
|
Serial.println("Server ready!");
|
||||||
displayText("Pret !");
|
clearMessageArea();
|
||||||
|
display.println("Pret !");
|
||||||
|
display.display();
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
||||||
audio.setVolume(currentVolume); // Max 21
|
audio.setVolume(currentVolume);
|
||||||
|
|
||||||
// Setup is done, light up the LED
|
// Setup is done, light up the LED
|
||||||
digitalWrite(LED, HIGH);
|
digitalWrite(LED, HIGH);
|
||||||
|
|
Loading…
Reference in a new issue