movement internal time is now UTC

This commit is contained in:
joeycastillo
2024-10-05 01:27:07 -04:00
parent 411a64f44b
commit 12241386ea
11 changed files with 72 additions and 35 deletions

View File

@@ -57,7 +57,7 @@ bool beats_face_loop(movement_event_t event, void *context) {
switch (event.event_type) {
case EVENT_ACTIVATE:
case EVENT_TICK:
date_time = watch_rtc_get_date_time();
date_time = movement_get_local_date_time();
centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_get_current_timezone_offset());
if (centibeats == state->last_centibeat_displayed) {
// we missed this update, try again next subsecond
@@ -73,7 +73,7 @@ bool beats_face_loop(movement_event_t event, void *context) {
break;
case EVENT_LOW_ENERGY_UPDATE:
if (!watch_sleep_animation_is_running()) watch_start_sleep_animation(432);
date_time = watch_rtc_get_date_time();
date_time = movement_get_local_date_time();
centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_get_current_timezone_offset());
sprintf(buf, "%4lu ", centibeats / 100);

View File

@@ -245,11 +245,11 @@ bool clock_face_loop(movement_event_t event, void *context) {
switch (event.event_type) {
case EVENT_LOW_ENERGY_UPDATE:
clock_start_tick_tock_animation();
clock_display_low_energy(watch_rtc_get_date_time());
clock_display_low_energy(movement_get_local_date_time());
break;
case EVENT_TICK:
case EVENT_ACTIVATE:
current = watch_rtc_get_date_time();
current = movement_get_local_date_time();
clock_display_clock(state, current);
@@ -282,7 +282,7 @@ movement_watch_face_advisory_t clock_face_advise(void *context) {
clock_state_t *state = (clock_state_t *) context;
if (state->time_signal_enabled) {
watch_date_time date_time = watch_rtc_get_date_time();
watch_date_time date_time = movement_get_local_date_time();
retval.wants_background_task = date_time.unit.minute == 0;
}

View File

@@ -42,11 +42,6 @@ void world_clock_face_setup(uint8_t watch_face_index, void ** context_ptr) {
memset(*context_ptr, 0, sizeof(world_clock_state_t));
world_clock_state_t *state = (world_clock_state_t *)*context_ptr;
state->settings.bit.timezone_index = 15;
uint8_t backup_register = movement_claim_backup_register();
if (backup_register) {
state->settings.reg = watch_get_backup_data(backup_register);
state->backup_register = backup_register;
}
}
}
@@ -72,8 +67,7 @@ static bool world_clock_face_do_display_mode(movement_event_t event, world_clock
// fall through
case EVENT_TICK:
case EVENT_LOW_ENERGY_UPDATE:
date_time = watch_rtc_get_date_time();
date_time = watch_utility_date_time_convert_zone(date_time, movement_get_current_timezone_offset(), state->current_offset);
date_time = movement_get_date_time_in_zone(state->settings.bit.timezone_index);
previous_date_time = state->previous_date_time;
state->previous_date_time = date_time.reg;
if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) {

View File

@@ -156,7 +156,7 @@ static void _alarm_update_alarm_enabled(alarm_state_t *state) {
break;
} else {
if (!now_init) {
now = watch_rtc_get_date_time();
now = movement_get_local_date_time();
now_init = true;
weekday_idx = _get_weekday_idx(now);
now_minutes_of_day = now.unit.hour * 60 + now.unit.minute;
@@ -244,7 +244,7 @@ movement_watch_face_advisory_t advanced_alarm_face_advise(void *context) {
alarm_state_t *state = (alarm_state_t *)context;
movement_watch_face_advisory_t retval = { 0 };
watch_date_time now = watch_rtc_get_date_time();
watch_date_time now = movement_get_local_date_time();
// just a failsafe: never fire more than one alarm within a minute
if (state->alarm_handled_minute == now.unit.minute) return retval;
state->alarm_handled_minute = now.unit.minute;

View File

@@ -69,7 +69,7 @@ static void schedule_countdown(countdown_state_t *state) {
// Calculate the new state->now_ts but don't update it until we've updated the target -
// avoid possible race where the old target is compared to the new time and immediately triggers
uint32_t new_now = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_get_current_timezone_offset());
uint32_t new_now = watch_utility_date_time_to_unix_time(movement_get_utc_date_time(), movement_get_current_timezone_offset());
state->target_ts = watch_utility_offset_timestamp(new_now, state->hours, state->minutes, state->seconds);
state->now_ts = new_now;
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, movement_get_current_timezone_offset());
@@ -196,7 +196,7 @@ void countdown_face_setup(uint8_t watch_face_index, void ** context_ptr) {
void countdown_face_activate(void *context) {
countdown_state_t *state = (countdown_state_t *)context;
if(state->mode == cd_running) {
watch_date_time now = watch_rtc_get_date_time();
watch_date_time now = movement_get_utc_date_time();
state->now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset());
watch_set_indicator(WATCH_INDICATOR_SIGNAL);
}

View File

@@ -62,7 +62,7 @@ static void _sunrise_sunset_face_update(sunrise_sunset_state_t *state) {
return;
}
watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
watch_date_time date_time = movement_get_local_date_time(); // the current local date / time
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_get_current_timezone_offset(), 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;
@@ -338,7 +338,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, void *context) {
// if entering low energy mode, start tick animation
if (event.event_type == EVENT_LOW_ENERGY_UPDATE && !watch_sleep_animation_is_running()) watch_start_sleep_animation(1000);
// check if we need to update the display
watch_date_time date_time = watch_rtc_get_date_time();
watch_date_time date_time = movement_get_local_date_time();
if (date_time.reg >= state->rise_set_expires.reg) {
// and on the off chance that this happened before EVENT_TIMEOUT snapped us back to rise/set 0, go back now
state->rise_index = 0;

View File

@@ -53,7 +53,7 @@ bool voltage_face_loop(movement_event_t event, void *context) {
_voltage_face_update_display();
break;
case EVENT_TICK:
date_time = watch_rtc_get_date_time();
date_time = movement_get_local_date_time();
if (date_time.unit.second % 5 == 4) {
watch_set_indicator(WATCH_INDICATOR_SIGNAL);
} else if (date_time.unit.second % 5 == 0) {

View File

@@ -66,7 +66,7 @@ static void _handle_alarm_button(watch_date_time date_time, uint8_t current_page
}
if (date_time.unit.day > days_in_month(date_time.unit.month, date_time.unit.year + WATCH_RTC_REFERENCE_YEAR))
date_time.unit.day = 1;
watch_rtc_set_date_time(date_time);
movement_set_local_date_time(date_time);
}
static void _abort_quick_ticks() {
@@ -90,7 +90,7 @@ void set_time_face_activate(void *context) {
bool set_time_face_loop(movement_event_t event, void *context) {
uint8_t current_page = *((uint8_t *)context);
watch_date_time date_time = watch_rtc_get_date_time();
watch_date_time date_time = movement_get_local_date_time();
switch (event.event_type) {
case EVENT_TICK: