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.
This commit is contained in:
Victor Graf 2023-11-18 20:10:45 -08:00 committed by GitHub
parent ae6ccfd637
commit 5b212a4423
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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;
}