refactor: watch faces no longer need a pointer to settings!

This commit is contained in:
joeycastillo
2024-09-29 09:59:49 -04:00
parent 3bd8f8d51f
commit e88359d1d5
201 changed files with 1180 additions and 1553 deletions

View File

@@ -41,8 +41,7 @@
static const float phase_changes[] = {0, 1, 6.38264692644, 8.38264692644, 13.76529385288, 15.76529385288, 21.14794077932, 23.14794077932, 28.53058770576, 29.53058770576};
void moon_phase_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void moon_phase_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(moon_phase_state_t));
@@ -50,12 +49,11 @@ void moon_phase_face_setup(movement_settings_t *settings, uint8_t watch_face_ind
}
}
void moon_phase_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void moon_phase_face_activate(void *context) {
(void) context;
}
static void _update(movement_settings_t *settings, moon_phase_state_t *state, uint32_t offset) {
static void _update(moon_phase_state_t *state, uint32_t offset) {
(void)state;
char buf[11];
watch_date_time date_time = watch_rtc_get_date_time();
@@ -132,23 +130,23 @@ static void _update(movement_settings_t *settings, moon_phase_state_t *state, ui
watch_display_string(buf, 2);
}
bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
bool moon_phase_face_loop(movement_event_t event, void *context) {
moon_phase_state_t *state = (moon_phase_state_t *)context;
watch_date_time date_time;
switch (event.event_type) {
case EVENT_ACTIVATE:
_update(settings, state, state->offset);
_update(state, state->offset);
break;
case EVENT_TICK:
// only update once an hour
date_time = watch_rtc_get_date_time();
if ((date_time.unit.minute == 0) && (date_time.unit.second == 0)) _update(settings, state, state->offset);
if ((date_time.unit.minute == 0) && (date_time.unit.second == 0)) _update(state, state->offset);
break;
case EVENT_LOW_ENERGY_UPDATE:
// update at the top of the hour OR if we're entering sleep mode with an offset.
// also, in sleep mode, always show the current moon phase (offset = 0).
if (state->offset || (watch_rtc_get_date_time().unit.minute == 0)) _update(settings, state, 0);
if (state->offset || (watch_rtc_get_date_time().unit.minute == 0)) _update(state, 0);
// and kill the offset so when the wearer wakes up, it matches what's on screen.
state->offset = 0;
// finally: clear out the last two digits and replace them with the sleep mode indicator
@@ -159,24 +157,23 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings,
// Pressing the alarm adds an offset of one day to the displayed value,
// so you can see moon phases in the future.
state->offset += 86400;
_update(settings, state, state->offset);
_update(state, state->offset);
break;
case EVENT_ALARM_LONG_PRESS:
state->offset = 0;
_update(settings, state, state->offset);
_update(state, state->offset);
break;
case EVENT_TIMEOUT:
// QUESTION: Should timeout reset offset to 0?
break;
default:
return movement_default_loop_handler(event, settings);
return movement_default_loop_handler(event);
}
return true;
}
void moon_phase_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void moon_phase_face_resign(void *context) {
moon_phase_state_t *state = (moon_phase_state_t *)context;
state->offset = 0;
}