mirror of
https://github.com/joeycastillo/second-movement.git
synced 2025-10-29 19:47:40 +00:00
refactor remaining uses of movement_timezone_offsets to movement_get_current_timezone_offset
This commit is contained in:
parent
677872434d
commit
f315744cc3
@ -62,7 +62,7 @@ void day_night_percentage_face_setup(movement_settings_t *settings, uint8_t watc
|
||||
if (*context_ptr == NULL) {
|
||||
*context_ptr = malloc(sizeof(day_night_percentage_state_t));
|
||||
day_night_percentage_state_t *state = (day_night_percentage_state_t *)*context_ptr;
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60, 0);
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), movement_get_current_timezone_offset(), 0);
|
||||
recalculate(utc_now, state);
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,7 @@ bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t
|
||||
|
||||
char buf[12];
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0);
|
||||
watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_get_current_timezone_offset(), 0);
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
|
||||
@ -70,7 +70,7 @@ static void _h_to_hms(mars_clock_hms_t *date_time, double h) {
|
||||
static void _update(movement_settings_t *settings, mars_time_state_t *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);
|
||||
uint32_t now = watch_utility_date_time_to_unix_time(date_time, movement_get_current_timezone_offset());
|
||||
// TODO: I'm skipping over some steps here.
|
||||
// https://www.giss.nasa.gov/tools/mars24/help/algorithm.html
|
||||
double jdut = 2440587.5 + ((double)now / 86400.0);
|
||||
|
||||
@ -183,7 +183,7 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
|
||||
|
||||
/* Determine current time at time zone and store date/time */
|
||||
date_time = watch_rtc_get_date_time();
|
||||
timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||
timestamp = watch_utility_date_time_to_unix_time(date_time, movement_get_current_timezone_offset());
|
||||
date_time = watch_utility_date_time_from_unix_time(timestamp, movement_timezone_offsets[state->current_zone] * 60);
|
||||
previous_date_time = state->previous_date_time;
|
||||
state->previous_date_time = date_time.reg;
|
||||
|
||||
@ -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, movement_get_current_timezone_offset());
|
||||
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);
|
||||
|
||||
|
||||
@ -159,7 +159,7 @@ static inline int _days_in_month(int16_t month, int16_t year)
|
||||
/* Return time zone offset */
|
||||
static inline int32_t _get_tz_offset(movement_settings_t *settings)
|
||||
{
|
||||
return movement_timezone_offsets[settings->bit.time_zone] * 60;
|
||||
return movement_get_current_timezone_offset();
|
||||
}
|
||||
|
||||
/* Beep for a button press*/
|
||||
|
||||
@ -301,7 +301,7 @@ void menstrual_cycle_face_activate(movement_settings_t *settings, void *context)
|
||||
state->period_today = 0;
|
||||
state->current_page = 0;
|
||||
state->reset_tracking = 0;
|
||||
state->utc_offset = movement_timezone_offsets[settings->bit.time_zone] * 60;
|
||||
state->utc_offset = movement_get_current_timezone_offset();
|
||||
movement_request_tick_frequency(4); // we need to manually blink some pixels
|
||||
}
|
||||
|
||||
|
||||
@ -59,8 +59,8 @@ 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);
|
||||
uint32_t now = watch_utility_date_time_to_unix_time(date_time, movement_get_current_timezone_offset()) + offset;
|
||||
date_time = watch_utility_date_time_from_unix_time(now, movement_get_current_timezone_offset());
|
||||
double currentfrac = fmod(now - FIRST_MOON, LUNAR_SECONDS) / LUNAR_SECONDS;
|
||||
double currentday = currentfrac * LUNAR_DAYS;
|
||||
uint8_t phase_index = 0;
|
||||
|
||||
@ -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, movement_get_current_timezone_offset());
|
||||
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,7 @@ 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
|
||||
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
|
||||
watch_date_time midnight;
|
||||
scratch_time.reg = midnight.reg = utc_now.reg;
|
||||
@ -147,7 +147,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)movement_get_current_timezone_offset()) / 3600.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);
|
||||
@ -237,7 +237,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, movement_get_current_timezone_offset(), 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
|
||||
|
||||
@ -129,7 +129,7 @@ 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
|
||||
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
|
||||
watch_date_time midnight;
|
||||
scratch_time.reg = midnight.reg = utc_now.reg;
|
||||
@ -142,7 +142,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)movement_get_current_timezone_offset()) / 3600.0;
|
||||
|
||||
// get UNIX epoch time
|
||||
now_epoch = watch_utility_date_time_to_unix_time(utc_now, 0);
|
||||
@ -210,7 +210,7 @@ static void _planetary_time(movement_event_t event, movement_settings_t *setting
|
||||
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(watch_rtc_get_date_time(), movement_get_current_timezone_offset(), 0);
|
||||
|
||||
// when current phase ends calculate the next phase
|
||||
if ( watch_utility_date_time_to_unix_time(state->scratch, 0) >= state->phase_end ) {
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
#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;
|
||||
return movement_get_current_timezone_offset();
|
||||
}
|
||||
|
||||
static int lap = 0;
|
||||
|
||||
@ -125,7 +125,7 @@ static watch_date_time jde_to_date_time(double JDE) {
|
||||
static void calculate_datetimes(solstice_state_t *state, movement_settings_t *settings) {
|
||||
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) + (movement_get_current_timezone_offset() / (3600.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, 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;
|
||||
|
||||
@ -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)movement_get_current_timezone_offset()) / 3600.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++) {
|
||||
|
||||
@ -37,7 +37,7 @@ 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;
|
||||
return movement_get_current_timezone_offset();
|
||||
}
|
||||
|
||||
static void _signal_callback() {
|
||||
|
||||
@ -31,7 +31,7 @@ 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;
|
||||
return movement_get_current_timezone_offset();
|
||||
}
|
||||
|
||||
static uint8_t get_length(tomato_state_t *state) {
|
||||
|
||||
@ -158,7 +158,7 @@ static void totp_generate_and_display(totp_state_t *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);
|
||||
return watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_get_current_timezone_offset());
|
||||
}
|
||||
|
||||
void totp_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
|
||||
|
||||
@ -254,7 +254,7 @@ 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);
|
||||
totp_state->timestamp = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_get_current_timezone_offset());
|
||||
totp_face_set_record(totp_state, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -442,7 +442,7 @@ static void start_reading(accelerometer_data_acquisition_state_t *state, movemen
|
||||
|
||||
accelerometer_data_acquisition_record_t record;
|
||||
watch_date_time date_time = watch_rtc_get_date_time();
|
||||
state->starting_timestamp = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
|
||||
state->starting_timestamp = watch_utility_date_time_to_unix_time(date_time, movement_get_current_timezone_offset());
|
||||
record.header.info.record_type = ACCELEROMETER_DATA_ACQUISITION_HEADER;
|
||||
record.header.info.range = ACCELEROMETER_RANGE;
|
||||
record.header.info.temperature = lis2dw_get_temperature();
|
||||
|
||||
@ -231,8 +231,8 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
|
||||
sprintf(buf,
|
||||
"%s %3d%02d ",
|
||||
set_time_hackwatch_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));
|
||||
(int8_t)(movement_get_current_timezone_offset() / 3600),
|
||||
(int8_t)(movement_get_current_timezone_offset() % 3600) * (movement_get_current_timezone_offset() < 0 ? -1 : 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user