implemented entering recovery mode
recovery mode itself does not work yet
This commit is contained in:
parent
e31d33273a
commit
ee924b8b30
|
@ -73,7 +73,9 @@ bool ESPMegaPRO::begin()
|
||||||
esp_restart();
|
esp_restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Recovery Mode
|
||||||
|
recovery.bindFRAM(&fram, 600);
|
||||||
|
recovery.begin();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +91,7 @@ void ESPMegaPRO::loop()
|
||||||
{
|
{
|
||||||
inputs.loop();
|
inputs.loop();
|
||||||
outputs.loop();
|
outputs.loop();
|
||||||
|
recovery.loop();
|
||||||
for (int i = 0; i < 255; i++)
|
for (int i = 0; i < 255; i++)
|
||||||
{
|
{
|
||||||
if (cardInstalled[i])
|
if (cardInstalled[i])
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <ESPMegaDisplay.hpp>
|
#include <ESPMegaDisplay.hpp>
|
||||||
#include <InternalDisplay.hpp>
|
#include <InternalDisplay.hpp>
|
||||||
#include <ESPMegaWebServer.hpp>
|
#include <ESPMegaWebServer.hpp>
|
||||||
|
#include <ESPMegaRecovery.hpp>
|
||||||
|
|
||||||
// ESPMega Pro R3 Board Address
|
// ESPMega Pro R3 Board Address
|
||||||
#define FRAM_ADDRESS 0x56
|
#define FRAM_ADDRESS 0x56
|
||||||
|
@ -82,6 +83,11 @@ class ESPMegaPRO {
|
||||||
* @note You must call enableWebServer() before using this component.
|
* @note You must call enableWebServer() before using this component.
|
||||||
*/
|
*/
|
||||||
ESPMegaWebServer *webServer;
|
ESPMegaWebServer *webServer;
|
||||||
|
/**
|
||||||
|
* @brief This component is used to enter recovery mode when the ESPMegaPRO board is in a bootloop.
|
||||||
|
* @typedef ESPMegaRecovery
|
||||||
|
*/
|
||||||
|
ESPMegaRecovery recovery;
|
||||||
private:
|
private:
|
||||||
bool iotEnabled = false;
|
bool iotEnabled = false;
|
||||||
bool internalDisplayEnabled = false;
|
bool internalDisplayEnabled = false;
|
||||||
|
|
|
@ -15,17 +15,29 @@ void ESPMegaRecovery::begin() {
|
||||||
}
|
}
|
||||||
// Inclement the bootloop counter
|
// Inclement the bootloop counter
|
||||||
this->inclementBootloopCounter();
|
this->inclementBootloopCounter();
|
||||||
|
ESP_LOGV("ESPMegaRecovery", "Bootloop counter: %d", this->getBootloopCounter());
|
||||||
// If the bootloop counter is greater than 5, enter recovery mode
|
// If the bootloop counter is greater than 5, enter recovery mode
|
||||||
if(this->getBootloopCounter() > 5) {
|
if(this->getBootloopCounter() > 5) {
|
||||||
|
ESP_LOGW("ESPMegaRecovery", "Entering recovery mode");
|
||||||
this->enterRecoveryMode();
|
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() {
|
void ESPMegaRecovery::loop() {
|
||||||
// If the device is in recovery mode, block all other tasks
|
// If the device is in recovery mode, block all other tasks
|
||||||
if(this->isRecoveryMode()) {
|
if(this->isRecoveryMode()) {
|
||||||
|
int i = 0;
|
||||||
while(true) {
|
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
|
// This code will become the new loop
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Watchdog timer
|
// Watchdog timer
|
||||||
|
@ -33,6 +45,7 @@ void ESPMegaRecovery::loop() {
|
||||||
static uint32_t boot_time = millis();
|
static uint32_t boot_time = millis();
|
||||||
if(!booted) {
|
if(!booted) {
|
||||||
if(millis() - boot_time > RECOVERY_WATCHDOG_TIMEOUT * 1000) {
|
if(millis() - boot_time > RECOVERY_WATCHDOG_TIMEOUT * 1000) {
|
||||||
|
ESP_LOGI("ESPMegaRecovery", "System booted successfully, resetting bootloop counter");
|
||||||
this->resetBootloopCounter();
|
this->resetBootloopCounter();
|
||||||
booted = true;
|
booted = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <FRAM.h>
|
#include <FRAM.h>
|
||||||
#include <ESPMegaWebServer.hpp>
|
#include <ESPMegaWebServer.hpp>
|
||||||
|
#include <esp_log.h>
|
||||||
/**
|
/**
|
||||||
* @brief Recovery mode for ESPMega
|
* @brief Recovery mode for ESPMega
|
||||||
* Recovery mode is a mode that is entered when the device is in a bootloop
|
* Recovery mode is a mode that is entered when the device is in a bootloop
|
||||||
|
|
Loading…
Reference in New Issue