deep sleep

This commit is contained in:
Stefan Ostermann 2023-10-06 10:44:06 +02:00
parent 3f04aa1c41
commit 21119603cb
2 changed files with 25 additions and 1 deletions

View File

@ -54,8 +54,13 @@ void writeFile(fs::FS &fs, const char * path, const char * message){
unsigned long lastStart = 0;
unsigned long lastInteraction = 0;
uint8_t buttontoignore = 0;
const int startDelay = 250;
// wait until deep sleep:
const long sleepDelay = 1800000;
#endif

View File

@ -236,11 +236,13 @@ void togglePlayPause()
{
playNextMp3();
}
lastInteraction = millis();
}
void next()
{
playNextMp3();
lastInteraction = millis();
}
void audio_eof_mp3(const char *info)
@ -262,12 +264,14 @@ void readRFID()
String uidString = getRFIDString(rfid.uid.uidByte);
Serial.println(uidString);
playSongByRFID(uidString);
lastInteraction = millis();
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(BTN_START_STOP, INPUT_PULLUP);
pinMode(BTN_NEXT, INPUT_PULLUP);
@ -282,7 +286,8 @@ void setup()
deactivateRFID();
activateSD();
//deep sleep wakeup
esp_sleep_enable_ext0_wakeup((gpio_num_t)BTN_START_STOP, LOW);
Serial.print("Initializing SD card...");
@ -383,6 +388,7 @@ void setup()
&RfidTask, /* Task handle. */
0); /* Core where the task should run */
lastInteraction = millis();
Serial.println("initialization done.");
}
@ -400,6 +406,7 @@ void named_song_action(AsyncWebServerRequest *request)
playSongByName(p->value());
}
}
lastInteraction = millis();
request->send_P(200, "text/plain", "ok");
}
@ -417,6 +424,7 @@ void progress_action(AsyncWebServerRequest *request)
audio.setAudioPlayPosition(atoi(p->value().c_str()));
}
}
lastInteraction = millis();
request->send_P(200, "text/plain", "ok");
}
@ -434,6 +442,7 @@ void volume_action(AsyncWebServerRequest *request)
audio.setVolume(atoi(p->value().c_str()));
}
}
lastInteraction = millis();
request->send_P(200, "text/plain", "ok");
}
@ -463,6 +472,15 @@ void loop()
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)
{
asyncTogglePlayPause = false;
@ -526,6 +544,7 @@ boolean buttonPressed(const uint8_t pin)
lastStart = now;
Serial.println("button pressed.");
buttontoignore = pin;
lastInteraction = now;
return true;
}
} else if (digitalRead(pin) == HIGH && buttontoignore == pin) {