Merge PR #470 - implement automatic DST toggling
Implements logic to automatically offset daylight saving time settings when calculating timezone offsets. This should make the DST functions work automatically with no need for user input in most cases. Reviewed-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com> GitHub-Pull-Request: https://github.com/joeycastillo/Sensor-Watch/pull/470
This commit is contained in:
@@ -80,7 +80,7 @@ static void _astronomy_face_recalculate(movement_settings_t *settings, astronomy
|
||||
#endif
|
||||
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||
uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
|
||||
date_time = watch_utility_date_time_from_unix_time(timestamp, 0);
|
||||
double jd = astro_convert_date_to_julian_date(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ static void abort_quick_ticks(countdown_state_t *state) {
|
||||
}
|
||||
}
|
||||
|
||||
static inline int32_t get_tz_offset(movement_settings_t *settings) {
|
||||
return movement_timezone_offsets[settings->bit.time_zone] * 60;
|
||||
static inline int32_t get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
|
||||
return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
|
||||
}
|
||||
|
||||
static inline void store_countdown(countdown_state_t *state) {
|
||||
@@ -70,13 +70,15 @@ static inline void button_beep(movement_settings_t *settings) {
|
||||
}
|
||||
|
||||
static void schedule_countdown(countdown_state_t *state, movement_settings_t *settings) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
int16_t tz = get_tz_offset(settings, now);
|
||||
|
||||
// Calculate the new state->now_ts but don't update it until we've updated the target -
|
||||
// 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(), get_tz_offset(settings));
|
||||
uint32_t new_now = watch_utility_date_time_to_unix_time(now, tz);
|
||||
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, get_tz_offset(settings));
|
||||
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, tz);
|
||||
movement_schedule_background_task_for_face(state->watch_face_index, target_dt);
|
||||
}
|
||||
|
||||
@@ -203,7 +205,7 @@ void countdown_face_activate(movement_settings_t *settings, void *context) {
|
||||
countdown_state_t *state = (countdown_state_t *)context;
|
||||
if(state->mode == cd_running) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
|
||||
watch_set_indicator(WATCH_INDICATOR_SIGNAL);
|
||||
}
|
||||
watch_set_colon();
|
||||
|
||||
@@ -59,8 +59,9 @@ static void _update(movement_settings_t *settings, moon_phase_state_t *state, ui
|
||||
(void)state;
|
||||
char buf[11];
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
uint32_t now = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60) + offset;
|
||||
date_time = watch_utility_date_time_from_unix_time(now, movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||
int16_t tz = get_timezone_offset(settings->bit.time_zone, date_time);
|
||||
uint32_t now = watch_utility_date_time_to_unix_time(date_time, tz * 60) + offset;
|
||||
date_time = watch_utility_date_time_from_unix_time(now, tz * 60);
|
||||
double currentfrac = fmod(now - FIRST_MOON, LUNAR_SECONDS) / LUNAR_SECONDS;
|
||||
double currentday = currentfrac * LUNAR_DAYS;
|
||||
uint8_t phase_index = 0;
|
||||
@@ -138,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:
|
||||
|
||||
@@ -48,7 +48,7 @@ static const char orrery_celestial_body_names[NUM_AVAILABLE_BODIES][3] = {
|
||||
|
||||
static void _orrery_face_recalculate(movement_settings_t *settings, orrery_state_t *state) {
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||
uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
|
||||
date_time = watch_utility_date_time_from_unix_time(timestamp, 0);
|
||||
double jd = astro_convert_date_to_julian_date(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
|
||||
double et = astro_convert_jd_to_julian_millenia_since_j2000(jd);
|
||||
|
||||
@@ -134,7 +134,8 @@ static void _planetary_solar_phases(movement_settings_t *settings, planetary_hou
|
||||
state->no_location = false;
|
||||
|
||||
watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
|
||||
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 scratch_time; // scratchpad, contains different values at different times
|
||||
watch_date_time midnight;
|
||||
scratch_time.reg = midnight.reg = utc_now.reg;
|
||||
@@ -147,7 +148,7 @@ static void _planetary_solar_phases(movement_settings_t *settings, planetary_hou
|
||||
double lon = (double)lon_centi / 100.0;
|
||||
|
||||
// save UTC offset
|
||||
state->utc_offset = ((double)movement_timezone_offsets[settings->bit.time_zone]) / 60.0;
|
||||
state->utc_offset = ((double)tz) / 60.0;
|
||||
|
||||
// calculate sunrise and sunset of current day in decimal hours after midnight
|
||||
sun_rise_set(scratch_time.unit.year + WATCH_RTC_REFERENCE_YEAR, scratch_time.unit.month, scratch_time.unit.day, lon, lat, &sunrise, &sunset);
|
||||
@@ -238,7 +239,7 @@ static void _planetary_hours(movement_settings_t *settings, planetary_hours_stat
|
||||
|
||||
// get current time
|
||||
watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60, 0); // the current date / time in UTC
|
||||
current_hour_epoch = watch_utility_date_time_to_unix_time(utc_now, 0);
|
||||
|
||||
// set the current planetary hour as default screen
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
// STATIC FUNCTIONS AND CONSTANTS /////////////////////////////////////////////
|
||||
|
||||
/** @brief Planetary rulers in the Chaldean order from slowest to fastest
|
||||
* @details Planetary rulers in the Chaldean order from slowest to fastest:
|
||||
* @details Planetary rulers in the Chaldean order from slowest to fastest:
|
||||
* Jupiter, Mars, Sun, Venus, Mercury, Moon
|
||||
*/
|
||||
static const char planets[7][3] = {"Sa", "Ju", "Ma", "So", "Ve", "Me", "Lu"}; // Latin
|
||||
@@ -129,7 +129,8 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
|
||||
state->no_location = false;
|
||||
|
||||
watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
|
||||
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 scratch_time; // scratchpad, contains different values at different times
|
||||
watch_date_time midnight;
|
||||
scratch_time.reg = midnight.reg = utc_now.reg;
|
||||
@@ -142,7 +143,7 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
|
||||
double lon = (double)lon_centi / 100.0;
|
||||
|
||||
// save UTC offset
|
||||
state->utc_offset = ((double)movement_timezone_offsets[settings->bit.time_zone]) / 60.0;
|
||||
state->utc_offset = ((double)tz) / 60.0;
|
||||
|
||||
// get UNIX epoch time
|
||||
now_epoch = watch_utility_date_time_to_unix_time(utc_now, 0);
|
||||
@@ -150,7 +151,7 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
|
||||
|
||||
// calculate sunrise and sunset of current day in decimal hours after midnight
|
||||
sun_rise_set(scratch_time.unit.year + WATCH_RTC_REFERENCE_YEAR, scratch_time.unit.month, scratch_time.unit.day, lon, lat, &sunrise, &sunset);
|
||||
|
||||
|
||||
// calculate sunrise and sunset UNIX timestamps
|
||||
sunrise_epoch = midnight_epoch + sunrise * 3600;
|
||||
sunset_epoch = midnight_epoch + sunset * 3600;
|
||||
@@ -191,7 +192,7 @@ static void _planetary_solar_phase(movement_settings_t *settings, planetary_time
|
||||
state->phase_end = sunrise_epoch;
|
||||
}
|
||||
|
||||
// calculate the duration of a planetary second during this solar phase
|
||||
// calculate the duration of a planetary second during this solar phase
|
||||
// and convert to Hertz so we can call a faster tick rate
|
||||
state->freq = (1 / ((double)( state->phase_end - state->phase_start ) / 43200));
|
||||
}
|
||||
@@ -207,11 +208,12 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
|
||||
uint8_t weekday, planet, planetary_hour;
|
||||
double hour_duration, current_hour, current_minute, current_second;
|
||||
bool set_leading_zero = false;
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
|
||||
watch_set_colon();
|
||||
|
||||
// get current time and convert to UTC
|
||||
state->scratch = watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60, 0);
|
||||
state->scratch = watch_utility_date_time_convert_zone(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60, 0);
|
||||
|
||||
// when current phase ends calculate the next phase
|
||||
if ( watch_utility_date_time_to_unix_time(state->scratch, 0) >= state->phase_end ) {
|
||||
@@ -261,11 +263,11 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
|
||||
if ( state->ruler == 0 ) strncpy(ruler, planets[planet], 3);
|
||||
if ( state->ruler == 1 ) strncpy(ruler, planetes[planet], 3);
|
||||
if ( state->ruler == 2 ) strncpy(ruler, " ", 3);
|
||||
|
||||
|
||||
// display planetary time with ruler of the hour or ruler of the day
|
||||
if ( state->day_ruler ) sprintf(buf, "%s d%2d%02d%02d", ruler, state->scratch.unit.hour, state->scratch.unit.minute, state->scratch.unit.second);
|
||||
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);
|
||||
@@ -301,7 +303,7 @@ void planetary_time_face_activate(movement_settings_t *settings, void *context)
|
||||
#endif
|
||||
|
||||
planetary_time_state_t *state = (planetary_time_state_t *)context;
|
||||
|
||||
|
||||
// calculate phase
|
||||
_planetary_solar_phase(settings, state);
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
#define sl_SELECTIONS 6
|
||||
#define DEFAULT_MINUTES { 5,4,1,0,0,0 }
|
||||
|
||||
static inline int32_t get_tz_offset(movement_settings_t *settings) {
|
||||
return movement_timezone_offsets[settings->bit.time_zone] * 60;
|
||||
static inline int32_t get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
|
||||
return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
|
||||
}
|
||||
|
||||
static int lap = 0;
|
||||
@@ -165,7 +165,8 @@ static void ring(sailing_state_t *state, movement_settings_t *settings) {
|
||||
return;
|
||||
}
|
||||
state->nextbeep_ts = state->target_ts - beepseconds[beepflag+1];
|
||||
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->nextbeep_ts, get_tz_offset(settings));
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->nextbeep_ts, get_tz_offset(settings, now));
|
||||
movement_schedule_background_task_for_face(state->watch_face_index, target_dt);
|
||||
//background task is set, now we have time to play the tune. If this is cancelled accidentally, the next alarm will still ring. Sound is implemented non-blocking, so that neither buttons nor display output are compromised.
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -194,7 +195,7 @@ static void start(sailing_state_t *state, movement_settings_t *settings) {//gets
|
||||
}
|
||||
if (state->index > 5 || state->minutes[state->index] == 0) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
|
||||
state->target_ts = state->now_ts;
|
||||
if (alarmflag != 0){
|
||||
watch_buzzer_play_sequence(long_beep, NULL);
|
||||
@@ -205,7 +206,7 @@ static void start(sailing_state_t *state, movement_settings_t *settings) {//gets
|
||||
movement_request_tick_frequency(1); //synchronises tick with the moment the button was pressed. Solves 1s offset between sound and display, solves up to +-0.5s offset between button action and display.
|
||||
state->mode = sl_running;
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
|
||||
state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, state->minutes[state->index], 0);
|
||||
ring(state, settings);
|
||||
}
|
||||
@@ -253,11 +254,11 @@ void sailing_face_activate(movement_settings_t *settings, void *context) {
|
||||
sailing_state_t *state = (sailing_state_t *)context;
|
||||
if(state->mode == sl_running) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
|
||||
}
|
||||
if(state->mode == sl_counting) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
|
||||
watch_set_indicator(WATCH_INDICATOR_LAP);
|
||||
}
|
||||
switch (alarmflag) {
|
||||
|
||||
@@ -123,9 +123,10 @@ static watch_date_time jde_to_date_time(double JDE) {
|
||||
}
|
||||
|
||||
static void calculate_datetimes(solstice_state_t *state, movement_settings_t *settings) {
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// TODO: handle DST changes
|
||||
state->datetimes[i] = jde_to_date_time(calculate_solstice_equinox(2020 + state->year, i) + (movement_timezone_offsets[settings->bit.time_zone] / (60.0*24.0)));
|
||||
state->datetimes[i] = jde_to_date_time(calculate_solstice_equinox(2020 + state->year, i) + (get_timezone_offset(settings->bit.time_zone, date_time) / (60.0*24.0)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,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
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 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;
|
||||
|
||||
@@ -77,7 +77,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)movement_timezone_offsets[settings->bit.time_zone]) / 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++) {
|
||||
@@ -334,6 +334,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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -36,8 +36,8 @@ static const int8_t _sound_seq_start[] = {BUZZER_NOTE_C8, 2, 0};
|
||||
|
||||
static uint8_t _beeps_to_play; // temporary counter for ring signals playing
|
||||
|
||||
static inline int32_t _get_tz_offset(movement_settings_t *settings) {
|
||||
return movement_timezone_offsets[settings->bit.time_zone] * 60;
|
||||
static inline int32_t _get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
|
||||
return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
|
||||
}
|
||||
|
||||
static void _signal_callback() {
|
||||
@@ -50,7 +50,8 @@ static void _signal_callback() {
|
||||
static void _start(timer_state_t *state, movement_settings_t *settings, bool with_beep) {
|
||||
if (state->timers[state->current_timer].value == 0) return;
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, _get_tz_offset(settings));
|
||||
int32_t tz = _get_tz_offset(settings, now);
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, tz);
|
||||
if (state->mode == pausing)
|
||||
state->target_ts = state->now_ts + state->paused_left;
|
||||
else
|
||||
@@ -58,7 +59,7 @@ static void _start(timer_state_t *state, movement_settings_t *settings, bool wit
|
||||
state->timers[state->current_timer].unit.hours,
|
||||
state->timers[state->current_timer].unit.minutes,
|
||||
state->timers[state->current_timer].unit.seconds);
|
||||
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, _get_tz_offset(settings));
|
||||
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, tz);
|
||||
state->mode = running;
|
||||
movement_schedule_background_task_for_face(state->watch_face_index, target_dt);
|
||||
watch_set_indicator(WATCH_INDICATOR_BELL);
|
||||
@@ -210,7 +211,7 @@ void timer_face_activate(movement_settings_t *settings, void *context) {
|
||||
watch_set_colon();
|
||||
if(state->mode == running) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, _get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, _get_tz_offset(settings, now));
|
||||
watch_set_indicator(WATCH_INDICATOR_BELL);
|
||||
} else {
|
||||
state->pausing_seconds = 1;
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
static uint8_t focus_min = 25;
|
||||
static uint8_t break_min = 5;
|
||||
|
||||
static inline int32_t get_tz_offset(movement_settings_t *settings) {
|
||||
return movement_timezone_offsets[settings->bit.time_zone] * 60;
|
||||
static inline int32_t get_tz_offset(movement_settings_t *settings, watch_date_time date_time) {
|
||||
return get_timezone_offset(settings->bit.time_zone, date_time) * 60;
|
||||
}
|
||||
|
||||
static uint8_t get_length(tomato_state_t *state) {
|
||||
@@ -47,12 +47,13 @@ static uint8_t get_length(tomato_state_t *state) {
|
||||
|
||||
static void tomato_start(tomato_state_t *state, movement_settings_t *settings) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
int32_t tz = get_tz_offset(settings, now);
|
||||
int8_t length = (int8_t) get_length(state);
|
||||
|
||||
state->mode = tomato_run;
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, tz);
|
||||
state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, length, 0);
|
||||
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
|
||||
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, tz);
|
||||
movement_schedule_background_task(target_dt);
|
||||
watch_set_indicator(WATCH_INDICATOR_BELL);
|
||||
}
|
||||
@@ -126,7 +127,7 @@ void tomato_face_activate(movement_settings_t *settings, void *context) {
|
||||
tomato_state_t *state = (tomato_state_t *)context;
|
||||
if (state->mode == tomato_run) {
|
||||
watch_date_time now = watch_rtc_get_date_time();
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
|
||||
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings, now));
|
||||
watch_set_indicator(WATCH_INDICATOR_BELL);
|
||||
}
|
||||
watch_set_colon();
|
||||
|
||||
@@ -157,8 +157,9 @@ static void totp_generate_and_display(totp_state_t *totp_state) {
|
||||
totp_display(totp_state);
|
||||
}
|
||||
|
||||
static inline uint32_t totp_compute_base_timestamp(movement_settings_t *settings) {
|
||||
return watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||
static uint32_t totp_compute_base_timestamp(movement_settings_t *settings) {
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
return watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
|
||||
}
|
||||
|
||||
void totp_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
|
||||
|
||||
@@ -254,7 +254,8 @@ void totp_face_lfs_activate(movement_settings_t *settings, void *context) {
|
||||
}
|
||||
#endif
|
||||
|
||||
totp_state->timestamp = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
totp_state->timestamp = watch_utility_date_time_to_unix_time(date_time, get_timezone_offset(settings->bit.time_zone, date_time) * 60);
|
||||
totp_face_set_record(totp_state, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user