From 04dbf36da5980fef2a8813785659728567a19bec Mon Sep 17 00:00:00 2001 From: tyeth Date: Thu, 19 Dec 2024 17:15:46 +0000 Subject: [PATCH] Parameterise the reset timeout for haltError --- src/Wippersnapper.cpp | 13 ++++++++----- src/Wippersnapper.h | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Wippersnapper.cpp b/src/Wippersnapper.cpp index a7ad455b..47e472c3 100644 --- a/src/Wippersnapper.cpp +++ b/src/Wippersnapper.cpp @@ -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! @@ -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); } } } diff --git a/src/Wippersnapper.h b/src/Wippersnapper.h index ede52322..2962b771 100644 --- a/src/Wippersnapper.h +++ b/src/Wippersnapper.h @@ -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 //