diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 8ac54da6..f109b20d 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -23,14 +23,23 @@ static void sdsEnter() doDeepSleep(radioConfig.preferences.sds_secs * 1000LL); } +#include "error.h" + static void lsEnter() { DEBUG_MSG("lsEnter begin, ls_secs=%u\n", radioConfig.preferences.ls_secs); screen.setOn(false); - while (!service.radio.rf95.canSleep()) + uint32_t now = millis(); + while (!service.radio.rf95.canSleep()) { delay(10); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives) + if (millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep + recordCriticalError(ErrSleepEnterWait); + break; + } + } + gps.prepareSleep(); // abandon in-process parsing // if (!isUSBPowered) // FIXME - temp hack until we can put gps in sleep mode, if we have AC when we go to sleep then diff --git a/src/error.h b/src/error.h index 6538f501..cc3328c3 100644 --- a/src/error.h +++ b/src/error.h @@ -1,7 +1,7 @@ #pragma once /// Error codes for critical error -enum CriticalErrorCode { NoError, ErrTxWatchdog }; +enum CriticalErrorCode { NoError, ErrTxWatchdog, ErrSleepEnterWait }; /// Record an error that should be reported via analytics void recordCriticalError(CriticalErrorCode code, uint32_t address = 0);