summaryrefslogtreecommitdiffstats
path: root/movement
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-02-12 22:19:01 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2022-02-12 22:19:01 -0500
commitb8cb6f3bcf52d5c94f1cc99879deaceb9cbaf7b5 (patch)
treed76deab3bb0ba2bc2035b33b6571e83706540d62 /movement
parent5dac14974c9b2d00431430e9f24dd7e26f69246f (diff)
downloadSensor-Watch-b8cb6f3bcf52d5c94f1cc99879deaceb9cbaf7b5.tar.gz
Sensor-Watch-b8cb6f3bcf52d5c94f1cc99879deaceb9cbaf7b5.tar.bz2
Sensor-Watch-b8cb6f3bcf52d5c94f1cc99879deaceb9cbaf7b5.zip
movement: prevent invalid tick frequency from breaking scheduled tasks
Diffstat (limited to 'movement')
-rw-r--r--movement/movement.c9
-rw-r--r--movement/movement.h2
2 files changed, 7 insertions, 4 deletions
diff --git a/movement/movement.c b/movement/movement.c
index aa95f2f1..42b73526 100644
--- a/movement/movement.c
+++ b/movement/movement.c
@@ -152,14 +152,19 @@ static void _movement_handle_scheduled_tasks(void) {
}
void movement_request_tick_frequency(uint8_t freq) {
- if (freq == 128) return; // Movement uses the 128 Hz tick internally
+ // Movement uses the 128 Hz tick internally
+ if (freq == 128) return;
+
+ // Movement requires at least a 1 Hz tick.
+ // If we are asked for an invalid frequency, default back to 1 Hz.
+ if (freq == 0 || __builtin_popcount(freq) != 1) freq = 1;
// disable all callbacks except the 128 Hz one
watch_rtc_disable_matching_periodic_callbacks(0xFE);
movement_state.subsecond = 0;
movement_state.tick_frequency = freq;
- if (freq) watch_rtc_register_periodic_callback(cb_tick, freq);
+ watch_rtc_register_periodic_callback(cb_tick, freq);
}
void movement_illuminate_led(void) {
diff --git a/movement/movement.h b/movement/movement.h
index 8949d026..cb2c9ca2 100644
--- a/movement/movement.h
+++ b/movement/movement.h
@@ -274,8 +274,6 @@ void movement_move_to_face(uint8_t watch_face_index);
void movement_move_to_next_face(void);
void movement_illuminate_led(void);
-// note: requesting a tick frequency of 0 will break any scheduled background tasks.
-// this will be fixed in a future refactor of the tick mechanism.
void movement_request_tick_frequency(uint8_t freq);
// note: watch faces can only schedule a background task when in the foreground, since