Merge pull request #2210 from meshtastic/heap-reboot

move temporary reboot code to blink thread
This commit is contained in:
Ben Meadors 2023-01-27 08:21:49 -06:00 committed by GitHub
commit ed155476ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View File

@ -1,9 +1,5 @@
#include "OSThread.h"
#include "configuration.h"
#ifdef HAS_SCREEN
#include "graphics/Screen.h"
#endif
#include "main.h"
#include <assert.h>
namespace concurrency
@ -83,21 +79,12 @@ void OSThread::run()
#endif
currentThread = this;
auto newDelay = runOnce();
#ifdef ARCH_ESP32
auto newHeap = ESP.getFreeHeap();
if (newHeap < 10000) {
LOG_DEBUG("\n\n====== heap too low [10000] -> reboot in 5s ======\n\n");
#ifdef HAS_SCREEN
screen->startRebootScreen();
#endif
rebootAtMsec = millis() + 5000;
}
#ifdef DEBUG_HEAP
auto newHeap = ESP.getFreeHeap();
if (newHeap < heap)
LOG_DEBUG("------ Thread %s leaked heap %d -> %d (%d) ------\n", ThreadName.c_str(), heap, newHeap, newHeap - heap);
if (heap < newHeap)
LOG_DEBUG("++++++ Thread %s freed heap %d -> %d (%d) ++++++\n", ThreadName.c_str(), heap, newHeap, newHeap - heap);
#endif
#endif
runned();

View File

@ -128,6 +128,17 @@ static int32_t ledBlinker()
setLed(ledOn);
#ifdef ARCH_ESP32
auto newHeap = ESP.getFreeHeap();
if (newHeap < 11000) {
LOG_DEBUG("\n\n====== heap too low [11000] -> reboot in 1s ======\n\n");
#ifdef HAS_SCREEN
screen->startRebootScreen();
#endif
rebootAtMsec = millis() + 900;
}
#endif
// have a very sparse duty cycle of LED being on, unless charging, then blink 0.5Hz square wave rate to indicate that
return powerStatus->getIsCharging() ? 1000 : (ledOn ? 1 : 1000);
}