Made the faces I care about not need to continuously re-find the timezone

This commit is contained in:
David Volovskiy
2024-08-02 07:37:30 -04:00
parent 4c546b14dc
commit bae8c65825
7 changed files with 16 additions and 18 deletions

View File

@@ -139,6 +139,7 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings,
switch (event.event_type) {
case EVENT_ACTIVATE:
_update(settings, state, state->offset);
break;
case EVENT_TICK:

View File

@@ -54,8 +54,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
}
watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
int16_t tz = get_timezone_offset(settings->bit.time_zone, date_time);
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, state->tz * 60, 0); // the current date / time in UTC
watch_date_time scratch_time; // scratchpad, contains different values at different times
scratch_time.reg = utc_now.reg;
@@ -70,7 +69,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
// sunriset returns the rise/set times as signed decimal hours in UTC.
// this can mean hours below 0 or above 31, which won't fit into a watch_date_time struct.
// to deal with this, we set aside the offset in hours, and add it back before converting it to a watch_date_time.
double hours_from_utc = ((double)tz) / 60.0;
double hours_from_utc = ((double)state->tz) / 60.0;
// we loop twice because if it's after sunset today, we need to recalculate to display values for tomorrow.
for(int i = 0; i < 2; i++) {
@@ -317,6 +316,7 @@ void sunrise_sunset_face_activate(movement_settings_t *settings, void *context)
movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
state->working_latitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.latitude);
state->working_longitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.longitude);
state->tz = get_timezone_offset(settings->bit.time_zone, watch_rtc_get_date_time());
}
bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {

View File

@@ -52,6 +52,7 @@ typedef struct {
uint8_t rise_index;
uint8_t active_digit;
bool location_changed;
int16_t tz;
watch_date_time rise_set_expires;
sunrise_sunset_lat_lon_settings_t working_latitude;
sunrise_sunset_lat_lon_settings_t working_longitude;