summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Graf <nategraf1@gmail.com>2023-11-18 20:10:45 -0800
committerGitHub <noreply@github.com>2023-11-18 23:10:45 -0500
commit5b212a442317a7c6b3c09c1e64aff46922f3d365 (patch)
treeac2da65989886c8bceda1dbfc73c18c7b49d2c85
parentae6ccfd6377f027a9f8c9acdbaa525a6f54f734f (diff)
downloadSensor-Watch-5b212a442317a7c6b3c09c1e64aff46922f3d365.tar.gz
Sensor-Watch-5b212a442317a7c6b3c09c1e64aff46922f3d365.tar.bz2
Sensor-Watch-5b212a442317a7c6b3c09c1e64aff46922f3d365.zip
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.
-rw-r--r--watch-library/simulator/watch/watch_rtc.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c
index fa80d6b4..f6279eed 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;
}