summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Cross <sean@xobs.io>2020-05-27 10:21:43 +0800
committerSean Cross <sean@xobs.io>2020-05-27 11:28:50 +0800
commitdbf1bef56ab3a7ce73388c9833c9aa5a4074eb24 (patch)
tree475977568c19a41451c9dee09e9a494405f9272a
parente470376c126828c768dfbcf25430869e8bc2b021 (diff)
watchdog: support catching the timeout
With this patch, the exception can now be caught: import microcontroller import watchdog import time wdt = microcontroller.watchdog wdt.timeout = 5 while True: wdt.mode = watchdog.WatchDogMode.RAISE print("Starting loop -- should exit after five seconds") try: while True: time.sleep(10) # pass # This also works for a spinloop except watchdog.WatchDogTimeout as e: print("Watchdog Expired (PASS)") except Exception as e: print("Other exception (FAIL)") print("Exited loop") This prints: Starting loop -- should exit after five seconds Watchdog Expired (PASS) Starting loop -- should exit after five seconds Watchdog Expired (PASS) Starting loop -- should exit after five seconds Watchdog Expired (PASS) Signed-off-by: Sean Cross <sean@xobs.io>
-rw-r--r--shared-bindings/watchdog/__init__.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/shared-bindings/watchdog/__init__.c b/shared-bindings/watchdog/__init__.c
index 7f818b226..d0704b7cf 100644
--- a/shared-bindings/watchdog/__init__.c
+++ b/shared-bindings/watchdog/__init__.c
@@ -74,6 +74,7 @@ mp_obj_exception_t mp_watchdog_timeout_exception = {
STATIC const mp_rom_map_elem_t watchdog_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_watchdog) },
{ MP_ROM_QSTR(MP_QSTR_WatchDogMode), MP_ROM_PTR(&watchdog_watchdogmode_type) },
+ { MP_ROM_QSTR(MP_QSTR_WatchDogTimeout), MP_ROM_PTR(&mp_type_WatchDogTimeout) },
};
STATIC MP_DEFINE_CONST_DICT(watchdog_module_globals, watchdog_module_globals_table);