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>
This commit is contained in:
parent
e470376c12
commit
dbf1bef56a
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user