refactor movement's 24h mode to a function call

This commit is contained in:
joeycastillo 2024-09-29 08:02:20 -04:00
parent 63e0981693
commit c5e5bc1200
27 changed files with 61 additions and 48 deletions

View File

@ -337,6 +337,14 @@ void movement_set_button_should_sound(bool value) {
movement_state.settings.bit.button_should_sound = value;
}
movement_clock_mode_t movement_clock_mode_24h(void) {
return movement_state.settings.bit.clock_mode_24h ? MOVEMENT_CLOCK_MODE_24H : MOVEMENT_CLOCK_MODE_12H;
}
void movement_set_clock_mode_24h(movement_clock_mode_t value) {
movement_state.settings.bit.clock_mode_24h = (value == MOVEMENT_CLOCK_MODE_24H);
}
void app_init(void) {
_watch_init();

View File

@ -41,6 +41,12 @@
// stuff we'll want to make available to all watch faces and stash in the BKUP[3] register.
// This allows these preferences to be stored before entering BACKUP mode and and restored after waking from reset.
typedef enum {
MOVEMENT_CLOCK_MODE_12H = 0,
MOVEMENT_CLOCK_MODE_24H,
MOVEMENT_NUM_CLOCK_MODES
} movement_clock_mode_t;
// movement_settings_t contains global settings that cover watch behavior, including preferences around clock and unit
// display, time zones, buzzer behavior, LED color and low energy mode timeouts.
typedef union {
@ -321,3 +327,6 @@ int32_t movement_get_current_timezone_offset(void);
bool movement_button_should_sound(void);
void movement_set_button_should_sound(bool value);
movement_clock_mode_t movement_clock_mode_24h(void);
void movement_set_clock_mode_24h(movement_clock_mode_t value);

View File

@ -53,11 +53,7 @@ typedef struct {
} clock_state_t;
static bool clock_is_in_24h_mode(movement_settings_t *settings) {
#ifdef CLOCK_FACE_24H_ONLY
return true;
#else
return settings->bit.clock_mode_24h;
#endif
return movement_clock_mode_24h();
}
static bool clock_should_set_leading_zero(movement_settings_t *settings) {
@ -89,7 +85,7 @@ static bool clock_is_pm(watch_date_time date_time) {
}
static void clock_indicate_pm(movement_settings_t *settings, watch_date_time date_time) {
if (settings->bit.clock_mode_24h) { return; }
if (movement_clock_mode_24h()) { return; }
clock_indicate(WATCH_INDICATOR_PM, clock_is_pm(date_time));
}

View File

@ -77,7 +77,7 @@ void close_enough_clock_face_activate(movement_settings_t *settings, void *conte
watch_stop_tick_animation();
}
if (settings->bit.clock_mode_24h) {
if (movement_clock_mode_24h()) {
watch_set_indicator(WATCH_INDICATOR_24H);
}
@ -155,7 +155,7 @@ bool close_enough_clock_face_loop(movement_event_t event, movement_settings_t *s
close_enough_hour = (close_enough_hour + 1) % 24;
}
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
// if we are in 12 hour mode, do some cleanup.
if (close_enough_hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);

View File

@ -102,7 +102,7 @@ bool french_revolutionary_face_loop(movement_event_t event, movement_settings_t
else { watch_display_string("--", 8); }
break;
case EVENT_LIGHT_LONG_PRESS:
// In case anyone really wants that upper time in 12-hour format. I thought about using the global setting (settings->bit.clock_mode_24h)
// In case anyone really wants that upper time in 12-hour format. I thought about using the global setting (movement_clock_mode_24h())
// for this preference, but thought someone who prefers 12-hour format normally, might prefer 24hr when compared to a 10hr decimal day,
// so this is separate for now.
state->use_am_pm = !state->use_am_pm;

View File

@ -30,7 +30,7 @@ static void _minimal_clock_face_update_display(movement_settings_t *settings) {
watch_date_time date_time = watch_rtc_get_date_time();
char buffer[11];
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
date_time.unit.hour %= 12;
sprintf(buffer, "%2d%02d ", date_time.unit.hour, date_time.unit.minute);
} else {

View File

@ -83,7 +83,7 @@ void minute_repeater_decimal_face_activate(movement_settings_t *settings, void *
if (watch_tick_animation_is_running()) watch_stop_tick_animation();
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
@ -138,7 +138,7 @@ bool minute_repeater_decimal_face_loop(movement_event_t event, movement_settings
sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second);
} else {
// other stuff changed; let's do it all.
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
// if we are in 12 hour mode, do some cleanup.
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);
@ -183,7 +183,7 @@ bool minute_repeater_decimal_face_loop(movement_event_t event, movement_settings
int minutes = date_time.unit.minute % 10;
// chiming hours
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
hours = date_time.unit.hour % 12;
if (hours == 0) hours = 12;
}

View File

@ -68,7 +68,7 @@ void repetition_minute_face_activate(movement_settings_t *settings, void *contex
if (watch_tick_animation_is_running()) watch_stop_tick_animation();
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
@ -123,7 +123,7 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se
sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second);
} else {
// other stuff changed; let's do it all.
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
// if we are in 12 hour mode, do some cleanup.
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);
@ -170,7 +170,7 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se
int minutes = date_time.unit.minute % 15;
// chiming hours
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
hours = date_time.unit.hour % 12;
if (hours == 0) hours = 12;
}

View File

@ -60,7 +60,7 @@ void simple_clock_bin_led_face_activate(movement_settings_t *settings, void *con
if (watch_tick_animation_is_running()) watch_stop_tick_animation();
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
@ -149,7 +149,7 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t
sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second);
} else {
// other stuff changed; let's do it all.
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
// if we are in 12 hour mode, do some cleanup.
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);
@ -187,7 +187,7 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t
date_time = watch_rtc_get_date_time();
state->flashing_state = 1 + 128;
state->ticks = 4;
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
date_time.unit.hour %= 12;
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
}

View File

@ -50,7 +50,7 @@ void weeknumber_clock_face_activate(movement_settings_t *settings, void *context
if (watch_tick_animation_is_running()) watch_stop_tick_animation();
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
@ -100,7 +100,7 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set
sprintf(buf, "%02d%02d", date_time.unit.minute, watch_utility_get_weeknumber(date_time.unit.year, date_time.unit.month, date_time.unit.day));
} else {
// other stuff changed; let's do it all.
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
// if we are in 12 hour mode, do some cleanup.
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);

View File

@ -174,7 +174,7 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
if (refresh_face) {
watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
watch_set_colon();
if (settings->bit.clock_mode_24h)
if (movement_clock_mode_24h())
watch_set_indicator(WATCH_INDICATOR_24H);
state->previous_date_time = REFRESH_TIME;
@ -198,7 +198,7 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second);
} else {
/* Other stuff changed; Let's do it all. */
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
/* If we are in 12 hour mode, do some cleanup. */
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);

View File

@ -296,7 +296,7 @@ static void _activity_update_logging_screen(movement_settings_t *settings, activ
watch_clear_indicator(WATCH_INDICATOR_LAP);
watch_date_time now = watch_rtc_get_date_time();
uint8_t hour = now.unit.hour;
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
watch_clear_indicator(WATCH_INDICATOR_24H);
if (hour < 12)
watch_clear_indicator(WATCH_INDICATOR_PM);

View File

@ -73,7 +73,7 @@ static void _alarm_face_draw(movement_settings_t *settings, alarm_state_t *state
}
//handle am/pm for hour display
uint8_t h = state->alarm[state->alarm_idx].hour;
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
if (h >= 12) {
watch_set_indicator(WATCH_INDICATOR_PM);
h %= 12;

View File

@ -448,7 +448,7 @@ static void _setting_display(movement_event_t event, movement_settings_t *settin
int i = state->current_index + 1;
if (state->current_page > 2) {
watch_set_colon();
if (settings->bit.clock_mode_24h) {
if (movement_clock_mode_24h()) {
watch_set_indicator(WATCH_INDICATOR_24H);
sprintf(buf, "%s%2d%2d%02d ", settings_titles[state->current_page], i, date_time.unit.hour, date_time.unit.minute);
} else {

View File

@ -602,7 +602,7 @@ bool endless_runner_face_loop(movement_event_t event, movement_settings_t *setti
display_title(state);
break;
case EVENT_LOW_ENERGY_UPDATE:
display_time(watch_rtc_get_date_time(), settings->bit.clock_mode_24h);
display_time(watch_rtc_get_date_time(), movement_clock_mode_24h());
break;
default:
return movement_default_loop_handler(event, settings);

View File

@ -253,7 +253,7 @@ static void _planetary_hours(movement_settings_t *settings, planetary_hours_stat
return;
}
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
// roll over hour iterator
if ( state->hour < 0 ) state->hour = 23;
@ -305,7 +305,7 @@ static void _planetary_hours(movement_settings_t *settings, planetary_hours_stat
else if ( scratch_time.unit.minute < 59 ) scratch_time.unit.minute++;
// if we are in 12 hour mode, do some cleanup
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
if (scratch_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);
} else {

View File

@ -218,11 +218,11 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
return;
}
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
// PM for night hours, otherwise the night hours are counted from 13
if ( state->night ) {
if (settings->bit.clock_mode_24h) night_hour_count = 12;
if (movement_clock_mode_24h()) night_hour_count = 12;
else watch_set_indicator(WATCH_INDICATOR_PM);
}

View File

@ -165,7 +165,7 @@ static void show_main_screen(solstice_state_t *state) {
static void show_date_time(movement_settings_t *settings, solstice_state_t *state) {
char buf[11];
watch_date_time date_time = state->datetimes[state->index];
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);
} else {

View File

@ -93,7 +93,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
}
watch_set_colon();
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
rise += hours_from_utc;
set += hours_from_utc;
@ -113,7 +113,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
if (date_time.reg < scratch_time.reg || show_next_match) {
if (state->rise_index == 0 || show_next_match) {
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM);
else watch_clear_indicator(WATCH_INDICATOR_PM);
}
@ -140,7 +140,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
if (date_time.reg < scratch_time.reg || show_next_match) {
if (state->rise_index == 0 || show_next_match) {
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM);
else watch_clear_indicator(WATCH_INDICATOR_PM);
}

View File

@ -38,7 +38,7 @@ void _wake_face_update_display(movement_settings_t *settings, wake_face_state_t
uint8_t hour = state->hour;
watch_clear_display();
if ( settings->bit.clock_mode_24h )
if ( movement_clock_mode_24h() )
watch_set_indicator(WATCH_INDICATOR_24H);
else {
if ( hour >= 12 )

View File

@ -50,7 +50,7 @@ static void _lis2dw_logging_face_update_display(movement_settings_t *settings, l
} else {
date_time = logger_state->data[pos].timestamp;
watch_set_colon();
if (settings->bit.clock_mode_24h) {
if (movement_clock_mode_24h()) {
watch_set_indicator(WATCH_INDICATOR_24H);
} else {
if (date_time.unit.hour > 11) watch_set_indicator(WATCH_INDICATOR_PM);

View File

@ -100,18 +100,18 @@ bool thermistor_logging_face_loop(movement_event_t event, movement_settings_t *s
break;
case EVENT_LIGHT_BUTTON_DOWN:
logger_state->ts_ticks = 2;
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, settings->bit.clock_mode_24h);
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, movement_clock_mode_24h());
break;
case EVENT_ALARM_BUTTON_DOWN:
logger_state->display_index = (logger_state->display_index + 1) % THERMISTOR_LOGGING_NUM_DATA_POINTS;
logger_state->ts_ticks = 0;
// fall through
case EVENT_ACTIVATE:
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, settings->bit.clock_mode_24h);
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, movement_clock_mode_24h());
break;
case EVENT_TICK:
if (logger_state->ts_ticks && --logger_state->ts_ticks == 0) {
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, settings->bit.clock_mode_24h);
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, movement_clock_mode_24h());
}
break;
case EVENT_BACKGROUND_TASK:

View File

@ -191,7 +191,7 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
char buf[11];
if (current_page < 3) {
watch_set_colon();
if (settings->bit.clock_mode_24h) {
if (movement_clock_mode_24h()) {
watch_set_indicator(WATCH_INDICATOR_24H);
sprintf(buf,
"%s %2d%02d%02d",

View File

@ -51,7 +51,7 @@ void simple_clock_face_activate(movement_settings_t *settings, void *context) {
if (watch_tick_animation_is_running()) watch_stop_tick_animation();
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
@ -106,7 +106,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
watch_display_text(WATCH_POSITION_SECONDS, buf + 2);
} else {
// other stuff changed; let's do it all.
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
// if we are in 12 hour mode, do some cleanup.
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);

View File

@ -68,7 +68,7 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
watch_date_time date_time;
switch (event.event_type) {
case EVENT_ACTIVATE:
if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H);
watch_set_colon();
state->previous_date_time = 0xFFFFFFFF;
// fall through
@ -93,7 +93,7 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
}
} else {
// other stuff changed; let's do it all.
if (!settings->bit.clock_mode_24h) {
if (!movement_clock_mode_24h()) {
// if we are in 12 hour mode, do some cleanup.
if (date_time.unit.hour < 12) {
watch_clear_indicator(WATCH_INDICATOR_PM);

View File

@ -84,7 +84,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
char buf[8];
switch (state->current_page) {
case PREFERENCES_PAGE_CLOCK_MODE:
if (settings->bit.clock_mode_24h) watch_display_text(WATCH_POSITION_BOTTOM, "24h");
if (movement_clock_mode_24h()) watch_display_text(WATCH_POSITION_BOTTOM, "24h");
else watch_display_text(WATCH_POSITION_BOTTOM, "12h");
break;
case PREFERENCES_PAGE_BUTTON_SOUND:
@ -179,7 +179,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
case EVENT_ALARM_BUTTON_UP:
switch (state->current_page) {
case PREFERENCES_PAGE_CLOCK_MODE:
settings->bit.clock_mode_24h = !settings->bit.clock_mode_24h;
movement_set_clock_mode_24h(((movement_clock_mode_24h() + 1) % MOVEMENT_NUM_CLOCK_MODES));
break;
case PREFERENCES_PAGE_BUTTON_SOUND:
movement_set_button_should_sound(!movement_button_should_sound());

View File

@ -132,7 +132,7 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
watch_display_text(WATCH_POSITION_TOP_RIGHT, " ");
if (current_page < 3) {
watch_set_colon();
if (settings->bit.clock_mode_24h) {
if (movement_clock_mode_24h()) {
watch_set_indicator(WATCH_INDICATOR_24H);
sprintf(buf, "%2d%02d%02d", date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
} else {