]> git.earman.xyz Git - sensor-watch.git/commitdiff
Fix simulator and hardware divergence in callback handling (#252)
authorVictor Graf <nategraf1@gmail.com>
Sun, 19 Nov 2023 04:10:45 +0000 (20:10 -0800)
committerGitHub <noreply@github.com>
Sun, 19 Nov 2023 04:10:45 +0000 (23:10 -0500)
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

index fa80d6b494b51b3ac94d210acd550fd7578d6723..f6279eedb53d38e0821e186f5d4ff0f8a945dc9a 100644 (file)
@@ -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;
         }