refactor: watch faces no longer need a pointer to settings!
This commit is contained in:
24
movement.c
24
movement.c
@@ -103,10 +103,10 @@ static inline void _movement_disable_fast_tick_if_possible(void) {
|
||||
static void _movement_handle_background_tasks(void) {
|
||||
for(uint8_t i = 0; i < MOVEMENT_NUM_FACES; i++) {
|
||||
// For each face, if the watch face wants a background task...
|
||||
if (watch_faces[i].wants_background_task != NULL && watch_faces[i].wants_background_task(&movement_state.settings, watch_face_contexts[i])) {
|
||||
if (watch_faces[i].wants_background_task != NULL && watch_faces[i].wants_background_task(watch_face_contexts[i])) {
|
||||
// ...we give it one. pretty straightforward!
|
||||
movement_event_t background_event = { EVENT_BACKGROUND_TASK, 0 };
|
||||
watch_faces[i].loop(background_event, &movement_state.settings, watch_face_contexts[i]);
|
||||
watch_faces[i].loop(background_event, watch_face_contexts[i]);
|
||||
}
|
||||
}
|
||||
movement_state.needs_background_tasks_handled = false;
|
||||
@@ -121,7 +121,7 @@ static void _movement_handle_scheduled_tasks(void) {
|
||||
if (scheduled_tasks[i].reg <= date_time.reg) {
|
||||
scheduled_tasks[i].reg = 0;
|
||||
movement_event_t background_event = { EVENT_BACKGROUND_TASK, 0 };
|
||||
watch_faces[i].loop(background_event, &movement_state.settings, watch_face_contexts[i]);
|
||||
watch_faces[i].loop(background_event, watch_face_contexts[i]);
|
||||
// check if loop scheduled a new task
|
||||
if (scheduled_tasks[i].reg) {
|
||||
num_active_tasks++;
|
||||
@@ -181,9 +181,7 @@ void movement_force_led_off(void) {
|
||||
_movement_disable_fast_tick_if_possible();
|
||||
}
|
||||
|
||||
bool movement_default_loop_handler(movement_event_t event, movement_settings_t *settings) {
|
||||
(void)settings;
|
||||
|
||||
bool movement_default_loop_handler(movement_event_t event) {
|
||||
switch (event.event_type) {
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
movement_move_to_next_face();
|
||||
@@ -530,10 +528,10 @@ void app_setup(void) {
|
||||
movement_request_tick_frequency(1);
|
||||
|
||||
for(uint8_t i = 0; i < MOVEMENT_NUM_FACES; i++) {
|
||||
watch_faces[i].setup(&movement_state.settings, i, &watch_face_contexts[i]);
|
||||
watch_faces[i].setup(i, &watch_face_contexts[i]);
|
||||
}
|
||||
|
||||
watch_faces[movement_state.current_face_idx].activate(&movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
|
||||
watch_faces[movement_state.current_face_idx].activate(watch_face_contexts[movement_state.current_face_idx]);
|
||||
event.subsecond = 0;
|
||||
event.event_type = EVENT_ACTIVATE;
|
||||
}
|
||||
@@ -547,7 +545,7 @@ static void _sleep_mode_app_loop(void) {
|
||||
if (movement_state.needs_background_tasks_handled) _movement_handle_background_tasks();
|
||||
|
||||
event.event_type = EVENT_LOW_ENERGY_UPDATE;
|
||||
watch_faces[movement_state.current_face_idx].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
|
||||
watch_faces[movement_state.current_face_idx].loop(event, watch_face_contexts[movement_state.current_face_idx]);
|
||||
|
||||
// if we need to wake immediately, do it!
|
||||
if (movement_state.needs_wake) return;
|
||||
@@ -564,13 +562,13 @@ bool app_loop(void) {
|
||||
// low note for nonzero case, high note for return to watch_face 0
|
||||
watch_buzzer_play_note(movement_state.next_face_idx ? BUZZER_NOTE_C7 : BUZZER_NOTE_C8, 50);
|
||||
}
|
||||
wf->resign(&movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
|
||||
wf->resign(watch_face_contexts[movement_state.current_face_idx]);
|
||||
movement_state.current_face_idx = movement_state.next_face_idx;
|
||||
// we have just updated the face idx, so we must recache the watch face pointer.
|
||||
wf = &watch_faces[movement_state.current_face_idx];
|
||||
watch_clear_display();
|
||||
movement_request_tick_frequency(1);
|
||||
wf->activate(&movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
|
||||
wf->activate(watch_face_contexts[movement_state.current_face_idx]);
|
||||
event.subsecond = 0;
|
||||
event.event_type = EVENT_ACTIVATE;
|
||||
movement_state.watch_face_changed = false;
|
||||
@@ -619,7 +617,7 @@ bool app_loop(void) {
|
||||
if (event.event_type) {
|
||||
event.subsecond = movement_state.subsecond;
|
||||
// the first trip through the loop overrides the can_sleep state
|
||||
can_sleep = wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
|
||||
can_sleep = wf->loop(event, watch_face_contexts[movement_state.current_face_idx]);
|
||||
|
||||
// Keep light on if user is still interacting with the watch.
|
||||
if (movement_state.light_ticks > 0) {
|
||||
@@ -646,7 +644,7 @@ bool app_loop(void) {
|
||||
// first trip | can sleep | cannot sleep | can sleep | cannot sleep
|
||||
// second trip | can sleep | cannot sleep | cannot sleep | can sleep
|
||||
// && | can sleep | cannot sleep | cannot sleep | cannot sleep
|
||||
bool can_sleep2 = wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
|
||||
bool can_sleep2 = wf->loop(event, watch_face_contexts[movement_state.current_face_idx]);
|
||||
can_sleep = can_sleep && can_sleep2;
|
||||
event.event_type = EVENT_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user