implemented entering recovery mode

recovery mode itself does not work yet
This commit is contained in:
Siwat Sirichai 2024-05-19 17:15:49 +07:00
parent e31d33273a
commit ee924b8b30
4 changed files with 24 additions and 1 deletions

View file

@ -15,17 +15,29 @@ void ESPMegaRecovery::begin() {
}
// Inclement the bootloop counter
this->inclementBootloopCounter();
ESP_LOGV("ESPMegaRecovery", "Bootloop counter: %d", this->getBootloopCounter());
// If the bootloop counter is greater than 5, enter recovery mode
if(this->getBootloopCounter() > 5) {
ESP_LOGW("ESPMegaRecovery", "Entering recovery mode");
this->enterRecoveryMode();
// Reset the bootloop counter to prevent re-entering recovery mode
// The device might unintentionally restart multiple times
// By resetting the counter, the user can press reset once in recovery mode to exit
ESP_LOGD("ESPMegaRecovery", "Resetting bootloop counter");
this->resetBootloopCounter();
}
}
void ESPMegaRecovery::loop() {
// If the device is in recovery mode, block all other tasks
if(this->isRecoveryMode()) {
int i = 0;
while(true) {
if (i%10 == 0)
ESP_LOGV("ESPMegaRecovery", "System is in recovery mode, no tasks will be executed");
ESP_LOGV("ESPMegaRecovery", "Please upload a new firmware to exit recovery mode");
// This code will become the new loop
delay(1000);
i++;
}
}
// Watchdog timer
@ -33,6 +45,7 @@ void ESPMegaRecovery::loop() {
static uint32_t boot_time = millis();
if(!booted) {
if(millis() - boot_time > RECOVERY_WATCHDOG_TIMEOUT * 1000) {
ESP_LOGI("ESPMegaRecovery", "System booted successfully, resetting bootloop counter");
this->resetBootloopCounter();
booted = true;
}