Time now auto-updates with DST
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "filesystem.h"
|
||||
#include "movement.h"
|
||||
#include "shell.h"
|
||||
#include "watch_utility.h"
|
||||
|
||||
#ifndef MOVEMENT_FIRMWARE
|
||||
#include "movement_config.h"
|
||||
@@ -467,6 +468,21 @@ uint8_t movement_claim_backup_register(void) {
|
||||
return movement_state.next_available_backup_register++;
|
||||
}
|
||||
|
||||
int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time) {
|
||||
if (!movement_state.settings.bit.dst_active) return movement_timezone_offsets[timezone_idx];
|
||||
uint8_t dst_result = is_dst(date_time);
|
||||
switch (dst_result)
|
||||
{
|
||||
case DST_STARTED:
|
||||
case DST_OCCURRING:
|
||||
return movement_timezone_offsets[movement_dst_jump_table[timezone_idx]];
|
||||
case DST_ENDING:
|
||||
case DST_ENDED:
|
||||
default:
|
||||
return movement_timezone_offsets[timezone_idx];
|
||||
}
|
||||
}
|
||||
|
||||
void app_init(void) {
|
||||
#if defined(NO_FREQCORR)
|
||||
watch_rtc_freqcorr_write(0, 0);
|
||||
|
||||
@@ -314,5 +314,6 @@ void movement_play_alarm(void);
|
||||
void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);
|
||||
|
||||
uint8_t movement_claim_backup_register(void);
|
||||
int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time);
|
||||
|
||||
#endif // MOVEMENT_H_
|
||||
|
||||
@@ -280,12 +280,28 @@ void clock_face_resign(movement_settings_t *settings, void *context) {
|
||||
(void) context;
|
||||
}
|
||||
|
||||
bool clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
clock_state_t *state = (clock_state_t *) context;
|
||||
if (!state->time_signal_enabled) return false;
|
||||
static void check_and_act_on_daylight_savings(bool dst_active, watch_date_time date_time) {
|
||||
if (!dst_active) return;
|
||||
uint8_t dst_result = is_dst(date_time);
|
||||
switch (dst_result)
|
||||
{
|
||||
case DST_STARTED:
|
||||
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
||||
break;
|
||||
case DST_ENDING:
|
||||
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
watch_rtc_set_date_time(date_time);
|
||||
}
|
||||
|
||||
bool clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||
clock_state_t *state = (clock_state_t *) context;
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
check_and_act_on_daylight_savings(settings->bit.dst_active, date_time);
|
||||
if (!state->time_signal_enabled) return false;
|
||||
|
||||
return date_time.unit.minute == 0;
|
||||
}
|
||||
|
||||
@@ -150,12 +150,28 @@ void simple_clock_face_resign(movement_settings_t *settings, void *context) {
|
||||
(void) context;
|
||||
}
|
||||
|
||||
bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
simple_clock_state_t *state = (simple_clock_state_t *)context;
|
||||
if (!state->signal_enabled) return false;
|
||||
static void check_and_act_on_daylight_savings(bool dst_active, watch_date_time date_time) {
|
||||
if (!dst_active) return;
|
||||
uint8_t dst_result = is_dst(date_time);
|
||||
switch (dst_result)
|
||||
{
|
||||
case DST_STARTED:
|
||||
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
||||
break;
|
||||
case DST_ENDING:
|
||||
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
watch_rtc_set_date_time(date_time);
|
||||
}
|
||||
|
||||
bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||
simple_clock_state_t *state = (simple_clock_state_t *)context;
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
check_and_act_on_daylight_savings(settings->bit.dst_active, date_time);
|
||||
if (!state->signal_enabled) return false;
|
||||
|
||||
return date_time.unit.minute == 0;
|
||||
}
|
||||
|
||||
@@ -67,13 +67,6 @@ static void _handle_alarm_button(movement_settings_t *settings, watch_date_time
|
||||
if (settings->bit.time_zone > 40) settings->bit.time_zone = 0;
|
||||
break;
|
||||
case 7: // daylight savings time
|
||||
if (settings->bit.dst_active) { // deactivate DST
|
||||
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
|
||||
settings->bit.time_zone = movement_dst_inverse_jump_table[settings->bit.time_zone];
|
||||
} else { // activate DST
|
||||
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
||||
settings->bit.time_zone = movement_dst_jump_table[settings->bit.time_zone];
|
||||
}
|
||||
settings->bit.dst_active = !settings->bit.dst_active;
|
||||
break;
|
||||
}
|
||||
@@ -161,8 +154,9 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
|
||||
watch_clear_colon();
|
||||
sprintf(buf, "%s ", set_time_face_titles[current_page]);
|
||||
} else {
|
||||
int16_t tz = get_timezone_offset(settings->bit.time_zone, date_time);
|
||||
watch_set_colon();
|
||||
sprintf(buf, "%s %3d%02d ", set_time_face_titles[current_page], (int8_t) (movement_timezone_offsets[settings->bit.time_zone] / 60), (int8_t) (movement_timezone_offsets[settings->bit.time_zone] % 60) * (movement_timezone_offsets[settings->bit.time_zone] < 0 ? -1 : 1));
|
||||
sprintf(buf, "%s %3d%02d ", set_time_face_titles[current_page], (int8_t) (tz / 60), (int8_t) (tz % 60) * (tz < 0 ? -1 : 1));
|
||||
}
|
||||
} else { // daylight savings
|
||||
watch_clear_colon();
|
||||
|
||||
Reference in New Issue
Block a user