refactor watch faces to use new advisory API
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user