From 5b212a442317a7c6b3c09c1e64aff46922f3d365 Mon Sep 17 00:00:00 2001 From: Victor Graf Date: Sat, 18 Nov 2023 20:10:45 -0800 Subject: [PATCH] Fix simulator and hardware divergence in callback handling (#252) When using the simulator, I encountered cases where the light would become stuck on, and the watch would be unresponsive. In particular, this would occur when pressing the light button on the sunrise sunset watch face. I appears that this is caused by a divergence in out the callback mask is interpreted by the hardware interface, and in the simulator in the following function. void watch_rtc_disable_matching_periodic_callbacks(uint8_t mask) In particular, a mask of 0xFE is intended to disable all except the 128hz callback at index 0, but instead disables all except the 1hz callback at index 7 in the simulator. --- watch-library/simulator/watch/watch_rtc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c index fa80d6b..f6279ee 100644 --- a/watch-library/simulator/watch/watch_rtc.c +++ b/watch-library/simulator/watch/watch_rtc.c @@ -97,8 +97,7 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen // 0x01 (1 Hz) will have 7 leading zeros for PER7. 0xF0 (128 Hz) will have no leading zeroes for PER0. uint8_t per_n = __builtin_clz(tmp); - // this also maps nicely to an index for our list of tick callbacks. - double interval = 1000 / frequency; // in msec + double interval = 1000.0 / frequency; // in msec if (tick_callbacks[per_n] != -1) emscripten_clear_interval(tick_callbacks[per_n]); tick_callbacks[per_n] = emscripten_set_interval(watch_invoke_periodic_callback, interval, (void *)callback); @@ -115,7 +114,7 @@ void watch_rtc_disable_periodic_callback(uint8_t frequency) { void watch_rtc_disable_matching_periodic_callbacks(uint8_t mask) { for (int i = 0; i < 8; i++) { - if (tick_callbacks[i] != -1 && (mask & (1 << (7 - i))) != 0) { + if (tick_callbacks[i] != -1 && (mask & (1 << i)) != 0) { emscripten_clear_interval(tick_callbacks[i]); tick_callbacks[i] = -1; }