Skip to content

Commit 04dbf36

Browse files
committed
Parameterise the reset timeout for haltError
1 parent 04f1c3c commit 04dbf36

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Wippersnapper.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,10 +2499,13 @@ void Wippersnapper::runNetFSM() {
24992499
The desired color to blink.
25002500
*/
25012501
/**************************************************************************/
2502-
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
2502+
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor,
2503+
uint8_t seconds_until_reboot) {
2504+
uint8_t wdt_timeout = 5; // future platform-specific differences
2505+
int seconds_until_wdt_enable = seconds_until_reboot - wdt_timeout;
25032506
for (int i = 0;; i++) {
25042507
WS_DEBUG_PRINT("ERROR [WDT RESET IN ");
2505-
WS_DEBUG_PRINT(25 - i);
2508+
WS_DEBUG_PRINT(seconds_until_reboot - i);
25062509
WS_DEBUG_PRINTLN("]: ");
25072510
WS_DEBUG_PRINTLN(error);
25082511
// let the WDT fail out and reset!
@@ -2514,11 +2517,11 @@ void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor) {
25142517
// hardware and software watchdog timers, delayMicroseconds does not.
25152518
delayMicroseconds(1000000);
25162519
#endif
2517-
if (i < 20) {
2520+
if (i < seconds_until_wdt_enable) {
25182521
yield();
25192522
WS.feedWDT(); // feed the WDT for the first 20 seconds
2520-
} else if (i == 20) {
2521-
WS.enableWDT(5000);
2523+
} else if (i == seconds_until_reboot) {
2524+
WS.enableWDT(wdt_timeout * 1000);
25222525
}
25232526
}
25242527
}

src/Wippersnapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ class Wippersnapper {
306306

307307
// Error handling helpers
308308
void haltError(String error,
309-
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME);
309+
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME,
310+
uint8_t seconds_until_reboot = 25);
310311
void errorWriteHang(String error);
311312

312313
// MQTT topic callbacks //

0 commit comments

Comments
 (0)