From cfd04be4fbd473e354ccec94f888e0bae5ecf1f1 Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Sun, 29 Sep 2024 22:14:55 -0400 Subject: [PATCH] refactor watch faces to use new advisory API --- .../watch_faces/clock/decimal_time_face.c | 2 +- .../watch_faces/clock/decimal_time_face.h | 2 +- .../clock/minute_repeater_decimal_face.c | 11 ++++--- .../clock/minute_repeater_decimal_face.h | 4 +-- .../clock/repetition_minute_face.c | 11 ++++--- .../clock/repetition_minute_face.h | 4 +-- .../clock/simple_clock_bin_led_face.c | 11 ++++--- .../clock/simple_clock_bin_led_face.h | 4 +-- .../watch_faces/clock/weeknumber_clock_face.c | 11 ++++--- .../watch_faces/clock/weeknumber_clock_face.h | 4 +-- movement/watch_faces/clock/wyoscan_face.h | 2 +- .../watch_faces/complication/alarm_face.c | 21 ++++++++---- .../watch_faces/complication/alarm_face.h | 4 +-- .../watch_faces/complication/deadline_face.c | 4 +-- .../watch_faces/complication/deadline_face.h | 4 +-- .../complication/ships_bell_face.c | 32 ++++++++++++------- .../complication/ships_bell_face.h | 4 +-- .../watch_faces/complication/tempchart_face.c | 11 ++++--- .../watch_faces/complication/tempchart_face.h | 4 +-- movement/watch_faces/complication/wake_face.c | 11 ++++--- movement/watch_faces/complication/wake_face.h | 4 +-- .../watch_faces/demo/lis2dw_logging_face.c | 7 ++-- .../watch_faces/demo/lis2dw_logging_face.h | 4 +-- .../sensor/accel_interrupt_count_face.c | 6 ++-- .../sensor/accel_interrupt_count_face.h | 4 +-- movement/watch_faces/sensor/minmax_face.c | 9 ++++-- movement/watch_faces/sensor/minmax_face.h | 4 +-- .../sensor/thermistor_logging_face.c | 8 +++-- .../sensor/thermistor_logging_face.h | 4 +-- movement/watch_faces/settings/nanosec_face.c | 14 +++++--- movement/watch_faces/settings/nanosec_face.h | 4 +-- 31 files changed, 141 insertions(+), 88 deletions(-) diff --git a/movement/watch_faces/clock/decimal_time_face.c b/movement/watch_faces/clock/decimal_time_face.c index 238be986..95e6a51a 100644 --- a/movement/watch_faces/clock/decimal_time_face.c +++ b/movement/watch_faces/clock/decimal_time_face.c @@ -160,7 +160,7 @@ void decimal_time_face_resign(void *context) { } -// void decimal_time_face_wants_background_task() { +// void decimal_time_face_advise() { // // } diff --git a/movement/watch_faces/clock/decimal_time_face.h b/movement/watch_faces/clock/decimal_time_face.h index e08c3da6..eb1a41e4 100644 --- a/movement/watch_faces/clock/decimal_time_face.h +++ b/movement/watch_faces/clock/decimal_time_face.h @@ -57,7 +57,7 @@ void decimal_time_face_setup(uint8_t watch_face_index, void ** context_ptr); void decimal_time_face_activate(void *context); bool decimal_time_face_loop(movement_event_t event, void *context); void decimal_time_face_resign(void *context); -// void decimal_time_face_wants_background_task(); +// void decimal_time_face_advise(); #define decimal_time_face ((const watch_face_t){ \ diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index 1ce02def..7582a7a4 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -225,11 +225,14 @@ void minute_repeater_decimal_face_resign(void *context) { (void) context; } -bool minute_repeater_decimal_face_wants_background_task(void *context) { +movement_watch_face_advisory_t minute_repeater_decimal_face_advise(void *context) { minute_repeater_decimal_state_t *state = (minute_repeater_decimal_state_t *)context; - if (!state->signal_enabled) return false; + movement_watch_face_advisory_t retval = { 0 }; - watch_date_time date_time = watch_rtc_get_date_time(); + if (state->signal_enabled) { + watch_date_time date_time = watch_rtc_get_date_time(); + retval.wants_background_task = date_time.unit.minute == 0; + } - return date_time.unit.minute == 0; + return retval; } diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.h b/movement/watch_faces/clock/minute_repeater_decimal_face.h index b5090530..738b34d7 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.h +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.h @@ -71,14 +71,14 @@ void minute_repeater_decimal_face_setup(uint8_t watch_face_index, void ** contex void minute_repeater_decimal_face_activate(void *context); bool minute_repeater_decimal_face_loop(movement_event_t event, void *context); void minute_repeater_decimal_face_resign(void *context); -bool minute_repeater_decimal_face_wants_background_task(void *context); +movement_watch_face_advisory_t minute_repeater_decimal_face_advise(void *context); #define minute_repeater_decimal_face ((const watch_face_t){ \ minute_repeater_decimal_face_setup, \ minute_repeater_decimal_face_activate, \ minute_repeater_decimal_face_loop, \ minute_repeater_decimal_face_resign, \ - minute_repeater_decimal_face_wants_background_task, \ + minute_repeater_decimal_face_advise, \ }) #endif // MINUTE_REPEATER_DECIMAL_FACE_H_ diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index 04fa8594..0d792a3f 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -208,11 +208,14 @@ void repetition_minute_face_resign(void *context) { (void) context; } -bool repetition_minute_face_wants_background_task(void *context) { +movement_watch_face_advisory_t repetition_minute_face_advise(void *context) { repetition_minute_state_t *state = (repetition_minute_state_t *)context; - if (!state->signal_enabled) return false; + movement_watch_face_advisory_t retval = { 0 }; - watch_date_time date_time = watch_rtc_get_date_time(); + if (state->signal_enabled) { + watch_date_time date_time = watch_rtc_get_date_time(); + retval.wants_background_task = date_time.unit.minute == 0; + } - return date_time.unit.minute == 0; + return retval; } diff --git a/movement/watch_faces/clock/repetition_minute_face.h b/movement/watch_faces/clock/repetition_minute_face.h index 3c631d6e..1e5d10ac 100644 --- a/movement/watch_faces/clock/repetition_minute_face.h +++ b/movement/watch_faces/clock/repetition_minute_face.h @@ -70,14 +70,14 @@ void repetition_minute_face_setup(uint8_t watch_face_index, void ** context_ptr) void repetition_minute_face_activate(void *context); bool repetition_minute_face_loop(movement_event_t event, void *context); void repetition_minute_face_resign(void *context); -bool repetition_minute_face_wants_background_task(void *context); +movement_watch_face_advisory_t repetition_minute_face_advise(void *context); #define repetition_minute_face ((const watch_face_t){ \ repetition_minute_face_setup, \ repetition_minute_face_activate, \ repetition_minute_face_loop, \ repetition_minute_face_resign, \ - repetition_minute_face_wants_background_task, \ + repetition_minute_face_advise, \ }) #endif // REPETITION_MINUTE_FACE_H_ diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index 5ac93dd7..cbe15935 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -209,11 +209,14 @@ void simple_clock_bin_led_face_resign(void *context) { (void) context; } -bool simple_clock_bin_led_face_wants_background_task(void *context) { +movement_watch_face_advisory_t simple_clock_bin_led_face_advise(void *context) { simple_clock_bin_led_state_t *state = (simple_clock_bin_led_state_t *)context; - if (!state->signal_enabled) return false; + movement_watch_face_advisory_t retval = { 0 }; - watch_date_time date_time = watch_rtc_get_date_time(); + if (state->signal_enabled) { + watch_date_time date_time = watch_rtc_get_date_time(); + retval.wants_background_task = date_time.unit.minute == 0; + } - return date_time.unit.minute == 0; + return retval; } diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.h b/movement/watch_faces/clock/simple_clock_bin_led_face.h index bff07589..ed9d3aee 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.h +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.h @@ -68,14 +68,14 @@ void simple_clock_bin_led_face_setup(uint8_t watch_face_index, void ** context_p void simple_clock_bin_led_face_activate(void *context); bool simple_clock_bin_led_face_loop(movement_event_t event, void *context); void simple_clock_bin_led_face_resign(void *context); -bool simple_clock_bin_led_face_wants_background_task(void *context); +movement_watch_face_advisory_t simple_clock_bin_led_face_advise(void *context); #define simple_clock_bin_led_face ((const watch_face_t){ \ simple_clock_bin_led_face_setup, \ simple_clock_bin_led_face_activate, \ simple_clock_bin_led_face_loop, \ simple_clock_bin_led_face_resign, \ - simple_clock_bin_led_face_wants_background_task, \ + simple_clock_bin_led_face_advise, \ }) #endif // SIIMPLE_CLOCK_BIN_LED_FACE_H_ diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 060191dd..2a270a2e 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -143,11 +143,14 @@ void weeknumber_clock_face_resign(void *context) { (void) context; } -bool weeknumber_clock_face_wants_background_task(void *context) { +movement_watch_face_advisory_t weeknumber_clock_face_advise(void *context) { weeknumber_clock_state_t *state = (weeknumber_clock_state_t *)context; - if (!state->signal_enabled) return false; + movement_watch_face_advisory_t retval = { 0 }; - watch_date_time date_time = watch_rtc_get_date_time(); + if (state->signal_enabled) { + watch_date_time date_time = watch_rtc_get_date_time(); + retval.wants_background_task = date_time.unit.minute == 0; + } - return date_time.unit.minute == 0; + return retval; } diff --git a/movement/watch_faces/clock/weeknumber_clock_face.h b/movement/watch_faces/clock/weeknumber_clock_face.h index d74da487..9ba12707 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.h +++ b/movement/watch_faces/clock/weeknumber_clock_face.h @@ -48,14 +48,14 @@ void weeknumber_clock_face_setup(uint8_t watch_face_index, void ** context_ptr); void weeknumber_clock_face_activate(void *context); bool weeknumber_clock_face_loop(movement_event_t event, void *context); void weeknumber_clock_face_resign(void *context); -bool weeknumber_clock_face_wants_background_task(void *context); +movement_watch_face_advisory_t weeknumber_clock_face_advise(void *context); #define weeknumber_clock_face ((const watch_face_t){ \ weeknumber_clock_face_setup, \ weeknumber_clock_face_activate, \ weeknumber_clock_face_loop, \ weeknumber_clock_face_resign, \ - weeknumber_clock_face_wants_background_task, \ + weeknumber_clock_face_advise, \ }) #endif // SIMPLE_CLOCK_FACE_H_ diff --git a/movement/watch_faces/clock/wyoscan_face.h b/movement/watch_faces/clock/wyoscan_face.h index 2816e4d3..ee412002 100644 --- a/movement/watch_faces/clock/wyoscan_face.h +++ b/movement/watch_faces/clock/wyoscan_face.h @@ -77,7 +77,7 @@ void wyoscan_face_setup(uint8_t watch_face_index, void ** context_ptr); void wyoscan_face_activate(void *context); bool wyoscan_face_loop(movement_event_t event, void *context); void wyoscan_face_resign(void *context); -bool wyoscan_face_wants_background_task(void *context); +movement_watch_face_advisory_t wyoscan_face_advise(void *context); #define wyoscan_face ((const watch_face_t){ \ wyoscan_face_setup, \ diff --git a/movement/watch_faces/complication/alarm_face.c b/movement/watch_faces/complication/alarm_face.c index b84a6523..417dbd2a 100644 --- a/movement/watch_faces/complication/alarm_face.c +++ b/movement/watch_faces/complication/alarm_face.c @@ -232,11 +232,13 @@ void alarm_face_resign(void *context) { movement_request_tick_frequency(1); } -bool alarm_face_wants_background_task(void *context) { +movement_watch_face_advisory_t alarm_face_advise(void *context) { alarm_state_t *state = (alarm_state_t *)context; + movement_watch_face_advisory_t retval = { 0 }; + watch_date_time now = watch_rtc_get_date_time(); // just a failsafe: never fire more than one alarm within a minute - if (state->alarm_handled_minute == now.unit.minute) return false; + if (state->alarm_handled_minute == now.unit.minute) return retval; state->alarm_handled_minute = now.unit.minute; // check the rest for (uint8_t i = 0; i < ALARM_ALARMS; i++) { @@ -246,17 +248,24 @@ bool alarm_face_wants_background_task(void *context) { state->alarm_playing_idx = i; if (state->alarm[i].day == ALARM_DAY_EACH_DAY || state->alarm[i].day == ALARM_DAY_ONE_TIME) return true; uint8_t weekday_idx = _get_weekday_idx(now); - if (state->alarm[i].day == weekday_idx) return true; - if (state->alarm[i].day == ALARM_DAY_WORKDAY && weekday_idx < 5) return true; - if (state->alarm[i].day == ALARM_DAY_WEEKEND && weekday_idx >= 5) return true; + if (state->alarm[i].day == weekday_idx) retval.wants_background_task = true; + if (state->alarm[i].day == ALARM_DAY_WORKDAY && weekday_idx < 5) retval.wants_background_task = true; + if (state->alarm[i].day == ALARM_DAY_WEEKEND && weekday_idx >= 5) retval.wants_background_task = true; } } } } + + if (retval.wants_background_task) { + // FIXME for #SecondMovement: I think that this replicates the previous behavior of returning true in the conditionals above, + // but would like to do more testing + return retval; + } + state->alarm_handled_minute = -1; // update the movement's alarm indicator five times an hour if (now.unit.minute % 12 == 0) _alarm_update_alarm_enabled(state); - return false; + return retval; } bool alarm_face_loop(movement_event_t event, void *context) { diff --git a/movement/watch_faces/complication/alarm_face.h b/movement/watch_faces/complication/alarm_face.h index f46da395..288ea2d9 100644 --- a/movement/watch_faces/complication/alarm_face.h +++ b/movement/watch_faces/complication/alarm_face.h @@ -89,14 +89,14 @@ void alarm_face_setup(uint8_t watch_face_index, void ** context_ptr); void alarm_face_activate(void *context); bool alarm_face_loop(movement_event_t event, void *context); void alarm_face_resign(void *context); -bool alarm_face_wants_background_task(void *context); +movement_watch_face_advisory_t alarm_face_advise(void *context); #define alarm_face ((const watch_face_t){ \ alarm_face_setup, \ alarm_face_activate, \ alarm_face_loop, \ alarm_face_resign, \ - alarm_face_wants_background_task, \ + alarm_face_advise, \ }) #endif // ALARM_FACE_H_ diff --git a/movement/watch_faces/complication/deadline_face.c b/movement/watch_faces/complication/deadline_face.c index 6243fc07..7fbea72e 100644 --- a/movement/watch_faces/complication/deadline_face.c +++ b/movement/watch_faces/complication/deadline_face.c @@ -229,7 +229,7 @@ static void _background_alarm_play(deadline_state_t *state) static void _background_alarm_schedule(deadline_state_t *state) { /* We simply re-use the scheduling in the background task */ - deadline_face_wants_background_task(state); + deadline_face_advise(state); } /* Cancel background alarm */ @@ -606,7 +606,7 @@ void deadline_face_resign(void *context) } /* Want background task */ -bool deadline_face_wants_background_task(void *context) +movement_watch_face_advisory_t deadline_face_advise(void *context) { deadline_state_t *state = (deadline_state_t *) context; diff --git a/movement/watch_faces/complication/deadline_face.h b/movement/watch_faces/complication/deadline_face.h index f89f3ef2..3cfca55f 100644 --- a/movement/watch_faces/complication/deadline_face.h +++ b/movement/watch_faces/complication/deadline_face.h @@ -52,14 +52,14 @@ void deadline_face_setup(uint8_t watch_face_index, void **context_ptr); void deadline_face_activate(void *context); bool deadline_face_loop(movement_event_t event, void *context); void deadline_face_resign(void *context); -bool deadline_face_wants_background_task(void *context); +movement_watch_face_advisory_t deadline_face_advise(void *context); #define deadline_face ((const watch_face_t){ \ deadline_face_setup, \ deadline_face_activate, \ deadline_face_loop, \ deadline_face_resign, \ - deadline_face_wants_background_task \ + deadline_face_advise \ }) #endif // DEADLINE_FACE_H_ diff --git a/movement/watch_faces/complication/ships_bell_face.c b/movement/watch_faces/complication/ships_bell_face.c index 6efbc52a..fe364fed 100644 --- a/movement/watch_faces/complication/ships_bell_face.c +++ b/movement/watch_faces/complication/ships_bell_face.c @@ -124,26 +124,36 @@ void ships_bell_face_resign(void *context) { (void) context; } -bool ships_bell_face_wants_background_task(void *context) { - +movement_watch_face_advisory_t ships_bell_face_advise(void *context) { ships_bell_state_t *state = (ships_bell_state_t *) context; - if (!state->bell_enabled) return false; + movement_watch_face_advisory_t retval = { 0 }; + + if (!state->bell_enabled) return retval; watch_date_time date_time = watch_rtc_get_date_time(); - if (!(date_time.unit.minute == 0 || date_time.unit.minute == 30)) return false; + if (!(date_time.unit.minute == 0 || date_time.unit.minute == 30)) return retval; date_time.unit.hour %= 12; + // #SecondMovement: This was migrated to the new advisory API but not tested. Needs more testing! switch (state->on_watch) { case 1: - return (date_time.unit.hour >= 4 && date_time.unit.hour < 8) || - (date_time.unit.hour == 8 && date_time.unit.minute == 0); + if ((date_time.unit.hour >= 4 && date_time.unit.hour < 8) || + (date_time.unit.hour == 8 && date_time.unit.minute == 0)) + retval.wants_background_task = true; + break; case 2: - return (date_time.unit.hour >= 8 && date_time.unit.hour < 12) || - (date_time.unit.hour == 0 && date_time.unit.minute == 0); + if ((date_time.unit.hour >= 8 && date_time.unit.hour < 12) || + (date_time.unit.hour == 0 && date_time.unit.minute == 0)) + retval.wants_background_task = true; + break; case 3: - return (date_time.unit.hour >= 0 && date_time.unit.hour < 4) || - (date_time.unit.hour == 4 && date_time.unit.minute == 0); + if ((date_time.unit.hour >= 0 && date_time.unit.hour < 4) || + (date_time.unit.hour == 4 && date_time.unit.minute == 0)) + retval.wants_background_task = true; + break; default: - return true; + retval.wants_background_task = true; } + + return retval; } diff --git a/movement/watch_faces/complication/ships_bell_face.h b/movement/watch_faces/complication/ships_bell_face.h index 7a17bd4d..bda16970 100644 --- a/movement/watch_faces/complication/ships_bell_face.h +++ b/movement/watch_faces/complication/ships_bell_face.h @@ -55,14 +55,14 @@ void ships_bell_face_setup(uint8_t watch_face_index, void ** context_ptr); void ships_bell_face_activate(void *context); bool ships_bell_face_loop(movement_event_t event, void *context); void ships_bell_face_resign(void *context); -bool ships_bell_face_wants_background_task(void *context); +movement_watch_face_advisory_t ships_bell_face_advise(void *context); #define ships_bell_face ((const watch_face_t){ \ ships_bell_face_setup, \ ships_bell_face_activate, \ ships_bell_face_loop, \ ships_bell_face_resign, \ - ships_bell_face_wants_background_task, \ + ships_bell_face_advise, \ }) #endif // SHIPS_BELL_FACE_H_ diff --git a/movement/watch_faces/complication/tempchart_face.c b/movement/watch_faces/complication/tempchart_face.c index 6825c78e..07ade30a 100644 --- a/movement/watch_faces/complication/tempchart_face.c +++ b/movement/watch_faces/complication/tempchart_face.c @@ -133,10 +133,13 @@ void tempchart_face_resign(void *context) { } //background freq correction -bool tempchart_face_wants_background_task(void *context) { +movement_watch_face_advisory_t tempchart_face_advise(void *context) { (void) context; - watch_date_time date_time = watch_rtc_get_date_time(); + movement_watch_face_advisory_t retval = { 0 }; - //Updating data every 5 minutes - return date_time.unit.minute % 5 == 0; + watch_date_time date_time = watch_rtc_get_date_time(); + // Updating data every 5 minutes + retval.wants_background_task = date_time.unit.minute % 5 == 0; + + return retval; } diff --git a/movement/watch_faces/complication/tempchart_face.h b/movement/watch_faces/complication/tempchart_face.h index db89d204..3c462cd0 100644 --- a/movement/watch_faces/complication/tempchart_face.h +++ b/movement/watch_faces/complication/tempchart_face.h @@ -44,7 +44,7 @@ void tempchart_face_setup(uint8_t watch_face_index, void ** context_ptr); void tempchart_face_activate(void *context); bool tempchart_face_loop(movement_event_t event, void *context); void tempchart_face_resign(void *context); -bool tempchart_face_wants_background_task(void *context); +movement_watch_face_advisory_t tempchart_face_advise(void *context); #define tempchart_face ((const watch_face_t){ \ @@ -52,7 +52,7 @@ bool tempchart_face_wants_background_task(void *context); tempchart_face_activate, \ tempchart_face_loop, \ tempchart_face_resign, \ - tempchart_face_wants_background_task, \ + tempchart_face_advise, \ }) #endif // TEMPCHART_FACE_H_ diff --git a/movement/watch_faces/complication/wake_face.c b/movement/watch_faces/complication/wake_face.c index 1829aee4..ca3a96ce 100644 --- a/movement/watch_faces/complication/wake_face.c +++ b/movement/watch_faces/complication/wake_face.c @@ -80,14 +80,14 @@ void wake_face_resign(void *context) { (void) context; } -bool wake_face_wants_background_task(void *context) { +movement_watch_face_advisory_t wake_face_advise(void *context) { wake_face_state_t *state = (wake_face_state_t *)context; + movement_watch_face_advisory_t retval = { 0 }; - bool rc = false; if ( state->mode ) { watch_date_time now = watch_rtc_get_date_time(); - rc = state->hour==now.unit.hour && state->minute==now.unit.minute; - // We’re at the mercy of the wants_background_task handler + retval.wants_background_task = state->hour==now.unit.hour && state->minute==now.unit.minute; + // We’re at the mercy of the advise handler // In Safari, the emulator triggers at the ›end‹ of the minute // Converting to Unix timestamps and taking a difference between now and wake // is not an easy win — because the timestamp for wake has to rely on now @@ -95,7 +95,8 @@ bool wake_face_wants_background_task(void *context) { // of now. If it is, take tomorrow’s date, calculating month and year rollover // if need be. } - return rc; + + return retval; } bool wake_face_loop(movement_event_t event, void *context) { diff --git a/movement/watch_faces/complication/wake_face.h b/movement/watch_faces/complication/wake_face.h index 72606afd..008a5403 100644 --- a/movement/watch_faces/complication/wake_face.h +++ b/movement/watch_faces/complication/wake_face.h @@ -52,14 +52,14 @@ void wake_face_setup(uint8_t watch_face_index, void **context_ptr); void wake_face_activate(void *context); bool wake_face_loop(movement_event_t event, void *context); void wake_face_resign(void *context); -bool wake_face_wants_background_task(void *context); +movement_watch_face_advisory_t wake_face_advise(void *context); #define wake_face ((const watch_face_t){ \ wake_face_setup, \ wake_face_activate, \ wake_face_loop, \ wake_face_resign, \ - wake_face_wants_background_task \ + wake_face_advise \ }) #endif // WAKE_FACE_H_ diff --git a/movement/watch_faces/demo/lis2dw_logging_face.c b/movement/watch_faces/demo/lis2dw_logging_face.c index 9792a745..969ad0ef 100644 --- a/movement/watch_faces/demo/lis2dw_logging_face.c +++ b/movement/watch_faces/demo/lis2dw_logging_face.c @@ -187,9 +187,10 @@ void lis2dw_logging_face_resign(void *context) { watch_disable_digital_input(A4); } -bool lis2dw_logging_face_wants_background_task(void *context) { +movement_watch_face_advisory_t lis2dw_logging_face_advise(void *context) { lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context; watch_date_time date_time = watch_rtc_get_date_time(); + movement_watch_face_advisory_t retval = { 0 }; // this is kind of an abuse of the API, but, let's use the 1 minute tick to shift all our data over. logger_state->interrupts[2] = logger_state->interrupts[1]; @@ -197,5 +198,7 @@ bool lis2dw_logging_face_wants_background_task(void *context) { logger_state->interrupts[0] = 0; // and do our logging task every 15 minutes - return (date_time.unit.minute % 15) == 0; + retval.wants_background_task = date_time.unit.minute % 15 == 0; + + return retval; } diff --git a/movement/watch_faces/demo/lis2dw_logging_face.h b/movement/watch_faces/demo/lis2dw_logging_face.h index 0272cd8f..cfae1a71 100644 --- a/movement/watch_faces/demo/lis2dw_logging_face.h +++ b/movement/watch_faces/demo/lis2dw_logging_face.h @@ -61,14 +61,14 @@ void lis2dw_logging_face_setup(uint8_t watch_face_index, void ** context_ptr); void lis2dw_logging_face_activate(void *context); bool lis2dw_logging_face_loop(movement_event_t event, void *context); void lis2dw_logging_face_resign(void *context); -bool lis2dw_logging_face_wants_background_task(void *context); +movement_watch_face_advisory_t lis2dw_logging_face_advise(void *context); #define lis2dw_logging_face ((const watch_face_t){ \ lis2dw_logging_face_setup, \ lis2dw_logging_face_activate, \ lis2dw_logging_face_loop, \ lis2dw_logging_face_resign, \ - lis2dw_logging_face_wants_background_task, \ + lis2dw_logging_face_advise, \ }) #endif // LIS2DW_LOGGING_FACE_H_ diff --git a/movement/watch_faces/sensor/accel_interrupt_count_face.c b/movement/watch_faces/sensor/accel_interrupt_count_face.c index 82679c54..8d436aea 100644 --- a/movement/watch_faces/sensor/accel_interrupt_count_face.c +++ b/movement/watch_faces/sensor/accel_interrupt_count_face.c @@ -153,7 +153,9 @@ void accel_interrupt_count_face_resign(void *context) { (void) context; } -bool accel_interrupt_count_face_wants_background_task(void *context) { +movement_watch_face_advisory_t accel_interrupt_count_face_advise(void *context) { (void) context; - return false; + movement_watch_face_advisory_t retval = { 0 }; + + return retval; } diff --git a/movement/watch_faces/sensor/accel_interrupt_count_face.h b/movement/watch_faces/sensor/accel_interrupt_count_face.h index 0f91363d..29d5df13 100644 --- a/movement/watch_faces/sensor/accel_interrupt_count_face.h +++ b/movement/watch_faces/sensor/accel_interrupt_count_face.h @@ -47,12 +47,12 @@ void accel_interrupt_count_face_setup(uint8_t watch_face_index, void ** context_ void accel_interrupt_count_face_activate(void *context); bool accel_interrupt_count_face_loop(movement_event_t event, void *context); void accel_interrupt_count_face_resign(void *context); -bool accel_interrupt_count_face_wants_background_task(void *context); +movement_watch_face_advisory_t accel_interrupt_count_face_advise(void *context); #define accel_interrupt_count_face ((const watch_face_t){ \ accel_interrupt_count_face_setup, \ accel_interrupt_count_face_activate, \ accel_interrupt_count_face_loop, \ accel_interrupt_count_face_resign, \ - accel_interrupt_count_face_wants_background_task, \ + accel_interrupt_count_face_advise, \ }) diff --git a/movement/watch_faces/sensor/minmax_face.c b/movement/watch_faces/sensor/minmax_face.c index 10e2a9ed..7f520063 100644 --- a/movement/watch_faces/sensor/minmax_face.c +++ b/movement/watch_faces/sensor/minmax_face.c @@ -143,8 +143,13 @@ void minmax_face_resign(void *context) { } -bool minmax_face_wants_background_task(void *context) { +movement_watch_face_advisory_t minmax_face_advise(void *context) { (void) context; + // this will get called at the top of each minute; always request bg task - return true; + movement_watch_face_advisory_t retval = { + .wants_background_task = 1, + }; + + return retval; } diff --git a/movement/watch_faces/sensor/minmax_face.h b/movement/watch_faces/sensor/minmax_face.h index 4faf6794..330f532b 100644 --- a/movement/watch_faces/sensor/minmax_face.h +++ b/movement/watch_faces/sensor/minmax_face.h @@ -55,14 +55,14 @@ void minmax_face_setup(uint8_t watch_face_index, void ** context_ptr); void minmax_face_activate(void *context); bool minmax_face_loop(movement_event_t event, void *context); void minmax_face_resign(void *context); -bool minmax_face_wants_background_task(void *context); +movement_watch_face_advisory_t minmax_face_advise(void *context); #define minmax_face ((const watch_face_t){ \ minmax_face_setup, \ minmax_face_activate, \ minmax_face_loop, \ minmax_face_resign, \ - minmax_face_wants_background_task, \ + minmax_face_advise, \ }) #endif // MINMAX_FACE_H_ diff --git a/movement/watch_faces/sensor/thermistor_logging_face.c b/movement/watch_faces/sensor/thermistor_logging_face.c index fe34e2cc..171daf27 100644 --- a/movement/watch_faces/sensor/thermistor_logging_face.c +++ b/movement/watch_faces/sensor/thermistor_logging_face.c @@ -127,9 +127,13 @@ void thermistor_logging_face_resign(void *context) { (void) context; } -bool thermistor_logging_face_wants_background_task(void *context) { +movement_watch_face_advisory_t thermistor_logging_face_advise(void *context) { (void) context; + movement_watch_face_advisory_t retval = { 0 }; + // this will get called at the top of each minute, so all we check is if we're at the top of the hour as well. // if we are, we ask for a background task. - return watch_rtc_get_date_time().unit.minute == 0; + retval.wants_background_task = watch_rtc_get_date_time().unit.minute == 0; + + return retval; } diff --git a/movement/watch_faces/sensor/thermistor_logging_face.h b/movement/watch_faces/sensor/thermistor_logging_face.h index 346f23f7..a32a274b 100644 --- a/movement/watch_faces/sensor/thermistor_logging_face.h +++ b/movement/watch_faces/sensor/thermistor_logging_face.h @@ -74,14 +74,14 @@ void thermistor_logging_face_setup(uint8_t watch_face_index, void ** context_ptr void thermistor_logging_face_activate(void *context); bool thermistor_logging_face_loop(movement_event_t event, void *context); void thermistor_logging_face_resign(void *context); -bool thermistor_logging_face_wants_background_task(void *context); +movement_watch_face_advisory_t thermistor_logging_face_advise(void *context); #define thermistor_logging_face ((const watch_face_t){ \ thermistor_logging_face_setup, \ thermistor_logging_face_activate, \ thermistor_logging_face_loop, \ thermistor_logging_face_resign, \ - thermistor_logging_face_wants_background_task, \ + thermistor_logging_face_advise, \ }) #endif // THERMISTOR_LOGGING_FACE_H_ diff --git a/movement/watch_faces/settings/nanosec_face.c b/movement/watch_faces/settings/nanosec_face.c index 23ff1040..ed5d7329 100644 --- a/movement/watch_faces/settings/nanosec_face.c +++ b/movement/watch_faces/settings/nanosec_face.c @@ -361,11 +361,15 @@ void nanosec_face_resign(void *context) { } // Background freq correction -bool nanosec_face_wants_background_task(void *context) { +movement_watch_face_advisory_t nanosec_face_advise(void *context) { (void) context; - if (nanosec_state.correction_profile == 0) - return 0; // No need for background correction if we are on profile 0 - static hardware correction. - watch_date_time date_time = watch_rtc_get_date_time(); + movement_watch_face_advisory_t retval = { 0 }; - return date_time.unit.minute % nanosec_state.correction_cadence == 0; + // No need for background correction if we are on profile 0 - static hardware correction. + if (nanosec_state.correction_profile != 0) { + watch_date_time date_time = watch_rtc_get_date_time(); + retval.wants_background_task = date_time.unit.minute % nanosec_state.correction_cadence == 0; + } + + return retval; } diff --git a/movement/watch_faces/settings/nanosec_face.h b/movement/watch_faces/settings/nanosec_face.h index 58167ee7..105773ae 100644 --- a/movement/watch_faces/settings/nanosec_face.h +++ b/movement/watch_faces/settings/nanosec_face.h @@ -90,7 +90,7 @@ void nanosec_face_setup(uint8_t watch_face_index, void ** context_ptr); void nanosec_face_activate(void *context); bool nanosec_face_loop(movement_event_t event, void *context); void nanosec_face_resign(void *context); -bool nanosec_face_wants_background_task(void *context); +movement_watch_face_advisory_t nanosec_face_advise(void *context); void nanosec_ui_save(void); void nanosec_save(void); float nanosec_get_aging(void); @@ -101,7 +101,7 @@ float nanosec_get_aging(void); nanosec_face_activate, \ nanosec_face_loop, \ nanosec_face_resign, \ - nanosec_face_wants_background_task, \ + nanosec_face_advise, \ }) #endif // NANOSEC_FACE_H_