Support leading zero representation for 24h clock

Toggle between default behavior and leading zero with long-press of alarm
button on page with 24h setting.
This commit is contained in:
Jonathan Glines
2023-09-24 14:00:13 -04:00
parent 5c94111ea2
commit f633b7634b
18 changed files with 132 additions and 31 deletions

View File

@@ -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;
@@ -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);
}
}

View File

@@ -99,6 +99,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) {
@@ -108,6 +109,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],
@@ -119,6 +124,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

View File

@@ -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 ) {
@@ -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;
@@ -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
@@ -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);
}

View File

@@ -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();
@@ -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 ) {
@@ -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;
@@ -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);

View File

@@ -85,7 +85,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 (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H);
rise += hours_from_utc;
set += hours_from_utc;
@@ -105,12 +105,17 @@ 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) {
bool set_leading_zero = false;
if (!settings->bit.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);
} else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) {
set_leading_zero = true;
}
sprintf(buf, "rI%2d%2d%02d ", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute);
watch_display_string(buf, 0);
if (set_leading_zero)
watch_display_string("0", 4);
return;
} else {
show_next_match = true;
@@ -132,12 +137,17 @@ 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) {
bool set_leading_zero = false;
if (!settings->bit.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);
} else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) {
set_leading_zero = true;
}
sprintf(buf, "SE%2d%2d%02d ", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute);
watch_display_string(buf, 0);
if (set_leading_zero)
watch_display_string("0", 4);
return;
} else {
show_next_match = true;

View File

@@ -50,12 +50,15 @@ 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 )
watch_set_indicator(WATCH_INDICATOR_24H);
else {
bool set_leading_zero = false;
if ( !settings->bit.clock_mode_24h ) {
if ( hour >= 12 )
watch_set_indicator(WATCH_INDICATOR_PM);
hour = hour % 12 ? hour % 12 : 12;
} else if ( !settings->bit.clock_24h_leading_zero ) {
watch_set_indicator(WATCH_INDICATOR_24H);
} else if ( hour < 10 ) {
set_leading_zero = true;
}
if ( state->mode )
@@ -66,6 +69,8 @@ void _wake_face_update_display(movement_settings_t *settings, wake_face_state_t
watch_set_colon();
watch_display_string(lcdbuf, 0);
if ( set_leading_zero )
watch_display_string("0", 4);
}
//