User Interface, Wifi timeout
This commit is contained in:
parent
af25c8af80
commit
3f04aa1c41
|
|
@ -11,9 +11,9 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||||
<span id="state"></span><br/><br/>
|
<span id="state"></span><br/><br/>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<button class="prev-button" onmouseup="simpleGetCall('prev');" ontouchend="simpleGetCall('prev');"></button>
|
<button class="prev-button" onclick="simpleGetCall('prev');""></button>
|
||||||
<button class="play-button" onmouseup="simpleGetCall('toggleplaypause');" ontouchend="simpleGetCall('toggleplaypause');"></button>
|
<button class="play-button" onclick="simpleGetCall('toggleplaypause');"></button>
|
||||||
<button class="next-button" onmouseup="simpleGetCall('next');" ontouchend="simpleGetCall('next');"></button><br/><br/>
|
<button class="next-button" onclick="simpleGetCall('next');"></button><br/><br/>
|
||||||
</div>
|
</div>
|
||||||
<div class="slidecontainer">
|
<div class="slidecontainer">
|
||||||
<label for="progress" id="progressLabel"></label>
|
<label for="progress" id="progressLabel"></label>
|
||||||
|
|
@ -23,7 +23,7 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||||
</div>
|
</div>
|
||||||
<div class="slidecontainer">
|
<div class="slidecontainer">
|
||||||
<label for="volume">Vol</label>
|
<label for="volume">Vol</label>
|
||||||
<input name="volume" type="range" min="0" max="21" value="12" class="slider" id="volumeSlider"
|
<input name="volume" type="range" min="0" max="15" value="7" class="slider" id="volumeSlider"
|
||||||
onmouseup="postValue('volume',document.getElementById('volumeSlider').value);"
|
onmouseup="postValue('volume',document.getElementById('volumeSlider').value);"
|
||||||
ontouchend="postValue('volume',document.getElementById('volumeSlider').value);">
|
ontouchend="postValue('volume',document.getElementById('volumeSlider').value);">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ void writeFile(fs::FS &fs, const char * path, const char * message){
|
||||||
|
|
||||||
unsigned long lastStart = 0;
|
unsigned long lastStart = 0;
|
||||||
|
|
||||||
|
uint8_t buttontoignore = 0;
|
||||||
|
|
||||||
const int startDelay = 250;
|
const int startDelay = 250;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
107
src/main.cpp
107
src/main.cpp
|
|
@ -8,7 +8,6 @@
|
||||||
#include <ESPAsyncWiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
|
#include <ESPAsyncWiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Audio.h"
|
#include "Audio.h"
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
@ -26,9 +25,9 @@
|
||||||
#define I2S_BCLK 27 // connect to DAC pin BCK
|
#define I2S_BCLK 27 // connect to DAC pin BCK
|
||||||
#define I2S_LRC 25 // connect to DAC pin LCK
|
#define I2S_LRC 25 // connect to DAC pin LCK
|
||||||
|
|
||||||
#define BTN_START_STOP 17 // Button on XX and GND
|
#define BTN_START_STOP 4 // Button on XX and GND
|
||||||
#define BTN_NEXT 16
|
#define BTN_NEXT 17
|
||||||
#define BTN_PREV 4
|
#define BTN_PREV 16
|
||||||
|
|
||||||
#define CS_SDCARD 22
|
#define CS_SDCARD 22
|
||||||
|
|
||||||
|
|
@ -44,7 +43,7 @@ File mp3File;
|
||||||
|
|
||||||
Audio audio;
|
Audio audio;
|
||||||
|
|
||||||
uint volume = 8;
|
uint volume = 7;
|
||||||
|
|
||||||
uint rfid_loop = RFID_LOOP_INTERVAL;
|
uint rfid_loop = RFID_LOOP_INTERVAL;
|
||||||
|
|
||||||
|
|
@ -93,7 +92,8 @@ void deactivateRFID()
|
||||||
digitalWrite(CS_RFID, HIGH);
|
digitalWrite(CS_RFID, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void playSongByName(String song) {
|
void playSongByName(String song)
|
||||||
|
{
|
||||||
currentNode = rootNode.advanceToMP3(&song);
|
currentNode = rootNode.advanceToMP3(&song);
|
||||||
String mp3File = currentNode->getCurrentPlayingFilePath();
|
String mp3File = currentNode->getCurrentPlayingFilePath();
|
||||||
Serial.println(mp3File.c_str());
|
Serial.println(mp3File.c_str());
|
||||||
|
|
@ -104,12 +104,12 @@ void playSongByName(String song) {
|
||||||
deactivateSD();
|
deactivateSD();
|
||||||
}
|
}
|
||||||
|
|
||||||
void playSongByRFID(String id) {
|
void playSongByRFID(String id)
|
||||||
|
{
|
||||||
String song = rfid_map[id];
|
String song = rfid_map[id];
|
||||||
Serial.println("searching for ");
|
Serial.println("searching for ");
|
||||||
Serial.println(song);
|
Serial.println(song);
|
||||||
playSongByName(song);
|
playSongByName(song);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -120,12 +120,11 @@ void playSongByRFID(String id) {
|
||||||
* @return true
|
* @return true
|
||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
bool playFile(const char* filename, uint32_t resumeFilePos) {
|
bool playFile(const char *filename, uint32_t resumeFilePos)
|
||||||
|
{
|
||||||
return audio.connecttoSD(filename, resumeFilePos);
|
return audio.connecttoSD(filename, resumeFilePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void playNextMp3()
|
void playNextMp3()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
|
|
@ -142,7 +141,8 @@ void playNextMp3()
|
||||||
currentNode = rootNode.advanceToNextMP3(currentNode->getCurrentPlaying());
|
currentNode = rootNode.advanceToNextMP3(currentNode->getCurrentPlaying());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentNode!=NULL) {
|
if (currentNode != NULL)
|
||||||
|
{
|
||||||
currentNode->setSecondsPlayed(0);
|
currentNode->setSecondsPlayed(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,7 +191,6 @@ String getState()
|
||||||
String output;
|
String output;
|
||||||
serializeJson(jsonState, output);
|
serializeJson(jsonState, output);
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String processor(const String &var)
|
String processor(const String &var)
|
||||||
|
|
@ -209,7 +208,8 @@ void stop()
|
||||||
{
|
{
|
||||||
Serial.println("stopping audio.");
|
Serial.println("stopping audio.");
|
||||||
audio.stopSong();
|
audio.stopSong();
|
||||||
if (currentNode!=NULL) {
|
if (currentNode != NULL)
|
||||||
|
{
|
||||||
currentNode->setSecondsPlayed(0);
|
currentNode->setSecondsPlayed(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -231,7 +231,9 @@ void togglePlayPause()
|
||||||
if (currentNode != NULL)
|
if (currentNode != NULL)
|
||||||
{
|
{
|
||||||
audio.pauseResume();
|
audio.pauseResume();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
playNextMp3();
|
playNextMp3();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -280,10 +282,7 @@ void setup()
|
||||||
deactivateRFID();
|
deactivateRFID();
|
||||||
activateSD();
|
activateSD();
|
||||||
|
|
||||||
// first parameter is name of access point, second is the password
|
|
||||||
AsyncWiFiManager wifiManager(&server, &dns);
|
|
||||||
|
|
||||||
wifiManager.autoConnect("HannaBox");
|
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
|
|
@ -321,6 +320,13 @@ void setup()
|
||||||
|
|
||||||
Serial.println("Audio initialized.");
|
Serial.println("Audio initialized.");
|
||||||
|
|
||||||
|
// first parameter is name of access point, second is the password
|
||||||
|
AsyncWiFiManager wifiManager(&server, &dns);
|
||||||
|
|
||||||
|
wifiManager.setTimeout(180);
|
||||||
|
|
||||||
|
if (wifiManager.autoConnect("HannaBox"))
|
||||||
|
{
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
{ request->send_P(200, "text/html", index_html, processor); });
|
{ request->send_P(200, "text/html", index_html, processor); });
|
||||||
|
|
||||||
|
|
@ -338,7 +344,6 @@ void setup()
|
||||||
request->send(200, "text/plain", "start");
|
request->send(200, "text/plain", "start");
|
||||||
start(); });
|
start(); });
|
||||||
|
|
||||||
|
|
||||||
server.on("/toggleplaypause", HTTP_GET, [](AsyncWebServerRequest *request)
|
server.on("/toggleplaypause", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -364,6 +369,10 @@ void setup()
|
||||||
server.on("/volume", HTTP_POST, volume_action);
|
server.on("/volume", HTTP_POST, volume_action);
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
|
Serial.println("Wifi initialized.");
|
||||||
|
} else {
|
||||||
|
Serial.println("Wifi timed out. Fallback no Wifi.");
|
||||||
|
}
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
loop2, /* Function to implement the task */
|
loop2, /* Function to implement the task */
|
||||||
|
|
@ -377,42 +386,51 @@ void setup()
|
||||||
Serial.println("initialization done.");
|
Serial.println("initialization done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void named_song_action(AsyncWebServerRequest *request) {
|
void named_song_action(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
Serial.println("named song!");
|
Serial.println("named song!");
|
||||||
|
|
||||||
int params = request->params();
|
int params = request->params();
|
||||||
for (int i = 0; i < params; i++) {
|
for (int i = 0; i < params; i++)
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam(i);
|
AsyncWebParameter *p = request->getParam(i);
|
||||||
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||||
if (p->name()=="title") {
|
if (p->name() == "title")
|
||||||
|
{
|
||||||
playSongByName(p->value());
|
playSongByName(p->value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request->send_P(200, "text/plain", "ok");
|
request->send_P(200, "text/plain", "ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
void progress_action(AsyncWebServerRequest *request) {
|
void progress_action(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
Serial.println("progress!");
|
Serial.println("progress!");
|
||||||
|
|
||||||
int params = request->params();
|
int params = request->params();
|
||||||
for (int i = 0; i < params; i++) {
|
for (int i = 0; i < params; i++)
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam(i);
|
AsyncWebParameter *p = request->getParam(i);
|
||||||
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||||
if (p->name()=="value") {
|
if (p->name() == "value")
|
||||||
|
{
|
||||||
audio.setAudioPlayPosition(atoi(p->value().c_str()));
|
audio.setAudioPlayPosition(atoi(p->value().c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request->send_P(200, "text/plain", "ok");
|
request->send_P(200, "text/plain", "ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
void volume_action(AsyncWebServerRequest *request) {
|
void volume_action(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
Serial.println("volume!");
|
Serial.println("volume!");
|
||||||
|
|
||||||
int params = request->params();
|
int params = request->params();
|
||||||
for (int i = 0; i < params; i++) {
|
for (int i = 0; i < params; i++)
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam(i);
|
AsyncWebParameter *p = request->getParam(i);
|
||||||
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||||
if (p->name()=="value") {
|
if (p->name() == "value")
|
||||||
|
{
|
||||||
audio.setVolume(atoi(p->value().c_str()));
|
audio.setVolume(atoi(p->value().c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -423,31 +441,40 @@ void loop()
|
||||||
{
|
{
|
||||||
if (audio.isRunning())
|
if (audio.isRunning())
|
||||||
{
|
{
|
||||||
if (asyncStop) {
|
if (asyncStop)
|
||||||
|
{
|
||||||
asyncStop = false;
|
asyncStop = false;
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
deactivateRFID();
|
deactivateRFID();
|
||||||
activateSD();
|
activateSD();
|
||||||
audio.loop();
|
audio.loop();
|
||||||
if (currentNode!=NULL) {
|
if (currentNode != NULL)
|
||||||
|
{
|
||||||
currentNode->setSecondsPlayed(audio.getAudioCurrentTime());
|
currentNode->setSecondsPlayed(audio.getAudioCurrentTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivateSD();
|
deactivateSD();
|
||||||
activateRFID();
|
activateRFID();
|
||||||
} else if (asyncStart) {
|
}
|
||||||
|
else if (asyncStart)
|
||||||
|
{
|
||||||
asyncStart = false;
|
asyncStart = false;
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asyncTogglePlayPause) {
|
if (asyncTogglePlayPause)
|
||||||
|
{
|
||||||
asyncTogglePlayPause = false;
|
asyncTogglePlayPause = false;
|
||||||
togglePlayPause();
|
togglePlayPause();
|
||||||
} else if (asyncNext) {
|
}
|
||||||
|
else if (asyncNext)
|
||||||
|
{
|
||||||
asyncNext = false;
|
asyncNext = false;
|
||||||
next();
|
next();
|
||||||
} else if (asyncPrev) {
|
}
|
||||||
|
else if (asyncPrev)
|
||||||
|
{
|
||||||
asyncPrev = false;
|
asyncPrev = false;
|
||||||
Serial.println("Previous not yet implemented!");
|
Serial.println("Previous not yet implemented!");
|
||||||
}
|
}
|
||||||
|
|
@ -476,10 +503,12 @@ void loop2(void *parameter)
|
||||||
{
|
{
|
||||||
asyncTogglePlayPause = true;
|
asyncTogglePlayPause = true;
|
||||||
}
|
}
|
||||||
if (buttonPressed(BTN_NEXT)) {
|
if (buttonPressed(BTN_NEXT))
|
||||||
|
{
|
||||||
asyncNext = true;
|
asyncNext = true;
|
||||||
}
|
}
|
||||||
if (buttonPressed(BTN_PREV)) {
|
if (buttonPressed(BTN_PREV))
|
||||||
|
{
|
||||||
asyncPrev = true;
|
asyncPrev = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -488,7 +517,7 @@ void loop2(void *parameter)
|
||||||
boolean buttonPressed(const uint8_t pin)
|
boolean buttonPressed(const uint8_t pin)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (digitalRead(pin) == LOW)
|
if (digitalRead(pin) == LOW && buttontoignore != pin)
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
@ -496,8 +525,12 @@ boolean buttonPressed(const uint8_t pin)
|
||||||
{
|
{
|
||||||
lastStart = now;
|
lastStart = now;
|
||||||
Serial.println("button pressed.");
|
Serial.println("button pressed.");
|
||||||
|
buttontoignore = pin;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else if (digitalRead(pin) == HIGH && buttontoignore == pin) {
|
||||||
|
buttontoignore = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue