deep sleep
This commit is contained in:
parent
3f04aa1c41
commit
21119603cb
|
|
@ -54,8 +54,13 @@ void writeFile(fs::FS &fs, const char * path, const char * message){
|
||||||
|
|
||||||
unsigned long lastStart = 0;
|
unsigned long lastStart = 0;
|
||||||
|
|
||||||
|
unsigned long lastInteraction = 0;
|
||||||
|
|
||||||
uint8_t buttontoignore = 0;
|
uint8_t buttontoignore = 0;
|
||||||
|
|
||||||
const int startDelay = 250;
|
const int startDelay = 250;
|
||||||
|
|
||||||
|
// wait until deep sleep:
|
||||||
|
const long sleepDelay = 1800000;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
21
src/main.cpp
21
src/main.cpp
|
|
@ -236,11 +236,13 @@ void togglePlayPause()
|
||||||
{
|
{
|
||||||
playNextMp3();
|
playNextMp3();
|
||||||
}
|
}
|
||||||
|
lastInteraction = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
void next()
|
void next()
|
||||||
{
|
{
|
||||||
playNextMp3();
|
playNextMp3();
|
||||||
|
lastInteraction = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_eof_mp3(const char *info)
|
void audio_eof_mp3(const char *info)
|
||||||
|
|
@ -262,12 +264,14 @@ void readRFID()
|
||||||
String uidString = getRFIDString(rfid.uid.uidByte);
|
String uidString = getRFIDString(rfid.uid.uidByte);
|
||||||
Serial.println(uidString);
|
Serial.println(uidString);
|
||||||
playSongByRFID(uidString);
|
playSongByRFID(uidString);
|
||||||
|
lastInteraction = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
|
||||||
pinMode(BTN_START_STOP, INPUT_PULLUP);
|
pinMode(BTN_START_STOP, INPUT_PULLUP);
|
||||||
pinMode(BTN_NEXT, INPUT_PULLUP);
|
pinMode(BTN_NEXT, INPUT_PULLUP);
|
||||||
|
|
@ -282,7 +286,8 @@ void setup()
|
||||||
deactivateRFID();
|
deactivateRFID();
|
||||||
activateSD();
|
activateSD();
|
||||||
|
|
||||||
|
//deep sleep wakeup
|
||||||
|
esp_sleep_enable_ext0_wakeup((gpio_num_t)BTN_START_STOP, LOW);
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
|
|
@ -383,6 +388,7 @@ void setup()
|
||||||
&RfidTask, /* Task handle. */
|
&RfidTask, /* Task handle. */
|
||||||
0); /* Core where the task should run */
|
0); /* Core where the task should run */
|
||||||
|
|
||||||
|
lastInteraction = millis();
|
||||||
Serial.println("initialization done.");
|
Serial.println("initialization done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,6 +406,7 @@ void named_song_action(AsyncWebServerRequest *request)
|
||||||
playSongByName(p->value());
|
playSongByName(p->value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastInteraction = millis();
|
||||||
request->send_P(200, "text/plain", "ok");
|
request->send_P(200, "text/plain", "ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -417,6 +424,7 @@ void progress_action(AsyncWebServerRequest *request)
|
||||||
audio.setAudioPlayPosition(atoi(p->value().c_str()));
|
audio.setAudioPlayPosition(atoi(p->value().c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastInteraction = millis();
|
||||||
request->send_P(200, "text/plain", "ok");
|
request->send_P(200, "text/plain", "ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,6 +442,7 @@ void volume_action(AsyncWebServerRequest *request)
|
||||||
audio.setVolume(atoi(p->value().c_str()));
|
audio.setVolume(atoi(p->value().c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastInteraction = millis();
|
||||||
request->send_P(200, "text/plain", "ok");
|
request->send_P(200, "text/plain", "ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -463,6 +472,15 @@ void loop()
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send device to sleep:
|
||||||
|
long now = millis();
|
||||||
|
if (now - lastInteraction > sleepDelay) {
|
||||||
|
Serial.println("entering deep sleep...");
|
||||||
|
deactivateRFID();
|
||||||
|
deactivateSD();
|
||||||
|
esp_deep_sleep_start();
|
||||||
|
}
|
||||||
|
|
||||||
if (asyncTogglePlayPause)
|
if (asyncTogglePlayPause)
|
||||||
{
|
{
|
||||||
asyncTogglePlayPause = false;
|
asyncTogglePlayPause = false;
|
||||||
|
|
@ -526,6 +544,7 @@ boolean buttonPressed(const uint8_t pin)
|
||||||
lastStart = now;
|
lastStart = now;
|
||||||
Serial.println("button pressed.");
|
Serial.println("button pressed.");
|
||||||
buttontoignore = pin;
|
buttontoignore = pin;
|
||||||
|
lastInteraction = now;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (digitalRead(pin) == HIGH && buttontoignore == pin) {
|
} else if (digitalRead(pin) == HIGH && buttontoignore == pin) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue