Skip to content

Commit

Permalink
Parameterise the reset timeout for haltError
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Dec 19, 2024
1 parent 04f1c3c commit 04dbf36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2499,10 +2499,13 @@ void Wippersnapper::runNetFSM() {
The desired color to blink.
*/
/**************************************************************************/
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor,
uint8_t seconds_until_reboot) {
uint8_t wdt_timeout = 5; // future platform-specific differences
int seconds_until_wdt_enable = seconds_until_reboot - wdt_timeout;
for (int i = 0;; i++) {
WS_DEBUG_PRINT("ERROR [WDT RESET IN ");
WS_DEBUG_PRINT(25 - i);
WS_DEBUG_PRINT(seconds_until_reboot - i);
WS_DEBUG_PRINTLN("]: ");
WS_DEBUG_PRINTLN(error);
// let the WDT fail out and reset!
Expand All @@ -2514,11 +2517,11 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
// hardware and software watchdog timers, delayMicroseconds does not.
delayMicroseconds(1000000);
#endif
if (i < 20) {
if (i < seconds_until_wdt_enable) {
yield();
WS.feedWDT(); // feed the WDT for the first 20 seconds
} else if (i == 20) {
WS.enableWDT(5000);
} else if (i == seconds_until_reboot) {
WS.enableWDT(wdt_timeout * 1000);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ class Wippersnapper {

// Error handling helpers
void haltError(String error,
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME);
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME,
uint8_t seconds_until_reboot = 25);
void errorWriteHang(String error);

// MQTT topic callbacks //
Expand Down

0 comments on commit 04dbf36

Please sign in to comment.