]> git.earman.xyz Git - sensor-watch.git/commitdiff
refactor remaining uses of movement_timezone_offsets to movement_get_current_timezone...
authorjoeycastillo <joeycastillo@utexas.edu>
Sun, 29 Sep 2024 13:20:14 +0000 (09:20 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Sun, 29 Sep 2024 14:18:11 +0000 (10:18 -0400)
19 files changed:
movement/watch_faces/clock/day_night_percentage_face.c
movement/watch_faces/clock/mars_time_face.c
movement/watch_faces/clock/world_clock2_face.c
movement/watch_faces/complication/astronomy_face.c
movement/watch_faces/complication/deadline_face.c
movement/watch_faces/complication/menstrual_cycle_face.c
movement/watch_faces/complication/moon_phase_face.c
movement/watch_faces/complication/orrery_face.c
movement/watch_faces/complication/planetary_hours_face.c
movement/watch_faces/complication/planetary_time_face.c
movement/watch_faces/complication/sailing_face.c
movement/watch_faces/complication/solstice_face.c
movement/watch_faces/complication/sunrise_sunset_face.c
movement/watch_faces/complication/timer_face.c
movement/watch_faces/complication/tomato_face.c
movement/watch_faces/complication/totp_face.c
movement/watch_faces/complication/totp_face_lfs.c
movement/watch_faces/sensor/accelerometer_data_acquisition_face.c
movement/watch_faces/settings/set_time_hackwatch_face.c

index 86f07f9d339e4871486cb75c54961113bbcd85bb..dd822ffd171f0e57a2bd728c331be9de8b9a7eb9 100644 (file)
@@ -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:
index 30f6a34b02bb0714932f664f75b9dba1c2e6c6a4..fba6e56b3c7e81473d5c5061e924c0db4153762d 100644 (file)
@@ -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);
index 7fa86d281a0fa5ab732f3d08c7e5b47d59da89a1..ead219af0070ff450e3fec504eb387f5520322f9 100644 (file)
@@ -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;
index 204a0a3a70509c84ed3503671ac322ab3efebae6..dece524723ca4a70cbc28a65b93e0f9200941766 100644 (file)
@@ -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);
 
index 8e2f41ea569995a9c8a06d98fe1eb4013716dafa..6af7be3a00706a1d4d2fec77a9c9e574e238b84e 100644 (file)
@@ -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*/
index 37cc73034291d93b22b1d9c38d55d752d9670093..57ca98248f8fa6af84af4f9d06a3793a8fe50e9f 100644 (file)
@@ -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
 }
 
index f74de647c68cc344a53982bff9571e8829c9bfea..6f60c017f7994b39245e9eb1ad11971d77c43570 100644 (file)
@@ -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;
index 42fdf81f56e01a4d3444eda3ed69537051b24779..5847b16d384b3bb7e042e1e494b44593dab2f71f 100644 (file)
@@ -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);
index 7c00449123373ca7c451394c18107e8c79f6f432..466296a6d562ef16aaaabbde2c0eb6cf4e4a799a 100644 (file)
@@ -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
index 227f68d4abcef586e35e4d02c2787f9392d45209..1bad968ed95f6afa6b176af09dde01674696b094 100644 (file)
@@ -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 ) {
index a6c13fe8621357b711c06859cd647f90031accac..8d39fc3646f30db91334d8a4bbbf7ed2456a4ff7 100644 (file)
@@ -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;
index c31223e97a645f13c27f5283dc1f71109516712d..66fe210eb26f7cef84b0017be3e30d50550ece0e 100644 (file)
@@ -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)));
     }
 }
 
index 7a0ba366abe672884cf4f6d1f1a0b73820afda21..5fd778898eefdbae4a3ba861464aaf9807a0707f 100644 (file)
@@ -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++) {
index aa7f2d9948835a76124c921665df66c6bf81d35d..50b93ec985c520a2b734b6c8906b82326d31ef23 100644 (file)
@@ -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() {
index 3d46ba94c7035dfbc5569675c2fae4ca391e39b1..b4b7ae379e9b10b19c7d13ba0f6e070db605b1ac 100644 (file)
@@ -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) {
index fdb410959ef43fd498b53dd63318020b17b06927..7fb45e564f9f78a94ebe779ecb158cd27090448d 100644 (file)
@@ -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) {
index 5d7defe88e26bde2545ea91dfa2c8fea30de9d41..8823cbc907bc161fbd0cf1af46039abcadfc9250 100644 (file)
@@ -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);
 }
 
index 6d174d5a667bf89f84f807c8a7fde3b10379a804..5acb9f09dd9d8620cd82953dd3bac4390c0fa016 100644 (file)
@@ -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();
index 9b96014f0a580e22ac2e145899c55e657a3adcd7..0b6c76e3d5ec1276ff4fafcea78a28cda8ebb078 100644 (file)
@@ -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));
         }
     }