Skip to content

Commit

Permalink
Merge PR #299 - leading zero representation
Browse files Browse the repository at this point in the history
Adds a movement-wide leading zero 024h representation mode
that's toggleable in the preferences watch face.
Also adds support for the new display mode to existing faces.

I modified the logic a bit to ensure the 24h indicator remains lit
in the simple clock face even when in 024h mode. I also added support
to the more advanced clock face. In the future I will add a compile time
toggle to it as well.

Reviewed-by: Matheus Afonso Martins Moreira <[email protected]>
GitHub-Pull-Request: #299
  • Loading branch information
matheusmoreira committed Sep 3, 2024
2 parents 31d0174 + f633b76 commit 57d3ccb
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 33 deletions.
3 changes: 2 additions & 1 deletion movement/movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ typedef union {
// time-oriented complication like a sunrise/sunset timer, and a simple locale preference could tell an
// altimeter to display feet or meters as easily as it tells a thermometer to display degrees in F or C.
bool clock_mode_24h : 1; // indicates whether clock should use 12 or 24 hour mode.
bool clock_24h_leading_zero : 1; // indicates whether clock should leading zero to indicate 24 hour mode.
bool use_imperial_units : 1; // indicates whether to use metric units (the default) or imperial.
bool alarm_enabled : 1; // indicates whether there is at least one alarm enabled.
uint8_t reserved : 6; // room for more preferences if needed.
uint8_t reserved : 5; // room for more preferences if needed.
} bit;
uint32_t reg;
} movement_settings_t;
Expand Down
6 changes: 3 additions & 3 deletions movement/watch_faces/clock/clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ static void clock_toggle_time_signal(clock_state_t *clock) {
clock_indicate_time_signal(clock);
}

static void clock_display_all(watch_date_time date_time) {
static void clock_display_all(watch_date_time date_time, bool leading_zero) {
char buf[10 + 1];

snprintf(
buf,
sizeof(buf),
"%s%2d%2d%02d%02d",
leading_zero? "%s%02d%02d%02d%02d" : "%s%2d%2d%02d%02d",
watch_utility_get_weekday(date_time),
date_time.unit.day,
date_time.unit.hour,
Expand Down Expand Up @@ -180,7 +180,7 @@ static void clock_display_clock(movement_settings_t *settings, clock_state_t *cl
clock_indicate_pm(settings, current);
current = clock_24h_to_12h(current);
}
clock_display_all(current);
clock_display_all(current, settings->bit.clock_24h_leading_zero);
}
}

Expand Down
7 changes: 6 additions & 1 deletion movement/watch_faces/clock/repetition_minute_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);

// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
Expand Down Expand Up @@ -112,6 +112,7 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se
// ...and set the LAP indicator if low.
if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP);

bool set_leading_zero = false;
if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before seconds is the same, don't waste cycles setting those segments.
watch_display_character_lp_seconds('0' + date_time.unit.second / 10, 8);
Expand All @@ -132,6 +133,8 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se
}
date_time.unit.hour %= 12;
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
} else if (settings->bit.clock_24h_leading_zero && date_time.unit.hour < 10) {
set_leading_zero = true;
}
pos = 0;
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
Expand All @@ -142,6 +145,8 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se
}
}
watch_display_string(buf, pos);
if (set_leading_zero)
watch_display_string("0", 4);
// handle alarm indicator
if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state);
break;
Expand Down
7 changes: 6 additions & 1 deletion movement/watch_faces/clock/simple_clock_bin_led_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);

// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
Expand Down Expand Up @@ -138,6 +138,7 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t
// ...and set the LAP indicator if low.
if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP);

bool set_leading_zero = false;
if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before seconds is the same, don't waste cycles setting those segments.
watch_display_character_lp_seconds('0' + date_time.unit.second / 10, 8);
Expand All @@ -158,6 +159,8 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t
}
date_time.unit.hour %= 12;
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
} else if (settings->bit.clock_24h_leading_zero && date_time.unit.hour < 10) {
set_leading_zero = true;
}
pos = 0;
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
Expand All @@ -168,6 +171,8 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t
}
}
watch_display_string(buf, pos);
if (set_leading_zero)
watch_display_string("0", 4);
// handle alarm indicator
if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state);
}
Expand Down
7 changes: 7 additions & 0 deletions movement/watch_faces/clock/simple_clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
// ...and set the LAP indicator if low.
if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP);

bool set_leading_zero = false;
if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before seconds is the same, don't waste cycles setting those segments.
watch_display_character_lp_seconds('0' + date_time.unit.second / 10, 8);
Expand All @@ -122,6 +123,10 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
}
#endif
if (settings->bit.clock_24h_leading_zero && date_time.unit.hour < 10) {
set_leading_zero = true;
}

pos = 0;
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
if (!watch_tick_animation_is_running()) watch_start_tick_animation(500);
Expand All @@ -131,6 +136,8 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
}
}
watch_display_string(buf, pos);
if (set_leading_zero)
watch_display_string("0", 4);
// handle alarm indicator
if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state);
break;
Expand Down
7 changes: 6 additions & 1 deletion movement/watch_faces/clock/weeknumber_clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);

// handle chime indicator
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
Expand Down Expand Up @@ -94,6 +94,7 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set
// ...and set the LAP indicator if low.
if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP);

bool set_leading_zero = false;
if ((date_time.reg >> 12) == (previous_date_time >> 12) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before minutes is the same.
pos = 6;
Expand All @@ -109,6 +110,8 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set
}
date_time.unit.hour %= 12;
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
} else if (settings->bit.clock_24h_leading_zero && date_time.unit.hour < 10) {
set_leading_zero = true;
}
pos = 0;
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
Expand All @@ -119,6 +122,8 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set
}
}
watch_display_string(buf, pos);
if (set_leading_zero)
watch_display_string("0", 4);
// handle alarm indicator
if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state);
break;
Expand Down
9 changes: 7 additions & 2 deletions movement/watch_faces/clock/world_clock2_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero)
watch_set_indicator(WATCH_INDICATOR_24H);

state->previous_date_time = REFRESH_TIME;
Expand All @@ -188,6 +188,7 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
previous_date_time = state->previous_date_time;
state->previous_date_time = date_time.reg;

bool set_leading_zero = false;
if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
/* Everything before seconds is the same, don't waste cycles setting those segments. */
pos = 8;
Expand All @@ -208,7 +209,9 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
date_time.unit.hour %= 12;
if (date_time.unit.hour == 0)
date_time.unit.hour = 12;
}
} else if (settings->bit.clock_24h_leading_zero && date_time.unit.hour < 10) {
set_leading_zero = true;
}

pos = 0;
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
Expand All @@ -230,6 +233,8 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
}
}
watch_display_string(buf, pos);
if (set_leading_zero)
watch_display_string("0", 4);
break;
case EVENT_ALARM_BUTTON_UP:
state->current_zone = find_selected_zone(state, FORWARD);
Expand Down
7 changes: 6 additions & 1 deletion movement/watch_faces/clock/world_clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);
watch_set_colon();
state->previous_date_time = 0xFFFFFFFF;
// fall through
Expand All @@ -72,6 +72,7 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
previous_date_time = state->previous_date_time;
state->previous_date_time = date_time.reg;

bool set_leading_zero = false;
if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {
// everything before seconds is the same, don't waste cycles setting those segments.
pos = 8;
Expand All @@ -91,6 +92,8 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
}
date_time.unit.hour %= 12;
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
} else if (settings->bit.clock_24h_leading_zero && date_time.unit.hour < 10) {
set_leading_zero = true;
}
pos = 0;
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
Expand All @@ -112,6 +115,8 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
}
}
watch_display_string(buf, pos);
if (set_leading_zero)
watch_display_string("0", 4);
break;
case EVENT_ALARM_LONG_PRESS:
movement_request_tick_frequency(4);
Expand Down
11 changes: 8 additions & 3 deletions movement/watch_faces/complication/activity_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ static void _activity_update_logging_screen(movement_settings_t *settings, activ
}
// Briefly, show time without seconds
else {
bool set_leading_zero = false;
watch_clear_indicator(WATCH_INDICATOR_LAP);
watch_date_time now = watch_rtc_get_date_time();
uint8_t hour = now.unit.hour;
Expand All @@ -304,14 +305,18 @@ static void _activity_update_logging_screen(movement_settings_t *settings, activ
watch_set_indicator(WATCH_INDICATOR_PM);
hour %= 12;
if (hour == 0) hour = 12;
}
else {
watch_set_indicator(WATCH_INDICATOR_24H);
} else {
watch_clear_indicator(WATCH_INDICATOR_PM);
if (!settings->bit.clock_24h_leading_zero)
watch_set_indicator(WATCH_INDICATOR_24H);
else if (hour < 10)
set_leading_zero = true;
}
sprintf(activity_buf, "%2d%02d ", hour, now.unit.minute);
watch_set_colon();
watch_display_string(activity_buf, 4);
if (set_leading_zero)
watch_display_string("0", 4);
}
}

Expand Down
7 changes: 7 additions & 0 deletions movement/watch_faces/complication/alarm_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static void _alarm_face_draw(movement_settings_t *settings, alarm_state_t *state
i = state->alarm[state->alarm_idx].day + 1;
}
//handle am/pm for hour display
bool set_leading_zero = false;
uint8_t h = state->alarm[state->alarm_idx].hour;
if (!settings->bit.clock_mode_24h) {
if (h >= 12) {
Expand All @@ -81,6 +82,10 @@ static void _alarm_face_draw(movement_settings_t *settings, alarm_state_t *state
watch_clear_indicator(WATCH_INDICATOR_PM);
}
if (h == 0) h = 12;
} else if (!settings->bit.clock_24h_leading_zero) {
watch_set_indicator(WATCH_INDICATOR_24H);
} else if (h < 10) {
set_leading_zero = true;
}
sprintf(buf, "%c%c%2d%2d%02d ",
_dow_strings[i][0], _dow_strings[i][1],
Expand All @@ -92,6 +97,8 @@ static void _alarm_face_draw(movement_settings_t *settings, alarm_state_t *state
buf[_blink_idx[state->setting_state]] = buf[_blink_idx2[state->setting_state]] = ' ';
}
watch_display_string(buf, 0);
if (set_leading_zero)
watch_display_string("0", 4);

if (state->is_setting) {
// draw pitch level indicator
Expand Down
7 changes: 6 additions & 1 deletion movement/watch_faces/complication/planetary_hours_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ static void _planetary_hours(movement_settings_t *settings, planetary_hours_stat
uint8_t weekday, planet, planetary_hour;
uint32_t current_hour_epoch;
watch_date_time scratch_time;
bool set_leading_zero = false;

// check if we have a location. If not, display error
if ( state->no_location ) {
Expand All @@ -253,7 +254,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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);

// roll over hour iterator
if ( state->hour < 0 ) state->hour = 23;
Expand Down Expand Up @@ -313,6 +314,8 @@ static void _planetary_hours(movement_settings_t *settings, planetary_hours_stat
}
scratch_time.unit.hour %= 12;
if (scratch_time.unit.hour == 0) scratch_time.unit.hour = 12;
} else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) {
set_leading_zero = true;
}

// planetary ruler of the hour
Expand All @@ -328,6 +331,8 @@ static void _planetary_hours(movement_settings_t *settings, planetary_hours_stat

watch_set_colon();
watch_display_string(buf, 0);
if (set_leading_zero)
watch_display_string("0", 4);

if ( state->ruler == 2 ) _planetary_icon(planet);
}
Expand Down
8 changes: 7 additions & 1 deletion movement/watch_faces/complication/planetary_time_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
double night_hour_count = 0.0;
uint8_t weekday, planet, planetary_hour;
double hour_duration, current_hour, current_minute, current_second;
bool set_leading_zero = false;

watch_set_colon();

Expand All @@ -218,7 +219,7 @@ 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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);

// PM for night hours, otherwise the night hours are counted from 13
if ( state->night ) {
Expand Down Expand Up @@ -246,6 +247,9 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
state->scratch.unit.minute = floor(current_minute);
state->scratch.unit.second = (uint8_t)floor(current_second) % 60;

if (settings->bit.clock_mode_24h && settings->bit.clock_24h_leading_zero && state->scratch.unit.hour < 10)
set_leading_zero = true;

// what weekday is it (0 - 6)
weekday = watch_utility_get_iso8601_weekday_number(state->scratch.unit.year, state->scratch.unit.month, state->scratch.unit.day) - 1;

Expand All @@ -263,6 +267,8 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
else sprintf(buf, "%s h%2d%02d%02d", ruler, state->scratch.unit.hour, state->scratch.unit.minute, state->scratch.unit.second);

watch_display_string(buf, 0);
if (set_leading_zero)
watch_display_string("0", 4);

if ( state->ruler == 2 ) _planetary_icon(planet);

Expand Down
Loading

0 comments on commit 57d3ccb

Please sign in to comment.