mirror of
https://github.com/firewalkwithm3/Sensor-Watch.git
synced 2024-11-22 19:20:30 +08:00
DST roll is now a global variable in watch_rtc
This commit is contained in:
parent
74421c7e65
commit
e50390b673
|
@ -430,6 +430,26 @@ uint8_t movement_claim_backup_register(void) {
|
||||||
return movement_state.next_available_backup_register++;
|
return movement_state.next_available_backup_register++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t check_and_act_on_daylight_savings(watch_date_time date_time) {
|
||||||
|
if (movement_state.settings.bit.dst_active) return date_time.unit.hour;
|
||||||
|
uint8_t dst_result = get_dst_status(date_time);
|
||||||
|
bool dst_skip_rolling_back = get_dst_skip_rolling_back();
|
||||||
|
|
||||||
|
if (dst_skip_rolling_back && (dst_result == DST_ENDED)) {
|
||||||
|
clear_dst_skip_rolling_back();
|
||||||
|
}
|
||||||
|
else if (dst_result == DST_ENDING && !dst_skip_rolling_back) {
|
||||||
|
set_dst_skip_rolling_back();
|
||||||
|
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
|
||||||
|
watch_rtc_set_date_time(date_time);
|
||||||
|
}
|
||||||
|
else if (dst_result == DST_STARTING) {
|
||||||
|
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
||||||
|
watch_rtc_set_date_time(date_time);
|
||||||
|
}
|
||||||
|
return date_time.unit.hour;
|
||||||
|
}
|
||||||
|
|
||||||
int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time) {
|
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];
|
if (!movement_state.settings.bit.dst_active) return movement_timezone_offsets[timezone_idx];
|
||||||
if (dst_occurring(date_time))
|
if (dst_occurring(date_time))
|
||||||
|
|
|
@ -313,6 +313,7 @@ void movement_play_alarm(void);
|
||||||
void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);
|
void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);
|
||||||
|
|
||||||
uint8_t movement_claim_backup_register(void);
|
uint8_t movement_claim_backup_register(void);
|
||||||
|
uint8_t check_and_act_on_daylight_savings(watch_date_time date_time); // Returns the currently set hour
|
||||||
int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time);
|
int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time);
|
||||||
|
|
||||||
#endif // MOVEMENT_H_
|
#endif // MOVEMENT_H_
|
||||||
|
|
|
@ -280,31 +280,16 @@ void clock_face_resign(movement_settings_t *settings, void *context) {
|
||||||
(void) context;
|
(void) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_and_act_on_daylight_savings(movement_settings_t *settings, watch_date_time date_time) {
|
|
||||||
if (!settings ->bit.dst_active) return;
|
|
||||||
uint8_t dst_result = get_dst_status(date_time);
|
|
||||||
|
|
||||||
if (settings ->bit.dst_skip_rolling_back && dst_result == DST_ENDED) {
|
|
||||||
settings ->bit.dst_skip_rolling_back = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (dst_result == DST_ENDING && !settings ->bit.dst_skip_rolling_back) {
|
|
||||||
settings ->bit.dst_skip_rolling_back = true;
|
|
||||||
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
|
|
||||||
watch_rtc_set_date_time(date_time);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (dst_result == DST_STARTING) {
|
|
||||||
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
|
||||||
watch_rtc_set_date_time(date_time);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
bool clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||||
|
(void) settings;
|
||||||
clock_state_t *state = (clock_state_t *) context;
|
clock_state_t *state = (clock_state_t *) context;
|
||||||
watch_date_time date_time = watch_rtc_get_date_time();
|
watch_date_time date_time = watch_rtc_get_date_time();
|
||||||
check_and_act_on_daylight_savings(settings, date_time);
|
uint8_t hour_dst = check_and_act_on_daylight_savings(date_time);
|
||||||
|
if(hour_dst != date_time.unit.hour) {
|
||||||
|
char buf[3 + 1];
|
||||||
|
sprintf(buf, "%2d", hour_dst);
|
||||||
|
watch_display_string(buf, 4);
|
||||||
|
}
|
||||||
if (!state->time_signal_enabled) return false;
|
if (!state->time_signal_enabled) return false;
|
||||||
|
|
||||||
return date_time.unit.minute == 0;
|
return date_time.unit.minute == 0;
|
||||||
|
|
|
@ -230,9 +230,9 @@ void minute_repeater_decimal_face_resign(movement_settings_t *settings, void *co
|
||||||
bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *settings, void *context) {
|
bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||||
(void) settings;
|
(void) settings;
|
||||||
minute_repeater_decimal_state_t *state = (minute_repeater_decimal_state_t *)context;
|
minute_repeater_decimal_state_t *state = (minute_repeater_decimal_state_t *)context;
|
||||||
if (!state->signal_enabled) return false;
|
|
||||||
|
|
||||||
watch_date_time date_time = watch_rtc_get_date_time();
|
watch_date_time date_time = watch_rtc_get_date_time();
|
||||||
|
check_and_act_on_daylight_savings(date_time);
|
||||||
|
if (!state->signal_enabled) return false;
|
||||||
|
|
||||||
return date_time.unit.minute == 0;
|
return date_time.unit.minute == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,9 +213,9 @@ void repetition_minute_face_resign(movement_settings_t *settings, void *context)
|
||||||
bool repetition_minute_face_wants_background_task(movement_settings_t *settings, void *context) {
|
bool repetition_minute_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||||
(void) settings;
|
(void) settings;
|
||||||
repetition_minute_state_t *state = (repetition_minute_state_t *)context;
|
repetition_minute_state_t *state = (repetition_minute_state_t *)context;
|
||||||
if (!state->signal_enabled) return false;
|
|
||||||
|
|
||||||
watch_date_time date_time = watch_rtc_get_date_time();
|
watch_date_time date_time = watch_rtc_get_date_time();
|
||||||
|
check_and_act_on_daylight_savings(date_time);
|
||||||
|
if (!state->signal_enabled) return false;
|
||||||
|
|
||||||
return date_time.unit.minute == 0;
|
return date_time.unit.minute == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,9 +214,9 @@ void simple_clock_bin_led_face_resign(movement_settings_t *settings, void *conte
|
||||||
bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settings, void *context) {
|
bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||||
(void) settings;
|
(void) settings;
|
||||||
simple_clock_bin_led_state_t *state = (simple_clock_bin_led_state_t *)context;
|
simple_clock_bin_led_state_t *state = (simple_clock_bin_led_state_t *)context;
|
||||||
if (!state->signal_enabled) return false;
|
|
||||||
|
|
||||||
watch_date_time date_time = watch_rtc_get_date_time();
|
watch_date_time date_time = watch_rtc_get_date_time();
|
||||||
|
check_and_act_on_daylight_savings(date_time);
|
||||||
|
if (!state->signal_enabled) return false;
|
||||||
|
|
||||||
return date_time.unit.minute == 0;
|
return date_time.unit.minute == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,31 +150,15 @@ void simple_clock_face_resign(movement_settings_t *settings, void *context) {
|
||||||
(void) context;
|
(void) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_and_act_on_daylight_savings(movement_settings_t *settings, watch_date_time date_time) {
|
|
||||||
if (!settings ->bit.dst_active) return;
|
|
||||||
uint8_t dst_result = get_dst_status(date_time);
|
|
||||||
|
|
||||||
if (settings ->bit.dst_skip_rolling_back && (dst_result == DST_ENDED)) {
|
|
||||||
settings ->bit.dst_skip_rolling_back = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (dst_result == DST_ENDING && !settings ->bit.dst_skip_rolling_back) {
|
|
||||||
settings ->bit.dst_skip_rolling_back = true;
|
|
||||||
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
|
|
||||||
watch_rtc_set_date_time(date_time);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (dst_result == DST_STARTING) {
|
|
||||||
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
|
||||||
watch_rtc_set_date_time(date_time);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) {
|
||||||
simple_clock_state_t *state = (simple_clock_state_t *)context;
|
simple_clock_state_t *state = (simple_clock_state_t *)context;
|
||||||
date_time = watch_rtc_get_date_time();
|
watch_date_time date_time = watch_rtc_get_date_time();
|
||||||
check_and_act_on_daylight_savings(settings, date_time);
|
uint8_t hour_dst = check_and_act_on_daylight_savings(date_time);
|
||||||
|
if(hour_dst != date_time.unit.hour) {
|
||||||
|
char buf[3 + 1];
|
||||||
|
sprintf(buf, "%2d", hour_dst);
|
||||||
|
watch_display_string(buf, 4);
|
||||||
|
}
|
||||||
if (!state->signal_enabled) return false;
|
if (!state->signal_enabled) return false;
|
||||||
|
|
||||||
return date_time.unit.minute == 0;
|
return date_time.unit.minute == 0;
|
||||||
|
|
|
@ -72,7 +72,6 @@ static void _handle_alarm_button(movement_settings_t *settings, watch_date_time
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
watch_rtc_set_date_time(date_time);
|
watch_rtc_set_date_time(date_time);
|
||||||
settings->bit.dst_skip_rolling_back = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _abort_quick_ticks() {
|
static void _abort_quick_ticks() {
|
||||||
|
|
|
@ -94,7 +94,6 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
|
||||||
}
|
}
|
||||||
date_time_settings.unit.second = 0;
|
date_time_settings.unit.second = 0;
|
||||||
watch_rtc_set_date_time(date_time_settings);
|
watch_rtc_set_date_time(date_time_settings);
|
||||||
settings->bit.dst_skip_rolling_back = false;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EVENT_ALARM_BUTTON_DOWN:
|
case EVENT_ALARM_BUTTON_DOWN:
|
||||||
|
@ -137,7 +136,6 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
|
||||||
}
|
}
|
||||||
if (current_page != 2) { // Do not set time when we are at seconds, it was already set previously
|
if (current_page != 2) { // Do not set time when we are at seconds, it was already set previously
|
||||||
watch_rtc_set_date_time(date_time_settings);
|
watch_rtc_set_date_time(date_time_settings);
|
||||||
settings->bit.dst_skip_rolling_back = false;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -183,7 +181,6 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
|
||||||
}
|
}
|
||||||
if (current_page != 2) { // Do not set time when we are at seconds, it was already set previously
|
if (current_page != 2) { // Do not set time when we are at seconds, it was already set previously
|
||||||
watch_rtc_set_date_time(date_time_settings);
|
watch_rtc_set_date_time(date_time_settings);
|
||||||
settings->bit.dst_skip_rolling_back = false;
|
|
||||||
}
|
}
|
||||||
//TODO: Do not update whole RTC, just what we are changing
|
//TODO: Do not update whole RTC, just what we are changing
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -30,6 +30,19 @@ ext_irq_cb_t btn_alarm_callback;
|
||||||
ext_irq_cb_t a2_callback;
|
ext_irq_cb_t a2_callback;
|
||||||
ext_irq_cb_t a4_callback;
|
ext_irq_cb_t a4_callback;
|
||||||
|
|
||||||
|
static bool dst_skip_rolling_back;
|
||||||
|
bool get_dst_skip_rolling_back(void) {
|
||||||
|
return dst_skip_rolling_back;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_dst_skip_rolling_back(void) {
|
||||||
|
dst_skip_rolling_back = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_dst_skip_rolling_back(void) {
|
||||||
|
dst_skip_rolling_back = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool _watch_rtc_is_enabled(void) {
|
bool _watch_rtc_is_enabled(void) {
|
||||||
return RTC->MODE2.CTRLA.bit.ENABLE;
|
return RTC->MODE2.CTRLA.bit.ENABLE;
|
||||||
}
|
}
|
||||||
|
@ -60,6 +73,7 @@ void watch_rtc_set_date_time(watch_date_time date_time) {
|
||||||
_sync_rtc(); // Double sync as without it at high Hz faces setting time is unrealiable (specifically, set_time_hackwatch)
|
_sync_rtc(); // Double sync as without it at high Hz faces setting time is unrealiable (specifically, set_time_hackwatch)
|
||||||
RTC->MODE2.CLOCK.reg = date_time.reg;
|
RTC->MODE2.CLOCK.reg = date_time.reg;
|
||||||
_sync_rtc();
|
_sync_rtc();
|
||||||
|
clear_dst_skip_rolling_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
watch_date_time watch_rtc_get_date_time(void) {
|
watch_date_time watch_rtc_get_date_time(void) {
|
||||||
|
|
|
@ -157,5 +157,11 @@ void watch_rtc_enable(bool en);
|
||||||
*/
|
*/
|
||||||
void watch_rtc_freqcorr_write(int16_t value, int16_t sign);
|
void watch_rtc_freqcorr_write(int16_t value, int16_t sign);
|
||||||
|
|
||||||
|
/** @brief Returns if we're currently at a point where the we rolled back for DST and need to ignore the next DST segment
|
||||||
|
*/
|
||||||
|
bool get_dst_skip_rolling_back(void);
|
||||||
|
void set_dst_skip_rolling_back(void);
|
||||||
|
void clear_dst_skip_rolling_back(void);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -39,6 +39,19 @@ ext_irq_cb_t btn_alarm_callback;
|
||||||
ext_irq_cb_t a2_callback;
|
ext_irq_cb_t a2_callback;
|
||||||
ext_irq_cb_t a4_callback;
|
ext_irq_cb_t a4_callback;
|
||||||
|
|
||||||
|
static bool dst_skip_rolling_back;
|
||||||
|
bool get_dst_skip_rolling_back(void) {
|
||||||
|
return dst_skip_rolling_back;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_dst_skip_rolling_back(void) {
|
||||||
|
dst_skip_rolling_back = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_dst_skip_rolling_back(void) {
|
||||||
|
dst_skip_rolling_back = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool _watch_rtc_is_enabled(void) {
|
bool _watch_rtc_is_enabled(void) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +70,7 @@ void watch_rtc_set_date_time(watch_date_time date_time) {
|
||||||
const date = new Date(year, month - 1, day, hour, minute, second);
|
const date = new Date(year, month - 1, day, hour, minute, second);
|
||||||
return date - Date.now();
|
return date - Date.now();
|
||||||
}, date_time.reg);
|
}, date_time.reg);
|
||||||
|
clear_dst_skip_rolling_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
watch_date_time watch_rtc_get_date_time(void) {
|
watch_date_time watch_rtc_get_date_time(void) {
|
||||||
|
|
Loading…
Reference in a new issue