diff --git a/movement.c b/movement.c index 0ee7e00a..624ed296 100644 --- a/movement.c +++ b/movement.c @@ -52,7 +52,7 @@ movement_state_t movement_state; void * watch_face_contexts[MOVEMENT_NUM_FACES]; -watch_date_time scheduled_tasks[MOVEMENT_NUM_FACES]; +watch_date_time_t scheduled_tasks[MOVEMENT_NUM_FACES]; const int32_t movement_le_inactivity_deadlines[8] = {INT_MAX, 600, 3600, 7200, 21600, 43200, 86400, 604800}; const int16_t movement_timeout_inactivity_deadlines[4] = {60, 120, 300, 1800}; movement_event_t event; @@ -76,7 +76,7 @@ void yield(void) { cdc_task(); } -static udatetime_t _movement_convert_date_time_to_udate(watch_date_time date_time) { +static udatetime_t _movement_convert_date_time_to_udate(watch_date_time_t date_time) { return (udatetime_t) { .date.dayofmonth = date_time.unit.day, .date.dayofweek = dayofweek(UYEAR_FROM_YEAR(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR), date_time.unit.month, date_time.unit.day), @@ -92,13 +92,13 @@ static bool _movement_update_dst_offset_cache(void) { uzone_t local_zone; udatetime_t udate_time; bool dst_changed = false; - watch_date_time system_date_time = watch_rtc_get_date_time(); + watch_date_time_t system_date_time = watch_rtc_get_date_time(); printf("current zone: %d\n", movement_state.settings.bit.time_zone); for (uint8_t i = 0; i < NUM_ZONE_NAMES; i++) { unpack_zone(&zone_defns[i], "", &local_zone); - watch_date_time date_time = watch_utility_date_time_convert_zone(system_date_time, 0, local_zone.offset.hours * 3600 + local_zone.offset.minutes * 60); + watch_date_time_t date_time = watch_utility_date_time_convert_zone(system_date_time, 0, local_zone.offset.hours * 3600 + local_zone.offset.minutes * 60); if (!!local_zone.rules_len) { // if local zone has DST rules, we need to see if DST applies. @@ -144,7 +144,7 @@ static inline void _movement_disable_fast_tick_if_possible(void) { } static void _movement_handle_top_of_minute(void) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); // update the DST offset cache every 15 minutes, since someplace in the world could change. if (date_time.unit.minute % 15 == 0) { @@ -171,7 +171,7 @@ static void _movement_handle_top_of_minute(void) { } static void _movement_handle_scheduled_tasks(void) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); uint8_t num_active_tasks = 0; for(uint8_t i = 0; i < MOVEMENT_NUM_FACES; i++) { @@ -281,7 +281,7 @@ void movement_move_to_next_face(void) { movement_move_to_face((movement_state.current_face_idx + 1) % face_max); } -void movement_schedule_background_task(watch_date_time date_time) { +void movement_schedule_background_task(watch_date_time_t date_time) { movement_schedule_background_task_for_face(movement_state.current_face_idx, date_time); } @@ -289,8 +289,8 @@ void movement_cancel_background_task(void) { movement_cancel_background_task_for_face(movement_state.current_face_idx); } -void movement_schedule_background_task_for_face(uint8_t watch_face_index, watch_date_time date_time) { - watch_date_time now = watch_rtc_get_date_time(); +void movement_schedule_background_task_for_face(uint8_t watch_face_index, watch_date_time_t date_time) { + watch_date_time_t now = watch_rtc_get_date_time(); if (date_time.reg > now.reg) { movement_state.has_scheduled_background_task = true; scheduled_tasks[watch_face_index].reg = date_time.reg; @@ -394,23 +394,23 @@ void movement_set_timezone_index(uint8_t value) { movement_state.settings.bit.time_zone = value; } -watch_date_time movement_get_utc_date_time(void) { +watch_date_time_t movement_get_utc_date_time(void) { return watch_rtc_get_date_time(); } -watch_date_time movement_get_date_time_in_zone(uint8_t zone_index) { +watch_date_time_t movement_get_date_time_in_zone(uint8_t zone_index) { int32_t offset = movement_get_current_timezone_offset_for_zone(zone_index); return watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), 0, offset); } -watch_date_time movement_get_local_date_time(void) { - watch_date_time date_time = watch_rtc_get_date_time(); +watch_date_time_t movement_get_local_date_time(void) { + watch_date_time_t date_time = watch_rtc_get_date_time(); return watch_utility_date_time_convert_zone(date_time, 0, movement_get_current_timezone_offset()); } -void movement_set_local_date_time(watch_date_time date_time) { +void movement_set_local_date_time(watch_date_time_t date_time) { int32_t current_offset = movement_get_current_timezone_offset(); - watch_date_time utc_date_time = watch_utility_date_time_convert_zone(date_time, current_offset, 0); + watch_date_time_t utc_date_time = watch_utility_date_time_convert_zone(date_time, current_offset, 0); watch_rtc_set_date_time(utc_date_time); // this may seem wasteful, but if the user's local time is in a zone that observes DST, @@ -496,7 +496,7 @@ void movement_set_alarm_enabled(bool value) { void app_init(void) { _watch_init(); - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); if (date_time.reg == 0) { // at first boot, set year to 2024 date_time.unit.year = 2024 - WATCH_RTC_REFERENCE_YEAR; @@ -593,7 +593,7 @@ void app_setup(void) { _movement_update_dst_offset_cache(); // set up the 1 minute alarm (for background tasks and low power updates) - watch_date_time alarm_time; + watch_date_time_t alarm_time; alarm_time.reg = 0; alarm_time.unit.second = 59; // after a match, the alarm fires at the next rising edge of CLK_RTC_CNT, so 59 seconds lets us update at :00 watch_rtc_register_alarm_callback(cb_alarm_fired, alarm_time, ALARM_MATCH_SS); @@ -857,7 +857,7 @@ void cb_fast_tick(void) { void cb_tick(void) { event.event_type = EVENT_TICK; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); if (date_time.unit.second != movement_state.last_second) { // TODO: can we consolidate these two ticks? if (movement_state.settings.bit.le_interval && movement_state.le_mode_ticks > 0) movement_state.le_mode_ticks--; diff --git a/movement.h b/movement.h index 72ac9d7c..879ec3b7 100644 --- a/movement.h +++ b/movement.h @@ -312,14 +312,14 @@ void movement_request_tick_frequency(uint8_t freq); // note: watch faces can only schedule a background task when in the foreground, since // movement will associate the scheduled task with the currently active face. -void movement_schedule_background_task(watch_date_time date_time); +void movement_schedule_background_task(watch_date_time_t date_time); // note: watch faces can only cancel their background task when in the foreground, since // movement will associate the scheduled task with the currently active face. void movement_cancel_background_task(void); // these functions should work around the limitation of the above functions, which will be deprecated. -void movement_schedule_background_task_for_face(uint8_t watch_face_index, watch_date_time date_time); +void movement_schedule_background_task_for_face(uint8_t watch_face_index, watch_date_time_t date_time); void movement_cancel_background_task_for_face(uint8_t watch_face_index); void movement_request_sleep(void); @@ -337,11 +337,11 @@ int32_t movement_get_current_timezone_offset(void); int32_t movement_get_timezone_index(void); void movement_set_timezone_index(uint8_t value); -watch_date_time movement_get_utc_date_time(void); -watch_date_time movement_get_local_date_time(void); -watch_date_time movement_get_date_time_in_zone(uint8_t zone_index); +watch_date_time_t movement_get_utc_date_time(void); +watch_date_time_t movement_get_local_date_time(void); +watch_date_time_t movement_get_date_time_in_zone(uint8_t zone_index); -void movement_set_local_date_time(watch_date_time date_time); +void movement_set_local_date_time(watch_date_time_t date_time); bool movement_button_should_sound(void); void movement_set_button_should_sound(bool value); diff --git a/movement/watch_faces/clock/close_enough_clock_face.c b/movement/watch_faces/clock/close_enough_clock_face.c index 2f34c293..98a8e703 100644 --- a/movement/watch_faces/clock/close_enough_clock_face.c +++ b/movement/watch_faces/clock/close_enough_clock_face.c @@ -92,7 +92,7 @@ bool close_enough_clock_face_loop(movement_event_t event, void *context) { close_enough_clock_state_t *state = (close_enough_clock_state_t *)context; char buf[11]; - watch_date_time date_time; + watch_date_time_t date_time; bool show_next_hour = false; int prev_five_minute_period; int prev_min_checked; diff --git a/movement/watch_faces/clock/day_night_percentage_face.c b/movement/watch_faces/clock/day_night_percentage_face.c index dfac555a..fbd3d455 100644 --- a/movement/watch_faces/clock/day_night_percentage_face.c +++ b/movement/watch_faces/clock/day_night_percentage_face.c @@ -34,7 +34,7 @@ static double better_fmod(double x, double y) { return fmod(fmod(x, y) + y, y); } -static void recalculate(watch_date_time utc_now, day_night_percentage_state_t *state) { +static void recalculate(watch_date_time_t utc_now, day_night_percentage_state_t *state) { movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); if (movement_location.reg == 0) { @@ -61,7 +61,7 @@ void day_night_percentage_face_setup(uint8_t watch_face_index, void ** context_p 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_get_current_timezone_offset(), 0); + watch_date_time_t utc_now = watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), movement_get_current_timezone_offset(), 0); recalculate(utc_now, state); } } @@ -74,8 +74,8 @@ bool day_night_percentage_face_loop(movement_event_t event, void *context) { day_night_percentage_state_t *state = (day_night_percentage_state_t *)context; 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_get_current_timezone_offset(), 0); + watch_date_time_t date_time = watch_rtc_get_date_time(); + watch_date_time_t utc_now = watch_utility_date_time_convert_zone(date_time, movement_get_current_timezone_offset(), 0); switch (event.event_type) { case EVENT_ACTIVATE: diff --git a/movement/watch_faces/clock/decimal_time_face.c b/movement/watch_faces/clock/decimal_time_face.c index 95e6a51a..5056302f 100644 --- a/movement/watch_faces/clock/decimal_time_face.c +++ b/movement/watch_faces/clock/decimal_time_face.c @@ -72,7 +72,7 @@ bool decimal_time_face_loop(movement_event_t event, void *context) { char buf[16]; uint8_t centihours, decimal_seconds; - watch_date_time date_time; + watch_date_time_t date_time; switch (event.event_type) { case EVENT_ACTIVATE: diff --git a/movement/watch_faces/clock/french_revolutionary_face.c b/movement/watch_faces/clock/french_revolutionary_face.c index 3b2e9c39..83564a3a 100644 --- a/movement/watch_faces/clock/french_revolutionary_face.c +++ b/movement/watch_faces/clock/french_revolutionary_face.c @@ -52,7 +52,7 @@ bool french_revolutionary_face_loop(movement_event_t event, void *context) { french_revolutionary_state_t *state = (french_revolutionary_state_t *)context; char buf[11]; - watch_date_time date_time; + watch_date_time_t date_time; fr_decimal_time decimal_time; switch (event.event_type) { @@ -139,7 +139,7 @@ void french_revolutionary_face_resign(void *context) { } // Calculate decimal time from normal (24hr) time -fr_decimal_time get_decimal_time(watch_date_time *date_time) { +fr_decimal_time get_decimal_time(watch_date_time_t *date_time) { uint32_t current_24hr_secs, current_decimal_seconds; fr_decimal_time decimal_time; // Current 24-hr time in seconds (There are 86400 of these in a day.) @@ -167,7 +167,7 @@ fr_decimal_time get_decimal_time(watch_date_time *date_time) { // - Decimal-time with normal time in the top (minutes first, then hours, due to display limitations) // TODO: There is some power-saving stuff that simple clock does here around not redrawing characters that haven't changed, but we're not doing that here. // I'll try to add that optimization could be added in a future commit. -void set_display_buffer(char *buf, french_revolutionary_state_t *state, fr_decimal_time *decimal_time, watch_date_time *date_time) { +void set_display_buffer(char *buf, french_revolutionary_state_t *state, fr_decimal_time *decimal_time, watch_date_time_t *date_time) { switch (state->display_type) { // Decimal time only case 0: diff --git a/movement/watch_faces/clock/french_revolutionary_face.h b/movement/watch_faces/clock/french_revolutionary_face.h index 60bacfc4..554bceaf 100644 --- a/movement/watch_faces/clock/french_revolutionary_face.h +++ b/movement/watch_faces/clock/french_revolutionary_face.h @@ -68,8 +68,8 @@ void french_revolutionary_face_activate(void *context); bool french_revolutionary_face_loop(movement_event_t event, void *context); void french_revolutionary_face_resign(void *context); char fix_character_one(char digit); -fr_decimal_time get_decimal_time(watch_date_time *date_time); -void set_display_buffer(char *buf, french_revolutionary_state_t *state, fr_decimal_time *decimal_time, watch_date_time *date_time); +fr_decimal_time get_decimal_time(watch_date_time_t *date_time); +void set_display_buffer(char *buf, french_revolutionary_state_t *state, fr_decimal_time *decimal_time, watch_date_time_t *date_time); #define french_revolutionary_face ((const watch_face_t){ \ diff --git a/movement/watch_faces/clock/mars_time_face.c b/movement/watch_faces/clock/mars_time_face.c index cb49ac96..5c55cd19 100644 --- a/movement/watch_faces/clock/mars_time_face.c +++ b/movement/watch_faces/clock/mars_time_face.c @@ -69,7 +69,7 @@ static void _h_to_hms(mars_clock_hms_t *date_time, double h) { static void _update(mars_time_state_t *state) { char buf[11]; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); 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 diff --git a/movement/watch_faces/clock/minimal_clock_face.c b/movement/watch_faces/clock/minimal_clock_face.c index bccd1153..cb66323d 100644 --- a/movement/watch_faces/clock/minimal_clock_face.c +++ b/movement/watch_faces/clock/minimal_clock_face.c @@ -27,7 +27,7 @@ #include "minimal_clock_face.h" static void _minimal_clock_face_update_display() { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); char buffer[11]; if (!movement_clock_mode_24h()) { diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index 7582a7a4..9f5eb43c 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -102,7 +102,7 @@ bool minute_repeater_decimal_face_loop(movement_event_t event, void *context) { char buf[11]; uint8_t pos; - watch_date_time date_time; + watch_date_time_t date_time; uint32_t previous_date_time; switch (event.event_type) { case EVENT_ACTIVATE: @@ -230,7 +230,7 @@ movement_watch_face_advisory_t minute_repeater_decimal_face_advise(void *context movement_watch_face_advisory_t retval = { 0 }; if (state->signal_enabled) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); retval.wants_background_task = date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index 0d792a3f..b475b45e 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -87,7 +87,7 @@ bool repetition_minute_face_loop(movement_event_t event, void *context) { char buf[11]; uint8_t pos; - watch_date_time date_time; + watch_date_time_t date_time; uint32_t previous_date_time; switch (event.event_type) { case EVENT_ACTIVATE: @@ -213,7 +213,7 @@ movement_watch_face_advisory_t repetition_minute_face_advise(void *context) { movement_watch_face_advisory_t retval = { 0 }; if (state->signal_enabled) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); retval.wants_background_task = date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index cbe15935..527b1cd1 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -79,7 +79,7 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, void *context) { char buf[11]; uint8_t pos; - watch_date_time date_time; + watch_date_time_t date_time; uint32_t previous_date_time; switch (event.event_type) { case EVENT_ACTIVATE: @@ -214,7 +214,7 @@ movement_watch_face_advisory_t simple_clock_bin_led_face_advise(void *context) { movement_watch_face_advisory_t retval = { 0 }; if (state->signal_enabled) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); retval.wants_background_task = date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 2a270a2e..3a153e18 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -69,7 +69,7 @@ bool weeknumber_clock_face_loop(movement_event_t event, void *context) { char buf[11]; uint8_t pos; - watch_date_time date_time; + watch_date_time_t date_time; uint32_t previous_date_time; switch (event.event_type) { case EVENT_ACTIVATE: @@ -148,7 +148,7 @@ movement_watch_face_advisory_t weeknumber_clock_face_advise(void *context) { movement_watch_face_advisory_t retval = { 0 }; if (state->signal_enabled) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); retval.wants_background_task = date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/world_clock2_face.c b/movement/watch_faces/clock/world_clock2_face.c index 5dca9267..e79f2df7 100644 --- a/movement/watch_faces/clock/world_clock2_face.c +++ b/movement/watch_faces/clock/world_clock2_face.c @@ -162,7 +162,7 @@ static bool mode_display(movement_event_t event, world_clock2_state_t *state) uint32_t timestamp; uint32_t previous_date_time; - watch_date_time date_time; + watch_date_time_t date_time; switch (event.event_type) { case EVENT_ACTIVATE: diff --git a/movement/watch_faces/clock/wyoscan_face.c b/movement/watch_faces/clock/wyoscan_face.c index 1598193f..bf7b5e1c 100644 --- a/movement/watch_faces/clock/wyoscan_face.c +++ b/movement/watch_faces/clock/wyoscan_face.c @@ -109,7 +109,7 @@ void wyoscan_face_activate(void *context) { bool wyoscan_face_loop(movement_event_t event, void *context) { wyoscan_state_t *state = (wyoscan_state_t *)context; - watch_date_time date_time; + watch_date_time_t date_time; switch (event.event_type) { case EVENT_ACTIVATE: break; diff --git a/movement/watch_faces/complication/activity_face.c b/movement/watch_faces/complication/activity_face.c index 063f03b5..58107493 100644 --- a/movement/watch_faces/complication/activity_face.c +++ b/movement/watch_faces/complication/activity_face.c @@ -75,7 +75,7 @@ static const uint8_t num_enabled_activities = sizeof(enabled_activities) / sizeo // One logged activity typedef struct __attribute__((__packed__)) { // Activity's start time - watch_date_time start_time; + watch_date_time_t start_time; // Total duration of activity, including time spend in paus uint16_t total_sec; @@ -132,7 +132,7 @@ typedef struct { uint16_t counter; // Start of currently logged activity, if any - watch_date_time start_time; + watch_date_time_t start_time; // Total seconds elapsed since logging started uint16_t curr_total_sec; @@ -197,7 +197,7 @@ static void _activity_activate(activity_state_t *state) { // Those are not up-to-date because ticks have not been coming if (state->le_state != 0 && state->mode == ACTM_LOGGING) { state->le_state = 2; - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint32_t now_timestamp = watch_utility_date_time_to_unix_time(now, 0); uint32_t start_timestamp = watch_utility_date_time_to_unix_time(state->start_time, 0); uint32_t total_seconds = now_timestamp - start_timestamp; @@ -244,7 +244,7 @@ static void _activity_update_logging_screen(activity_state_t *state) { // If we're in LE state: per-minute update is special if (state->le_state == 1) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint32_t now_timestamp = watch_utility_date_time_to_unix_time(now, 0); uint32_t start_timestamp = watch_utility_date_time_to_unix_time(state->start_time, 0); uint32_t total_seconds = now_timestamp - start_timestamp; @@ -292,7 +292,7 @@ static void _activity_update_logging_screen(activity_state_t *state) { // Briefly, show time without seconds else { watch_clear_indicator(WATCH_INDICATOR_LAP); - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint8_t hour = now.unit.hour; if (!movement_clock_mode_24h()) { watch_clear_indicator(WATCH_INDICATOR_24H); @@ -397,7 +397,7 @@ static uint8_t _activity_get_next_byte(uint8_t *next_byte) { // Do this the hard way, byte by byte, to avoid high/low endedness issues // Higher order bytes first, is our serialization format uint8_t val; - // watch_date_time start_time; + // watch_date_time_t start_time; // uint16_t total_sec; // uint16_t pause_sec; // uint8_t activity_type; diff --git a/movement/watch_faces/complication/astronomy_face.c b/movement/watch_faces/complication/astronomy_face.c index a02dd06d..61df67be 100644 --- a/movement/watch_faces/complication/astronomy_face.c +++ b/movement/watch_faces/complication/astronomy_face.c @@ -79,7 +79,7 @@ static void _astronomy_face_recalculate(astronomy_state_t *state) { } #endif - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); 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); diff --git a/movement/watch_faces/complication/day_one_face.c b/movement/watch_faces/complication/day_one_face.c index 46b2c4fc..0810b9aa 100644 --- a/movement/watch_faces/complication/day_one_face.c +++ b/movement/watch_faces/complication/day_one_face.c @@ -35,7 +35,7 @@ static uint32_t _day_one_face_juliandaynum(uint16_t year, uint16_t month, uint16 static void _day_one_face_update(day_one_state_t *state) { char buf[15]; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); uint32_t julian_date = _day_one_face_juliandaynum(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day); uint32_t julian_birthdate = _day_one_face_juliandaynum(state->birth_year, state->birth_month, state->birth_day); if (julian_date < julian_birthdate) { @@ -148,7 +148,7 @@ bool day_one_face_loop(movement_event_t event, void *context) { break; // otherwise, check if we have to update. the display only needs to change at midnight! case PAGE_DISPLAY: { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); if (date_time.unit.hour == 0 && date_time.unit.minute == 0 && date_time.unit.second == 0) { _day_one_face_update(state); } diff --git a/movement/watch_faces/complication/deadline_face.c b/movement/watch_faces/complication/deadline_face.c index 7fbea72e..ed4b5a06 100644 --- a/movement/watch_faces/complication/deadline_face.c +++ b/movement/watch_faces/complication/deadline_face.c @@ -112,13 +112,13 @@ static bool _running_loop(movement_event_t event, void *context); static void _running_display(movement_event_t event, deadline_state_t *state); static void _setting_init(deadline_state_t *state); static bool _setting_loop(movement_event_t event, void *context); -static void _setting_display(movement_event_t event, deadline_state_t *state, watch_date_time date); +static void _setting_display(movement_event_t event, deadline_state_t *state, watch_date_time_t date); /* Utility functions */ static void _background_alarm_play(deadline_state_t *state); static void _background_alarm_schedule(deadline_state_t *state); static void _background_alarm_cancel(deadline_state_t *state); -static void _increment_date(deadline_state_t *state, watch_date_time date_time); +static void _increment_date(deadline_state_t *state, watch_date_time_t date_time); static inline void _change_tick_freq(uint8_t freq, deadline_state_t *state); static inline bool _is_leap(int16_t y); static inline int _days_in_month(int16_t mpnth, int16_t y); @@ -199,7 +199,7 @@ static inline void _change_tick_freq(uint8_t freq, deadline_state_t *state) /* Determine index of closest deadline */ static uint8_t _closest_deadline(deadline_state_t *state) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint32_t now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); uint32_t min_ts = UINT32_MAX; uint8_t min_index = 0; @@ -243,7 +243,7 @@ static void _background_alarm_cancel(deadline_state_t *state) static inline void _reset_deadline(deadline_state_t *state) { /* Get current time and reset hours/minutes/seconds */ - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); date_time.unit.second = 0; date_time.unit.minute = 0; date_time.unit.hour = 0; @@ -256,7 +256,7 @@ static inline void _reset_deadline(deadline_state_t *state) } /* Increment date in settings mode. Function taken from `set_time_face.c` */ -static void _increment_date(deadline_state_t *state, watch_date_time date_time) +static void _increment_date(deadline_state_t *state, watch_date_time_t date_time) { const uint8_t days_in_month[12] = { 31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31 }; @@ -307,7 +307,7 @@ static void _running_display(movement_event_t event, deadline_state_t *state) else watch_clear_indicator(WATCH_INDICATOR_BELL); - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint32_t now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); /* Deadline expired */ @@ -323,7 +323,7 @@ static void _running_display(movement_event_t event, deadline_state_t *state) } /* Get date time structs */ - watch_date_time deadline = watch_utility_date_time_from_unix_time(state->deadlines[state->current_index], movement_get_current_timezone_offset() + watch_date_time_t deadline = watch_utility_date_time_from_unix_time(state->deadlines[state->current_index], movement_get_current_timezone_offset() ); /* Calculate naive difference of dates */ @@ -430,7 +430,7 @@ static bool _running_loop(movement_event_t event, void *context) } /* Update display in settings mode */ -static void _setting_display(movement_event_t event, deadline_state_t *state, watch_date_time date_time) +static void _setting_display(movement_event_t event, deadline_state_t *state, watch_date_time_t date_time) { char buf[11]; @@ -493,7 +493,7 @@ static void _setting_init(deadline_state_t *state) static bool _setting_loop(movement_event_t event, void *context) { deadline_state_t *state = (deadline_state_t *) context; - watch_date_time date_time; + watch_date_time_t date_time; date_time = watch_utility_date_time_from_unix_time(state->deadlines[state->current_index], movement_get_current_timezone_offset()); if (event.event_type != EVENT_BACKGROUND_TASK) @@ -614,7 +614,7 @@ movement_watch_face_advisory_t deadline_face_advise(void *context) return false; /* Determine closest deadline */ - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint32_t now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); uint32_t next_ts = state->deadlines[_closest_deadline(state)]; @@ -627,7 +627,7 @@ movement_watch_face_advisory_t deadline_face_advise(void *context) return false; /* Deadline within next minute. Let's set up an alarm */ - watch_date_time next = watch_utility_date_time_from_unix_time(next_ts, movement_get_current_timezone_offset()); + watch_date_time_t next = watch_utility_date_time_from_unix_time(next_ts, movement_get_current_timezone_offset()); movement_request_wake(); movement_schedule_background_task_for_face(state->face_idx, next); return false; diff --git a/movement/watch_faces/complication/dual_timer_face.c b/movement/watch_faces/complication/dual_timer_face.c index e7bc5b3f..e819d598 100644 --- a/movement/watch_faces/complication/dual_timer_face.c +++ b/movement/watch_faces/complication/dual_timer_face.c @@ -50,7 +50,7 @@ #include "../../../watch-library/hardware/hri/hri_tc_l22.h" #endif -static const watch_date_time distant_future = {.unit = {0, 0, 0, 1, 1, 63}}; +static const watch_date_time_t distant_future = {.unit = {0, 0, 0, 1, 1, 63}}; static bool _is_running; static uint32_t _ticks; diff --git a/movement/watch_faces/complication/endless_runner_face.c b/movement/watch_faces/complication/endless_runner_face.c index d15517ee..f305ac4f 100644 --- a/movement/watch_faces/complication/endless_runner_face.c +++ b/movement/watch_faces/complication/endless_runner_face.c @@ -243,7 +243,7 @@ static void display_fuel(uint8_t subsecond, uint8_t difficulty) { static void check_and_reset_hi_score(endless_runner_state_t *state) { // Resets the hi score at the beginning of each month. - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); if ((state -> year_last_hi_score != date_time.unit.year) || (state -> month_last_hi_score != date_time.unit.month)) { @@ -320,8 +320,8 @@ static void display_title(endless_runner_state_t *state) { display_difficulty(difficulty); } -static void display_time(watch_date_time date_time, bool clock_mode_24h) { - static watch_date_time previous_date_time; +static void display_time(watch_date_time_t date_time, bool clock_mode_24h) { + static watch_date_time_t previous_date_time; char buf[6 + 1]; // If the hour needs updating or it's the first time displaying the time diff --git a/movement/watch_faces/complication/habit_face.c b/movement/watch_faces/complication/habit_face.c index 693d7a0f..10450320 100644 --- a/movement/watch_faces/complication/habit_face.c +++ b/movement/watch_faces/complication/habit_face.c @@ -31,7 +31,7 @@ #include static inline uint32_t today_unix(const uint32_t utc_offset) { - const watch_date_time dt = watch_rtc_get_date_time(); + const watch_date_time_t dt = watch_rtc_get_date_time(); return watch_utility_convert_to_unix_time(dt.unit.year + 2020, dt.unit.month, dt.unit.day, 0, 0, 0, utc_offset); } diff --git a/movement/watch_faces/complication/interval_face.c b/movement/watch_faces/complication/interval_face.c index d32c2dc8..c354e722 100644 --- a/movement/watch_faces/complication/interval_face.c +++ b/movement/watch_faces/complication/interval_face.c @@ -93,7 +93,7 @@ static inline void _inc_uint8(uint8_t *value, uint8_t step, uint8_t max) { static uint32_t _get_now_ts() { // returns the current date time as unix timestamp - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); return watch_utility_date_time_to_unix_time(now, 0); } @@ -331,7 +331,7 @@ static void _set_next_timestamp(interval_face_state_t *state) { if (delta <= 0) delta = 1; _target_ts += delta; // schedule next background task - watch_date_time target_dt = watch_utility_date_time_from_unix_time(_target_ts, 0); + watch_date_time_t target_dt = watch_utility_date_time_from_unix_time(_target_ts, 0); movement_schedule_background_task_for_face(state->face_idx, target_dt); // play sound watch_buzzer_play_sequence(sound_seq, NULL); @@ -363,7 +363,7 @@ static void _resume_paused_timer(interval_face_state_t *state) { // resume paused timer _now_ts = _get_now_ts(); _target_ts += _now_ts - _paused_ts; - watch_date_time target_dt = watch_utility_date_time_from_unix_time(_target_ts, 0); + watch_date_time_t target_dt = watch_utility_date_time_from_unix_time(_target_ts, 0); movement_schedule_background_task_for_face(state->face_idx, target_dt); state->face_state = interval_state_running; watch_set_indicator(WATCH_INDICATOR_BELL); diff --git a/movement/watch_faces/complication/menstrual_cycle_face.c b/movement/watch_faces/complication/menstrual_cycle_face.c index 2ef2a89b..ccd678cd 100644 --- a/movement/watch_faces/complication/menstrual_cycle_face.c +++ b/movement/watch_faces/complication/menstrual_cycle_face.c @@ -98,7 +98,7 @@ static inline uint32_t total_days_tracked(menstrual_cycle_state_t *state) { return 0; // Otherwise, set the start date to the first day of the first tracked cycle - watch_date_time date_time_start; + watch_date_time_t date_time_start; date_time_start.unit.second = 0; date_time_start.unit.minute = 0; date_time_start.unit.hour = 0; @@ -107,7 +107,7 @@ static inline uint32_t total_days_tracked(menstrual_cycle_state_t *state) { date_time_start.unit.year = state->dates.bit.first_year; // Get the current date and time - watch_date_time date_time_now = watch_rtc_get_date_time(); + watch_date_time_t date_time_now = watch_rtc_get_date_time(); // Convert the start date and current date to Unix time uint32_t unix_start = watch_utility_date_time_to_unix_time(date_time_start, state->utc_offset); @@ -176,7 +176,7 @@ typedef enum Fertile_Window {first_day, last_day} fertile_window; static inline uint32_t get_day_pk_fert(menstrual_cycle_state_t *state, fertile_window which_day) { // Get the date of the previous period - watch_date_time date_prev_period; + watch_date_time_t date_prev_period; date_prev_period.unit.second = 0; date_prev_period.unit.minute = 0; date_prev_period.unit.hour = 0; @@ -210,7 +210,7 @@ static inline bool inside_fert_window(menstrual_cycle_state_t *state) { return false; // Get the current date/time - watch_date_time date_time_now = watch_rtc_get_date_time(); + watch_date_time_t date_time_now = watch_rtc_get_date_time(); // Check if the current day falls between the first and last predicted peak fertility days if (get_day_pk_fert(state, first_day) > get_day_pk_fert(state, last_day)) { // We are crossing over the end of the month @@ -229,7 +229,7 @@ static inline bool inside_fert_window(menstrual_cycle_state_t *state) { static inline void update_shortest_longest_cycle(menstrual_cycle_state_t *state) { // Get the date of the previous menstrual cycle - watch_date_time date_prev_period; + watch_date_time_t date_prev_period; date_prev_period.unit.second = 0; date_prev_period.unit.minute = 0; date_prev_period.unit.hour = 0; @@ -305,7 +305,7 @@ void menstrual_cycle_face_activate(void *context) { bool menstrual_cycle_face_loop(movement_event_t event, void *context) { menstrual_cycle_state_t *state = (menstrual_cycle_state_t *)context; - watch_date_time date_period; + watch_date_time_t date_period; uint8_t current_page = state->current_page; uint8_t first_day_fert; uint8_t last_day_fert; diff --git a/movement/watch_faces/complication/moon_phase_face.c b/movement/watch_faces/complication/moon_phase_face.c index 7729fed7..7b28e446 100644 --- a/movement/watch_faces/complication/moon_phase_face.c +++ b/movement/watch_faces/complication/moon_phase_face.c @@ -56,7 +56,7 @@ void moon_phase_face_activate(void *context) { static void _update(moon_phase_state_t *state, uint32_t offset) { (void)state; char buf[11]; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); 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; @@ -132,7 +132,7 @@ static void _update(moon_phase_state_t *state, uint32_t offset) { bool moon_phase_face_loop(movement_event_t event, void *context) { moon_phase_state_t *state = (moon_phase_state_t *)context; - watch_date_time date_time; + watch_date_time_t date_time; switch (event.event_type) { case EVENT_ACTIVATE: diff --git a/movement/watch_faces/complication/orrery_face.c b/movement/watch_faces/complication/orrery_face.c index 0b538bfe..fba821b0 100644 --- a/movement/watch_faces/complication/orrery_face.c +++ b/movement/watch_faces/complication/orrery_face.c @@ -47,7 +47,7 @@ static const char orrery_celestial_body_names[NUM_AVAILABLE_BODIES][3] = { }; static void _orrery_face_recalculate(orrery_state_t *state) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); 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); diff --git a/movement/watch_faces/complication/planetary_hours_face.c b/movement/watch_faces/complication/planetary_hours_face.c index 73cf747d..f4011ba4 100644 --- a/movement/watch_faces/complication/planetary_hours_face.c +++ b/movement/watch_faces/complication/planetary_hours_face.c @@ -133,10 +133,10 @@ static void _planetary_solar_phases(planetary_hours_state_t *state) { // location detected 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_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; + watch_date_time_t date_time = watch_rtc_get_date_time(); // the current local date / time + watch_date_time_t 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_t scratch_time; // scratchpad, contains different values at different times + watch_date_time_t midnight; scratch_time.reg = midnight.reg = utc_now.reg; midnight.unit.hour = midnight.unit.minute = midnight.unit.second = 0; // start of the day at midnight @@ -227,7 +227,7 @@ static void _planetary_hours(planetary_hours_state_t *state) { char ruler[3]; uint8_t weekday, planet, planetary_hour; uint32_t current_hour_epoch; - watch_date_time scratch_time; + watch_date_time_t scratch_time; // check if we have a location. If not, display error if ( state->no_location ) { @@ -236,8 +236,8 @@ static void _planetary_hours(planetary_hours_state_t *state) { } // 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_get_current_timezone_offset(), 0); // the current date / time in UTC + watch_date_time_t date_time = watch_rtc_get_date_time(); // the current local date / time + watch_date_time_t 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 diff --git a/movement/watch_faces/complication/planetary_time_face.c b/movement/watch_faces/complication/planetary_time_face.c index d0ed3df4..d19937b9 100644 --- a/movement/watch_faces/complication/planetary_time_face.c +++ b/movement/watch_faces/complication/planetary_time_face.c @@ -128,10 +128,10 @@ static void _planetary_solar_phase(planetary_time_state_t *state) { // location detected 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_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; + watch_date_time_t date_time = watch_rtc_get_date_time(); // the current local date / time + watch_date_time_t 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_t scratch_time; // scratchpad, contains different values at different times + watch_date_time_t midnight; scratch_time.reg = midnight.reg = utc_now.reg; midnight.unit.hour = midnight.unit.minute = midnight.unit.second = 0; // start of the day at midnight diff --git a/movement/watch_faces/complication/planetary_time_face.h b/movement/watch_faces/complication/planetary_time_face.h index 1acdb11d..0dd594ef 100644 --- a/movement/watch_faces/complication/planetary_time_face.h +++ b/movement/watch_faces/complication/planetary_time_face.h @@ -90,7 +90,7 @@ typedef struct { bool day_ruler; bool no_location; sunrise_sunset_state_t sunstate; - watch_date_time scratch; + watch_date_time_t scratch; } planetary_time_state_t; void planetary_time_face_setup(uint8_t watch_face_index, void ** context_ptr); diff --git a/movement/watch_faces/complication/sailing_face.c b/movement/watch_faces/complication/sailing_face.c index 32c6fa6f..9f8109ba 100644 --- a/movement/watch_faces/complication/sailing_face.c +++ b/movement/watch_faces/complication/sailing_face.c @@ -164,7 +164,7 @@ static void ring(sailing_state_t *state) { 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_t target_dt = watch_utility_date_time_from_unix_time(state->nextbeep_ts, get_tz_offset(settings)); 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++) { @@ -192,7 +192,7 @@ static void start(sailing_state_t *state) {//gets called by starting / switching beepflag++; } if (state->index > 5 || state->minutes[state->index] == 0) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); state->target_ts = state->now_ts; if (alarmflag != 0){ @@ -203,7 +203,7 @@ static void start(sailing_state_t *state) {//gets called by starting / switching } 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(); + watch_date_time_t now = watch_rtc_get_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, state->minutes[state->index], 0); ring(state, settings); @@ -249,11 +249,11 @@ void sailing_face_setup(uint8_t watch_face_index, void ** context_ptr) { void sailing_face_activate(void *context) { sailing_state_t *state = (sailing_state_t *)context; if(state->mode == sl_running) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); } if(state->mode == sl_counting) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); watch_set_indicator(WATCH_INDICATOR_LAP); } diff --git a/movement/watch_faces/complication/ships_bell_face.c b/movement/watch_faces/complication/ships_bell_face.c index fe364fed..fc4d51b4 100644 --- a/movement/watch_faces/complication/ships_bell_face.c +++ b/movement/watch_faces/complication/ships_bell_face.c @@ -28,7 +28,7 @@ #include "ships_bell_face.h" static void ships_bell_ring() { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); date_time.unit.hour %= 4; date_time.unit.hour = date_time.unit.hour == 0 && date_time.unit.minute < 30 ? 4 : date_time.unit.hour; @@ -54,7 +54,7 @@ static void ships_bell_draw(ships_bell_state_t *state) { sprintf(buf, " "); } - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); date_time.unit.hour %= 4; sprintf(buf + 1, " %d%02d%02d", date_time.unit.hour, date_time.unit.minute, date_time.unit.second); @@ -130,7 +130,7 @@ movement_watch_face_advisory_t ships_bell_face_advise(void *context) { if (!state->bell_enabled) return retval; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); if (!(date_time.unit.minute == 0 || date_time.unit.minute == 30)) return retval; date_time.unit.hour %= 12; diff --git a/movement/watch_faces/complication/solstice_face.c b/movement/watch_faces/complication/solstice_face.c index 58139f4e..d981c4f5 100644 --- a/movement/watch_faces/complication/solstice_face.c +++ b/movement/watch_faces/complication/solstice_face.c @@ -77,7 +77,7 @@ static double calculate_solstice_equinox(uint16_t year, uint8_t k) { } // Convert JDE to Gergorian datetime as per Meeus Ch 7 -static watch_date_time jde_to_date_time(double JDE) { +static watch_date_time_t jde_to_date_time(double JDE) { double tmp = JDE + 0.5; double Z = floor(tmp); double F = fmod(tmp, 1); @@ -110,7 +110,7 @@ static watch_date_time jde_to_date_time(double JDE) { double minutes = fmod(hours, 1) * 60; double seconds = fmod(minutes, 1) * 60; - watch_date_time result = {.unit = { + watch_date_time_t result = {.unit = { floor(seconds), floor(minutes), floor(hours), @@ -135,7 +135,7 @@ void solstice_face_setup(uint8_t watch_face_index, void ** context_ptr) { *context_ptr = malloc(sizeof(solstice_state_t)); solstice_state_t *state = (solstice_state_t *)*context_ptr; - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); state->year = now.unit.year; state->index = 0; calculate_datetimes(state, settings); @@ -155,14 +155,14 @@ void solstice_face_activate(void *context) { static void show_main_screen(solstice_state_t *state) { char buf[11]; - watch_date_time date_time = state->datetimes[state->index]; + watch_date_time_t date_time = state->datetimes[state->index]; sprintf(buf, " %2d %2d%02d", date_time.unit.year + 20, date_time.unit.month, date_time.unit.day); watch_display_string(buf, 0); } static void show_date_time(solstice_state_t *state) { char buf[11]; - watch_date_time date_time = state->datetimes[state->index]; + watch_date_time_t date_time = state->datetimes[state->index]; if (!movement_clock_mode_24h()) { if (date_time.unit.hour < 12) { watch_clear_indicator(WATCH_INDICATOR_PM); diff --git a/movement/watch_faces/complication/solstice_face.h b/movement/watch_faces/complication/solstice_face.h index 17e630d4..57dcb4ee 100644 --- a/movement/watch_faces/complication/solstice_face.h +++ b/movement/watch_faces/complication/solstice_face.h @@ -42,7 +42,7 @@ */ typedef struct { - watch_date_time datetimes[4]; + watch_date_time_t datetimes[4]; uint8_t year; uint8_t index; } solstice_state_t; diff --git a/movement/watch_faces/complication/stopwatch_face.c b/movement/watch_faces/complication/stopwatch_face.c index ecaba019..c2ef8997 100644 --- a/movement/watch_faces/complication/stopwatch_face.c +++ b/movement/watch_faces/complication/stopwatch_face.c @@ -31,7 +31,7 @@ // distant future for background task: January 1, 2083 // see stopwatch_face_activate for details -static const watch_date_time distant_future = { +static const watch_date_time_t distant_future = { .unit = {0, 0, 0, 1, 1, 63} }; @@ -45,7 +45,7 @@ void stopwatch_face_setup(uint8_t watch_face_index, void ** context_ptr) { static void _stopwatch_face_update_display(stopwatch_state_t *stopwatch_state, bool show_seconds) { if (stopwatch_state->running) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint32_t now_timestamp = watch_utility_date_time_to_unix_time(now, 0); uint32_t start_timestamp = watch_utility_date_time_to_unix_time(stopwatch_state->start_time, 0); stopwatch_state->seconds_counted = now_timestamp - start_timestamp; diff --git a/movement/watch_faces/complication/stopwatch_face.h b/movement/watch_faces/complication/stopwatch_face.h index cf0d8fe6..5f9d66bb 100644 --- a/movement/watch_faces/complication/stopwatch_face.h +++ b/movement/watch_faces/complication/stopwatch_face.h @@ -41,7 +41,7 @@ typedef struct { bool running; - watch_date_time start_time; // while running, show the difference between this time and now + watch_date_time_t start_time; // while running, show the difference between this time and now uint32_t seconds_counted; // set this value when paused, and show that instead. } stopwatch_state_t; diff --git a/movement/watch_faces/complication/tachymeter_face.c b/movement/watch_faces/complication/tachymeter_face.c index 8ed9b6e6..ddaafc5d 100644 --- a/movement/watch_faces/complication/tachymeter_face.c +++ b/movement/watch_faces/complication/tachymeter_face.c @@ -202,7 +202,7 @@ bool tachymeter_face_loop(movement_event_t event, void *context) { } // Stop running state->running = false; - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); uint32_t now_timestamp = watch_utility_date_time_to_unix_time(now, 0); uint32_t start_timestamp = watch_utility_date_time_to_unix_time(state->start_seconds, 0); // Total time in centiseconds diff --git a/movement/watch_faces/complication/tachymeter_face.h b/movement/watch_faces/complication/tachymeter_face.h index 98f96e25..d299cb83 100644 --- a/movement/watch_faces/complication/tachymeter_face.h +++ b/movement/watch_faces/complication/tachymeter_face.h @@ -84,7 +84,7 @@ typedef struct { bool editing; // editing distance uint8_t active_digit; // active digit at editing distance uint8_t animation_state; // running animation state - watch_date_time start_seconds; // start_seconds + watch_date_time_t start_seconds; // start_seconds int8_t start_subsecond; // start_subsecond count (each count = 250 ms) distance_digits_t dist_digits; // distance digitwise uint32_t distance; // distance diff --git a/movement/watch_faces/complication/tempchart_face.c b/movement/watch_faces/complication/tempchart_face.c index 07ade30a..e8e1cfa8 100644 --- a/movement/watch_faces/complication/tempchart_face.c +++ b/movement/watch_faces/complication/tempchart_face.c @@ -101,7 +101,7 @@ bool tempchart_face_loop(movement_event_t event, void *context) { thermistor_driver_enable(); float temperature_c = thermistor_driver_get_temperature(); thermistor_driver_disable(); - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); int temp = round(temperature_c * 2); if ((temp < 0) || (temp >= 70)) break; @@ -137,7 +137,7 @@ movement_watch_face_advisory_t tempchart_face_advise(void *context) { (void) context; movement_watch_face_advisory_t retval = { 0 }; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); // Updating data every 5 minutes retval.wants_background_task = date_time.unit.minute % 5 == 0; diff --git a/movement/watch_faces/complication/time_left_face.c b/movement/watch_faces/complication/time_left_face.c index 9e8caf87..b91db201 100644 --- a/movement/watch_faces/complication/time_left_face.c +++ b/movement/watch_faces/complication/time_left_face.c @@ -91,7 +91,7 @@ static void _draw(time_left_state_t *state, uint8_t subsecond) { watch_display_character(_state_titles[state->current_page][2], 3); if (state->current_page < TIME_LEFT_FACE_SETTINGS_STATE) { // we are displaying days left or days from birth - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); uint32_t julian_current_day = _juliandaynum(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day); uint32_t julian_target_day = _juliandaynum(state->target_date.bit.year, state->target_date.bit.month, state->target_date.bit.day); int32_t days_left = julian_target_day - julian_current_day; @@ -221,7 +221,7 @@ void time_left_face_setup(uint8_t watch_face_index, void ** context_ptr) { state->birth_date.bit.day = 1; watch_store_backup_data(state->birth_date.reg, 2); // set target date to today + 10 years (just to have any value) - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); state->target_date.bit.year = date_time.unit.year + WATCH_RTC_REFERENCE_YEAR + 10; state->target_date.bit.month = date_time.unit.month; state->target_date.bit.day = date_time.unit.day; @@ -233,7 +233,7 @@ void time_left_face_activate(void *context) { time_left_state_t *state = (time_left_state_t *)context; // stash the current year, useful in birthday setting mode - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); state->current_year = date_time.unit.year + WATCH_RTC_REFERENCE_YEAR; _quick_ticks_running = false; // fetch the user's birth date from the birthday register @@ -263,7 +263,7 @@ bool time_left_face_loop(movement_event_t event, void *context) { _draw(state, subsecond); } else { // otherwise, check if we have to update. the display only needs to change at midnight - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); if (date_time.unit.hour == 0 && date_time.unit.minute == 0 && date_time.unit.second == 0) { _draw(state, subsecond); } diff --git a/movement/watch_faces/complication/timer_face.c b/movement/watch_faces/complication/timer_face.c index b993a615..338269a3 100644 --- a/movement/watch_faces/complication/timer_face.c +++ b/movement/watch_faces/complication/timer_face.c @@ -45,7 +45,7 @@ static void _signal_callback() { static void _start(timer_state_t *state, bool with_beep) { if (state->timers[state->current_timer].value == 0) return; - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); if (state->mode == pausing) state->target_ts = state->now_ts + state->paused_left; @@ -54,7 +54,7 @@ static void _start(timer_state_t *state, bool with_beep) { 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, movement_get_current_timezone_offset()); + watch_date_time_t target_dt = watch_utility_date_time_from_unix_time(state->target_ts, movement_get_current_timezone_offset()); state->mode = running; movement_schedule_background_task_for_face(state->watch_face_index, target_dt); watch_set_indicator(WATCH_INDICATOR_BELL); @@ -203,7 +203,7 @@ void timer_face_activate(void *context) { watch_display_string("TR", 0); watch_set_colon(); if(state->mode == running) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); watch_set_indicator(WATCH_INDICATOR_BELL); } else { diff --git a/movement/watch_faces/complication/tomato_face.c b/movement/watch_faces/complication/tomato_face.c index 6e9f6bbd..d33f8f0f 100644 --- a/movement/watch_faces/complication/tomato_face.c +++ b/movement/watch_faces/complication/tomato_face.c @@ -42,13 +42,13 @@ static uint8_t get_length(tomato_state_t *state) { } static void tomato_start(tomato_state_t *state) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); int8_t length = (int8_t) get_length(state); state->mode = tomato_run; state->now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); 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, movement_get_current_timezone_offset()); + watch_date_time_t target_dt = watch_utility_date_time_from_unix_time(state->target_ts, movement_get_current_timezone_offset()); movement_schedule_background_task(target_dt); watch_set_indicator(WATCH_INDICATOR_BELL); } @@ -120,7 +120,7 @@ void tomato_face_setup(uint8_t watch_face_index, void ** context_ptr) { void tomato_face_activate(void *context) { tomato_state_t *state = (tomato_state_t *)context; if (state->mode == tomato_run) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); watch_set_indicator(WATCH_INDICATOR_BELL); } diff --git a/movement/watch_faces/complication/wake_face.c b/movement/watch_faces/complication/wake_face.c index ca3a96ce..30982da0 100644 --- a/movement/watch_faces/complication/wake_face.c +++ b/movement/watch_faces/complication/wake_face.c @@ -85,7 +85,7 @@ movement_watch_face_advisory_t wake_face_advise(void *context) { movement_watch_face_advisory_t retval = { 0 }; if ( state->mode ) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); retval.wants_background_task = state->hour==now.unit.hour && state->minute==now.unit.minute; // We’re at the mercy of the advise handler // In Safari, the emulator triggers at the ›end‹ of the minute diff --git a/movement/watch_faces/complication/wordle_face.c b/movement/watch_faces/complication/wordle_face.c index cae36eb4..e7ab39f9 100644 --- a/movement/watch_faces/complication/wordle_face.c +++ b/movement/watch_faces/complication/wordle_face.c @@ -293,7 +293,7 @@ static void display_wait(wordle_state_t *state) { #endif static uint32_t get_day_unix_time(void) { - watch_date_time now = watch_rtc_get_date_time(); + watch_date_time_t now = watch_rtc_get_date_time(); #if WORDLE_USE_DAILY_STREAK == 2 now.unit.hour = now.unit.minute = now.unit.second = 0; #endif diff --git a/movement/watch_faces/demo/lis2dw_logging_face.c b/movement/watch_faces/demo/lis2dw_logging_face.c index 969ad0ef..76108a0b 100644 --- a/movement/watch_faces/demo/lis2dw_logging_face.c +++ b/movement/watch_faces/demo/lis2dw_logging_face.c @@ -36,11 +36,11 @@ // Pressing the alarm button enters the log mode, where the main display shows the number of interrupts detected in each of the last // 24 hours (the hour is shown in the top right digit and AM/PM indicator, if the clock is set to 12 hour mode) -static void _lis2dw_logging_face_update_display(lis2dw_logger_state_t *logger_state, lis2dw_wakeup_source wakeup_source) { +static void _lis2dw_logging_face_update_display(lis2dw_logger_state_t *logger_state, lis2dw_wakeup_source_t wakeup_source) { char buf[14]; char time_indication_character; int8_t pos; - watch_date_time date_time; + watch_date_time_t date_time; if (logger_state->log_ticks) { pos = (logger_state->data_points - 1 - logger_state->display_index) % LIS2DW_LOGGING_NUM_DATA_POINTS; @@ -92,7 +92,7 @@ static void _lis2dw_logging_face_update_display(lis2dw_logger_state_t *logger_st } static void _lis2dw_logging_face_log_data(lis2dw_logger_state_t *logger_state) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); // we get this call 15 minutes late; i.e. at 6:15 we're logging events for 6:00. // so: if we're at the top of the hour, roll the hour back too (7:00 task logs data for 6:45) if (date_time.unit.minute == 0) date_time.unit.hour = (date_time.unit.hour + 23) % 24; @@ -136,8 +136,8 @@ void lis2dh_logging_face_activate(void *context) { bool lis2dw_logging_face_loop(movement_event_t event, void *context) { lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context; - lis2dw_wakeup_source wakeup_source = 0; - lis2dw_interrupt_source interrupt_source = 0; + lis2dw_wakeup_source_t wakeup_source = 0; + lis2dw_interrupt_source_t interrupt_source = 0; switch (event.event_type) { case EVENT_LIGHT_BUTTON_DOWN: @@ -189,7 +189,7 @@ void lis2dw_logging_face_resign(void *context) { movement_watch_face_advisory_t lis2dw_logging_face_advise(void *context) { lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); movement_watch_face_advisory_t retval = { 0 }; // this is kind of an abuse of the API, but, let's use the 1 minute tick to shift all our data over. diff --git a/movement/watch_faces/demo/lis2dw_logging_face.h b/movement/watch_faces/demo/lis2dw_logging_face.h index cfae1a71..49d48eec 100644 --- a/movement/watch_faces/demo/lis2dw_logging_face.h +++ b/movement/watch_faces/demo/lis2dw_logging_face.h @@ -39,7 +39,7 @@ #define LIS2DW_LOGGING_NUM_DATA_POINTS (96) typedef struct { - watch_date_time timestamp; + watch_date_time_t timestamp; uint32_t x_interrupts; uint32_t y_interrupts; uint32_t z_interrupts; diff --git a/movement/watch_faces/sensor/accelerometer_data_acquisition_face.c b/movement/watch_faces/sensor/accelerometer_data_acquisition_face.c index f5548f5c..5784bd2c 100644 --- a/movement/watch_faces/sensor/accelerometer_data_acquisition_face.c +++ b/movement/watch_faces/sensor/accelerometer_data_acquisition_face.c @@ -437,7 +437,7 @@ static void start_reading(accelerometer_data_acquisition_state_t *state) { lis2dw_enable_fifo(); accelerometer_data_acquisition_record_t record; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); 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; diff --git a/movement/watch_faces/sensor/thermistor_logging_face.c b/movement/watch_faces/sensor/thermistor_logging_face.c index 171daf27..77bc2425 100644 --- a/movement/watch_faces/sensor/thermistor_logging_face.c +++ b/movement/watch_faces/sensor/thermistor_logging_face.c @@ -30,7 +30,7 @@ static void _thermistor_logging_face_log_data(thermistor_logger_state_t *logger_state) { thermistor_driver_enable(); - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); size_t pos = logger_state->data_points % THERMISTOR_LOGGING_NUM_DATA_POINTS; logger_state->data[pos].timestamp.reg = date_time.reg; @@ -51,7 +51,7 @@ static void _thermistor_logging_face_update_display(thermistor_logger_state_t *l if (pos < 0) { sprintf(buf, "TL%2dno dat", logger_state->display_index); } else if (logger_state->ts_ticks) { - watch_date_time date_time = logger_state->data[pos].timestamp; + watch_date_time_t date_time = logger_state->data[pos].timestamp; watch_set_colon(); if (clock_mode_24h) { watch_set_indicator(WATCH_INDICATOR_24H); diff --git a/movement/watch_faces/sensor/thermistor_logging_face.h b/movement/watch_faces/sensor/thermistor_logging_face.h index a32a274b..51755730 100644 --- a/movement/watch_faces/sensor/thermistor_logging_face.h +++ b/movement/watch_faces/sensor/thermistor_logging_face.h @@ -59,7 +59,7 @@ #define THERMISTOR_LOGGING_NUM_DATA_POINTS (36) typedef struct { - watch_date_time timestamp; + watch_date_time_t timestamp; float temperature_c; } thermistor_logger_data_point_t; diff --git a/movement/watch_faces/sensor/thermistor_readout_face.c b/movement/watch_faces/sensor/thermistor_readout_face.c index bbd120f3..520ac4ff 100644 --- a/movement/watch_faces/sensor/thermistor_readout_face.c +++ b/movement/watch_faces/sensor/thermistor_readout_face.c @@ -53,7 +53,7 @@ void thermistor_readout_face_activate(void *context) { bool thermistor_readout_face_loop(movement_event_t event, void *context) { (void) context; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); switch (event.event_type) { case EVENT_ALARM_BUTTON_DOWN: movement_set_use_imperial_units(!movement_use_imperial_units()); diff --git a/movement/watch_faces/settings/finetune_face.c b/movement/watch_faces/settings/finetune_face.c index da26c2f6..e1b64a9c 100644 --- a/movement/watch_faces/settings/finetune_face.c +++ b/movement/watch_faces/settings/finetune_face.c @@ -63,7 +63,7 @@ static void finetune_update_display(void) { if (finetune_page == 0) { watch_display_string("FT", 0); - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); sprintf(buf, "%02d", date_time.unit.second); watch_display_string(buf, 8); @@ -104,7 +104,7 @@ static void finetune_adjust_subseconds(int delta) { watch_rtc_enable(false); delay_ms(delta); if (delta > 500) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); date_time.unit.second = (date_time.unit.second + 1) % 60; if (date_time.unit.second == 0) { // Overflow date_time.unit.minute = (date_time.unit.minute + 1) % 60; @@ -143,7 +143,7 @@ bool finetune_face_loop(movement_event_t event, void *context) { // If needed, update your display here, at canonical 0.5sec position. // We flash green LED once per minute to measure clock error, when we are not on first screen if (finetune_page!=0) { - watch_date_time date_time; + watch_date_time_t date_time; date_time = watch_rtc_get_date_time(); if (date_time.unit.second == 0) { watch_set_led_green(); diff --git a/movement/watch_faces/settings/nanosec_face.c b/movement/watch_faces/settings/nanosec_face.c index ed5d7329..8efdacca 100644 --- a/movement/watch_faces/settings/nanosec_face.c +++ b/movement/watch_faces/settings/nanosec_face.c @@ -45,7 +45,7 @@ const float voltage_coefficient = 0.241666667 * dithering; // 10 * ppm/V. Nomina static void nanosec_init_profile(void) { nanosec_changed = true; nanosec_state.correction_cadence = 10; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); nanosec_state.last_correction_time = watch_utility_date_time_to_unix_time(date_time, 0); // init data after changing profile - do that once per profile selection @@ -259,7 +259,7 @@ static void nanosec_next_edit_screen(void) { float nanosec_get_aging() // Returns aging correction in ppm { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); float years = (watch_utility_date_time_to_unix_time(date_time, 0) - nanosec_state.last_correction_time) / 31536000.0f; // Years passed since finetune return years*nanosec_state.aging_ppm_pa/100.0f; } @@ -367,7 +367,7 @@ movement_watch_face_advisory_t nanosec_face_advise(void *context) { // No need for background correction if we are on profile 0 - static hardware correction. if (nanosec_state.correction_profile != 0) { - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); retval.wants_background_task = date_time.unit.minute % nanosec_state.correction_cadence == 0; } diff --git a/movement/watch_faces/settings/save_load_face.h b/movement/watch_faces/settings/save_load_face.h index 786b5f54..4e962fbf 100644 --- a/movement/watch_faces/settings/save_load_face.h +++ b/movement/watch_faces/settings/save_load_face.h @@ -54,7 +54,7 @@ typedef struct savefile { uint32_t b5; uint32_t b6; uint32_t b7; - watch_date_time rtc; + watch_date_time_t rtc; } savefile_t; #define SAVE_LOAD_SLOTS 4 diff --git a/movement/watch_faces/settings/set_time_hackwatch_face.c b/movement/watch_faces/settings/set_time_hackwatch_face.c index d10917a8..94557be2 100644 --- a/movement/watch_faces/settings/set_time_hackwatch_face.c +++ b/movement/watch_faces/settings/set_time_hackwatch_face.c @@ -32,7 +32,7 @@ char set_time_hackwatch_face_titles[][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO"}; #define set_time_hackwatch_face_NUM_SETTINGS (sizeof(set_time_hackwatch_face_titles) / sizeof(*set_time_hackwatch_face_titles)) -watch_date_time date_time_settings; +watch_date_time_t date_time_settings; void set_time_hackwatch_face_setup(uint8_t watch_face_index, void ** context_ptr) { (void) watch_face_index; diff --git a/watch-faces/clock/beats_face.c b/watch-faces/clock/beats_face.c index b2bde552..16fc0b86 100644 --- a/watch-faces/clock/beats_face.c +++ b/watch-faces/clock/beats_face.c @@ -53,7 +53,7 @@ bool beats_face_loop(movement_event_t event, void *context) { char buf[16]; uint32_t centibeats; - watch_date_time date_time; + watch_date_time_t date_time; switch (event.event_type) { case EVENT_ACTIVATE: case EVENT_TICK: diff --git a/watch-faces/clock/clock_face.c b/watch-faces/clock/clock_face.c index 0fb63451..f120b109 100644 --- a/watch-faces/clock/clock_face.c +++ b/watch-faces/clock/clock_face.c @@ -44,7 +44,7 @@ typedef struct { struct { - watch_date_time previous; + watch_date_time_t previous; } date_time; uint8_t last_battery_check; uint8_t watch_face_index; @@ -72,11 +72,11 @@ static void clock_indicate_24h() { clock_indicate(WATCH_INDICATOR_24H, !!movement_clock_mode_24h()); } -static bool clock_is_pm(watch_date_time date_time) { +static bool clock_is_pm(watch_date_time_t date_time) { return date_time.unit.hour >= 12; } -static void clock_indicate_pm(watch_date_time date_time) { +static void clock_indicate_pm(watch_date_time_t date_time) { if (movement_clock_mode_24h()) { return; } clock_indicate(WATCH_INDICATOR_PM, clock_is_pm(date_time)); } @@ -86,7 +86,7 @@ static void clock_indicate_low_available_power(clock_state_t *clock) { clock_indicate(WATCH_INDICATOR_LAP, clock->battery_low); } -static watch_date_time clock_24h_to_12h(watch_date_time date_time) { +static watch_date_time_t clock_24h_to_12h(watch_date_time_t date_time) { date_time.unit.hour %= 12; if (date_time.unit.hour == 0) { @@ -96,7 +96,7 @@ static watch_date_time clock_24h_to_12h(watch_date_time date_time) { return date_time; } -static void clock_check_battery_periodically(clock_state_t *clock, watch_date_time date_time) { +static void clock_check_battery_periodically(clock_state_t *clock, watch_date_time_t date_time) { // check the battery voltage once a day if (date_time.unit.day == clock->last_battery_check) { return; } @@ -116,7 +116,7 @@ static void clock_toggle_time_signal(clock_state_t *clock) { clock_indicate_time_signal(clock); } -static void clock_display_all(watch_date_time date_time) { +static void clock_display_all(watch_date_time_t date_time) { char buf[8 + 1]; snprintf( @@ -134,7 +134,7 @@ static void clock_display_all(watch_date_time date_time) { watch_display_text(WATCH_POSITION_BOTTOM, buf + 2); } -static bool clock_display_some(watch_date_time current, watch_date_time previous) { +static bool clock_display_some(watch_date_time_t current, watch_date_time_t previous) { if ((current.reg >> 6) == (previous.reg >> 6)) { // everything before seconds is the same, don't waste cycles setting those segments. @@ -167,7 +167,7 @@ static bool clock_display_some(watch_date_time current, watch_date_time previous } } -static void clock_display_clock(clock_state_t *clock, watch_date_time current) { +static void clock_display_clock(clock_state_t *clock, watch_date_time_t current) { if (!clock_display_some(current, clock->date_time.previous)) { if (movement_clock_mode_24h() == MOVEMENT_CLOCK_MODE_12H) { clock_indicate_pm(current); @@ -177,7 +177,7 @@ static void clock_display_clock(clock_state_t *clock, watch_date_time current) { } } -static void clock_display_low_energy(watch_date_time date_time) { +static void clock_display_low_energy(watch_date_time_t date_time) { if (movement_clock_mode_24h() == MOVEMENT_CLOCK_MODE_12H) { clock_indicate_pm(date_time); date_time = clock_24h_to_12h(date_time); @@ -240,7 +240,7 @@ void clock_face_activate(void *context) { bool clock_face_loop(movement_event_t event, void *context) { clock_state_t *state = (clock_state_t *) context; - watch_date_time current; + watch_date_time_t current; switch (event.event_type) { case EVENT_LOW_ENERGY_UPDATE: @@ -282,7 +282,7 @@ movement_watch_face_advisory_t clock_face_advise(void *context) { clock_state_t *state = (clock_state_t *) context; if (state->time_signal_enabled) { - watch_date_time date_time = movement_get_local_date_time(); + watch_date_time_t date_time = movement_get_local_date_time(); retval.wants_background_task = date_time.unit.minute == 0; } diff --git a/watch-faces/clock/world_clock_face.c b/watch-faces/clock/world_clock_face.c index e67dbb21..4b819ee4 100644 --- a/watch-faces/clock/world_clock_face.c +++ b/watch-faces/clock/world_clock_face.c @@ -58,7 +58,7 @@ static bool world_clock_face_do_display_mode(movement_event_t event, world_clock char buf[11]; uint32_t previous_date_time; - watch_date_time date_time; + watch_date_time_t date_time; switch (event.event_type) { case EVENT_ACTIVATE: if (movement_clock_mode_24h()) watch_set_indicator(WATCH_INDICATOR_24H); diff --git a/watch-faces/complication/advanced_alarm_face.c b/watch-faces/complication/advanced_alarm_face.c index ea012a50..a8662c83 100644 --- a/watch-faces/complication/advanced_alarm_face.c +++ b/watch-faces/complication/advanced_alarm_face.c @@ -54,7 +54,7 @@ static const uint8_t _buzzer_segdata[3][2] = {{0, 3}, {1, 3}, {2, 2}}; static int8_t _wait_ticks; -static uint8_t _get_weekday_idx(watch_date_time date_time) { +static uint8_t _get_weekday_idx(watch_date_time_t date_time) { date_time.unit.year += 20; if (date_time.unit.month <= 2) { date_time.unit.month += 12; @@ -143,7 +143,7 @@ static void _alarm_resume_setting(alarm_state_t *state, uint8_t subsecond) { static void _alarm_update_alarm_enabled(alarm_state_t *state) { // save indication for active alarms to movement settings bool active_alarms = false; - watch_date_time now; + watch_date_time_t now; bool now_init = false; uint8_t weekday_idx; uint16_t now_minutes_of_day; @@ -244,7 +244,7 @@ movement_watch_face_advisory_t advanced_alarm_face_advise(void *context) { alarm_state_t *state = (alarm_state_t *)context; movement_watch_face_advisory_t retval = { 0 }; - watch_date_time now = movement_get_local_date_time(); + watch_date_time_t now = movement_get_local_date_time(); // just a failsafe: never fire more than one alarm within a minute if (state->alarm_handled_minute == now.unit.minute) return retval; state->alarm_handled_minute = now.unit.minute; diff --git a/watch-faces/complication/countdown_face.c b/watch-faces/complication/countdown_face.c index 34ea4341..4de05920 100644 --- a/watch-faces/complication/countdown_face.c +++ b/watch-faces/complication/countdown_face.c @@ -72,7 +72,7 @@ static void schedule_countdown(countdown_state_t *state) { uint32_t new_now = watch_utility_date_time_to_unix_time(movement_get_utc_date_time(), movement_get_current_timezone_offset()); 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, movement_get_current_timezone_offset()); + watch_date_time_t target_dt = watch_utility_date_time_from_unix_time(state->target_ts, movement_get_current_timezone_offset()); movement_schedule_background_task_for_face(state->watch_face_index, target_dt); } @@ -196,7 +196,7 @@ void countdown_face_setup(uint8_t watch_face_index, void ** context_ptr) { void countdown_face_activate(void *context) { countdown_state_t *state = (countdown_state_t *)context; if(state->mode == cd_running) { - watch_date_time now = movement_get_utc_date_time(); + watch_date_time_t now = movement_get_utc_date_time(); state->now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); watch_set_indicator(WATCH_INDICATOR_SIGNAL); } diff --git a/watch-faces/complication/fast_stopwatch_face.c b/watch-faces/complication/fast_stopwatch_face.c index 1116898b..d28832c4 100644 --- a/watch-faces/complication/fast_stopwatch_face.c +++ b/watch-faces/complication/fast_stopwatch_face.c @@ -48,7 +48,7 @@ #endif // distant future for background task: January 1, 2083 -static const watch_date_time distant_future = { +static const watch_date_time_t distant_future = { .unit = {0, 0, 0, 1, 1, 63} }; diff --git a/watch-faces/complication/sunrise_sunset_face.c b/watch-faces/complication/sunrise_sunset_face.c index 474fe9d7..1a657104 100644 --- a/watch-faces/complication/sunrise_sunset_face.c +++ b/watch-faces/complication/sunrise_sunset_face.c @@ -39,7 +39,7 @@ static const uint8_t _location_count = sizeof(longLatPresets) / sizeof(long_lat_presets_t); -static void _sunrise_sunset_set_expiration(sunrise_sunset_state_t *state, watch_date_time next_rise_set) { +static void _sunrise_sunset_set_expiration(sunrise_sunset_state_t *state, watch_date_time_t next_rise_set) { uint32_t timestamp = watch_utility_date_time_to_unix_time(next_rise_set, 0); state->rise_set_expires = watch_utility_date_time_from_unix_time(timestamp + 60, 0); } @@ -62,9 +62,9 @@ static void _sunrise_sunset_face_update(sunrise_sunset_state_t *state) { return; } - watch_date_time date_time = movement_get_local_date_time(); // the current local date / time - 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_t date_time = movement_get_local_date_time(); // the current local date / time + watch_date_time_t 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_t scratch_time; // scratchpad, contains different values at different times scratch_time.reg = utc_now.reg; // Weird quirky unsigned things were happening when I tried to cast these directly to doubles below. @@ -76,8 +76,8 @@ static void _sunrise_sunset_face_update(sunrise_sunset_state_t *state) { double lon = (double)lon_centi / 100.0; // 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. + // this can mean hours below 0 or above 31, which won't fit into a watch_date_time_t struct. + // to deal with this, we set aside the offset in hours, and add it back before converting it to a watch_date_time_t. 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. @@ -338,7 +338,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, void *context) { // if entering low energy mode, start tick animation if (event.event_type == EVENT_LOW_ENERGY_UPDATE && !watch_sleep_animation_is_running()) watch_start_sleep_animation(1000); // check if we need to update the display - watch_date_time date_time = movement_get_local_date_time(); + watch_date_time_t date_time = movement_get_local_date_time(); if (date_time.reg >= state->rise_set_expires.reg) { // and on the off chance that this happened before EVENT_TIMEOUT snapped us back to rise/set 0, go back now state->rise_index = 0; diff --git a/watch-faces/complication/sunrise_sunset_face.h b/watch-faces/complication/sunrise_sunset_face.h index 133eed02..2380105e 100644 --- a/watch-faces/complication/sunrise_sunset_face.h +++ b/watch-faces/complication/sunrise_sunset_face.h @@ -52,7 +52,7 @@ typedef struct { uint8_t rise_index; uint8_t active_digit; bool location_changed; - watch_date_time rise_set_expires; + watch_date_time_t rise_set_expires; sunrise_sunset_lat_lon_settings_t working_latitude; sunrise_sunset_lat_lon_settings_t working_longitude; uint8_t longLatToUse; diff --git a/watch-faces/sensor/voltage_face.c b/watch-faces/sensor/voltage_face.c index b172ec6b..17ab5ea2 100644 --- a/watch-faces/sensor/voltage_face.c +++ b/watch-faces/sensor/voltage_face.c @@ -47,7 +47,7 @@ void voltage_face_activate(void *context) { bool voltage_face_loop(movement_event_t event, void *context) { (void) context; - watch_date_time date_time; + watch_date_time_t date_time; switch (event.event_type) { case EVENT_ACTIVATE: _voltage_face_update_display(); diff --git a/watch-faces/settings/set_time_face.c b/watch-faces/settings/set_time_face.c index a1c41c97..8092e871 100644 --- a/watch-faces/settings/set_time_face.c +++ b/watch-faces/settings/set_time_face.c @@ -35,7 +35,7 @@ const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "M1", "S static bool _quick_ticks_running; static int32_t current_offset; -static void _handle_alarm_button(watch_date_time date_time, uint8_t current_page) { +static void _handle_alarm_button(watch_date_time_t date_time, uint8_t current_page) { // handles short or long pressing of the alarm button switch (current_page) { @@ -90,7 +90,7 @@ void set_time_face_activate(void *context) { bool set_time_face_loop(movement_event_t event, void *context) { uint8_t current_page = *((uint8_t *)context); - watch_date_time date_time = movement_get_local_date_time(); + watch_date_time_t date_time = movement_get_local_date_time(); switch (event.event_type) { case EVENT_TICK: diff --git a/watch-library/shared/driver/lis2dw.c b/watch-library/shared/driver/lis2dw.c index b90acc7e..6ea50e1d 100644 --- a/watch-library/shared/driver/lis2dw.c +++ b/watch-library/shared/driver/lis2dw.c @@ -229,10 +229,10 @@ void lis2dw_configure_wakeup_int1(uint8_t threshold, bool latch, bool active_sta watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7, configuration | LIS2DW_CTRL7_VAL_INTERRUPTS_ENABLE); } -lis2dw_wakeup_source lis2dw_get_wakeup_source() { - return (lis2dw_wakeup_source) watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_SRC); +lis2dw_wakeup_source_t lis2dw_get_wakeup_source() { + return (lis2dw_wakeup_source_t) watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_SRC); } -lis2dw_interrupt_source lis2dw_get_interrupt_source(void) { - return (lis2dw_interrupt_source) watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_ALL_INT_SRC); +lis2dw_interrupt_source_t lis2dw_get_interrupt_source(void) { + return (lis2dw_interrupt_source_t) watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_ALL_INT_SRC); } diff --git a/watch-library/shared/driver/lis2dw.h b/watch-library/shared/driver/lis2dw.h index c791c461..29bb2833 100644 --- a/watch-library/shared/driver/lis2dw.h +++ b/watch-library/shared/driver/lis2dw.h @@ -106,7 +106,7 @@ typedef enum { LIS2DW_INTERRUPT_SRC_SINGLE_TAP = 0b00000100, LIS2DW_INTERRUPT_SRC_WU = 0b00000010, LIS2DW_INTERRUPT_SRC_FF = 0b00000001 -} lis2dw_interrupt_source; +} lis2dw_interrupt_source_t; typedef enum { LIS2DW_WAKEUP_SRC_FREEFALL = 0b00100000, @@ -115,7 +115,7 @@ typedef enum { LIS2DW_WAKEUP_SRC_WAKEUP_X = 0b00000100, LIS2DW_WAKEUP_SRC_WAKEUP_Y = 0b00000010, LIS2DW_WAKEUP_SRC_WAKEUP_Z = 0b00000001 -} lis2dw_wakeup_source; +} lis2dw_wakeup_source_t; // Assumes SA0 is high; if low, its 0x18 #define LIS2DW_ADDRESS (0x19) @@ -337,8 +337,8 @@ void lis2dw_clear_fifo(void); void lis2dw_configure_wakeup_int1(uint8_t threshold, bool latch, bool active_state); -lis2dw_interrupt_source lis2dw_get_interrupt_source(void); +lis2dw_interrupt_source_t lis2dw_get_interrupt_source(void); -lis2dw_wakeup_source lis2dw_get_wakeup_source(void); +lis2dw_wakeup_source_t lis2dw_get_wakeup_source(void); #endif // LIS2DW_H diff --git a/watch-library/shared/watch/watch_rtc.h b/watch-library/shared/watch/watch_rtc.h index 64d107fb..c590040c 100644 --- a/watch-library/shared/watch/watch_rtc.h +++ b/watch-library/shared/watch/watch_rtc.h @@ -45,7 +45,7 @@ extern watch_cb_t a4_callback; #define WATCH_RTC_REFERENCE_YEAR (2020) -#define watch_date_time rtc_date_time_t +#define watch_date_time_t rtc_date_time_t /** @brief Called by main.c to check if the RTC is enabled. * You may call this function, but outside of app_init, it should always return true. diff --git a/watch-library/shared/watch/watch_utility.c b/watch-library/shared/watch/watch_utility.c index 337797e1..81211f6e 100644 --- a/watch-library/shared/watch/watch_utility.c +++ b/watch-library/shared/watch/watch_utility.c @@ -25,12 +25,12 @@ #include #include "watch_utility.h" -const char * watch_utility_get_weekday(watch_date_time date_time) { +const char * watch_utility_get_weekday(watch_date_time_t date_time) { static const char weekdays[7][3] = {"MO", "TU", "WE", "TH", "FR", "SA", "SU"}; return weekdays[watch_utility_get_iso8601_weekday_number(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day) - 1]; } -const char * watch_utility_get_long_weekday(watch_date_time date_time) { +const char * watch_utility_get_long_weekday(watch_date_time_t date_time) { static const char weekdays[7][4] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; return weekdays[watch_utility_get_iso8601_weekday_number(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day) - 1]; } @@ -190,7 +190,7 @@ uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_ return timestamp; } -uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, int32_t utc_offset) { +uint32_t watch_utility_date_time_to_unix_time(watch_date_time_t date_time, int32_t utc_offset) { return watch_utility_convert_to_unix_time(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, utc_offset); } @@ -200,8 +200,8 @@ uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, int32_t #define DAYS_PER_100Y (365*100 + 24) #define DAYS_PER_4Y (365*4 + 1) -watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, int32_t utc_offset) { - watch_date_time retval; +watch_date_time_t watch_utility_date_time_from_unix_time(uint32_t timestamp, int32_t utc_offset) { + watch_date_time_t retval; retval.reg = 0; int32_t days, secs; int32_t remdays, remsecs, remyears; @@ -270,7 +270,7 @@ watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, int32 return retval; } -watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset) { +watch_date_time_t watch_utility_date_time_convert_zone(watch_date_time_t date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset) { uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, origin_utc_offset); return watch_utility_date_time_from_unix_time(timestamp, destination_utc_offset); } @@ -286,7 +286,7 @@ watch_duration_t watch_utility_seconds_to_duration(uint32_t seconds) { return retval; } -bool watch_utility_convert_to_12_hour(watch_date_time *date_time) { +bool watch_utility_convert_to_12_hour(watch_date_time_t *date_time) { bool is_pm = date_time->unit.hour > 11; date_time->unit.hour %= 12; if (date_time->unit.hour == 0) date_time->unit.hour = 12; diff --git a/watch-library/shared/watch/watch_utility.h b/watch-library/shared/watch/watch_utility.h index 6cb35553..169e573b 100644 --- a/watch-library/shared/watch/watch_utility.h +++ b/watch-library/shared/watch/watch_utility.h @@ -46,14 +46,14 @@ typedef struct { } watch_duration_t; /** @brief Returns a two-letter weekday for the given timestamp, suitable for display in positions 0-1 of the watch face - * @param date_time The watch_date_time whose weekday you want. + * @param date_time The watch_date_time_t whose weekday you want. */ -const char * watch_utility_get_weekday(watch_date_time date_time); +const char * watch_utility_get_weekday(watch_date_time_t date_time); /** @brief Returns a three-letter weekday for the given timestamp, suitable for display on the custom LCD - * @param date_time The watch_date_time whose weekday you want. + * @param date_time The watch_date_time_t whose weekday you want. */ -const char * watch_utility_get_long_weekday(watch_date_time date_time); +const char * watch_utility_get_long_weekday(watch_date_time_t date_time); /** @brief Returns a number between 1-7 representing the weekday according to ISO8601 : week starts on Monday and has index 1, Sunday has index 7 * @param year The year of the date @@ -83,7 +83,7 @@ uint16_t watch_utility_days_since_new_year(uint16_t year, uint8_t month, uint8_t uint8_t is_leap(uint16_t year); /** @brief Returns the UNIX time (seconds since 1970) for a given date/time in UTC. - * @param date_time The watch_date_time that you wish to convert. + * @param date_time The watch_date_time_t that you wish to convert. * @param year The year of the date you wish to convert. * @param month The month of the date you wish to convert. * @param day The day of the date you wish to convert. @@ -97,12 +97,12 @@ uint8_t is_leap(uint16_t year); */ uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, int32_t utc_offset); -/** @brief Returns the UNIX time (seconds since 1970) for a given watch_date_time struct. - * @param date_time The watch_date_time that you wish to convert. +/** @brief Returns the UNIX time (seconds since 1970) for a given watch_date_time_t struct. + * @param date_time The watch_date_time_t that you wish to convert. * @param utc_offset The number of seconds that date_time is offset from UTC, or 0 if the time is UTC. - * @return A UNIX timestamp for the given watch_date_time and UTC offset. + * @return A UNIX timestamp for the given watch_date_time_t and UTC offset. */ -uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, int32_t utc_offset); +uint32_t watch_utility_date_time_to_unix_time(watch_date_time_t date_time, int32_t utc_offset); /** @brief Converts a duration in seconds to a watch_duration_t struct. * @param seconds A positive number of seconds that you wish to convert to a formatted duration. @@ -110,39 +110,39 @@ uint32_t watch_utility_date_time_to_unix_time(watch_date_time date_time, int32_t */ watch_duration_t watch_utility_seconds_to_duration(uint32_t seconds); -/** @brief Returns a watch_date_time struct for a given UNIX time and UTC offset. +/** @brief Returns a watch_date_time_t struct for a given UNIX time and UTC offset. * @param timestamp The UNIX timestamp that you wish to convert. * @param utc_offset The number of seconds that you wish date_time to be offset from UTC. - * @return A watch_date_time for the given UNIX timestamp and UTC offset, or if outside the range that - * watch_date_time can represent, a watch_date_time with all fields set to 0. + * @return A watch_date_time_t for the given UNIX timestamp and UTC offset, or if outside the range that + * watch_date_time_t can represent, a watch_date_time_t with all fields set to 0. * @note Adapted from MIT-licensed code from musl, Copyright © 2005-2014 Rich Felker, et al.: * https://github.com/esmil/musl/blob/1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6/src/time/__secs_to_tm.c */ -watch_date_time watch_utility_date_time_from_unix_time(uint32_t timestamp, int32_t utc_offset); +watch_date_time_t watch_utility_date_time_from_unix_time(uint32_t timestamp, int32_t utc_offset); -/** @brief Converts a watch_date_time for 12-hour display. - * @param date_time A pointer to the watch_date_time that you wish to convert for display. Note that this +/** @brief Converts a watch_date_time_t for 12-hour display. + * @param date_time A pointer to the watch_date_time_t that you wish to convert for display. Note that this * function will OVERWRITE the original date/time, rendering it invalid for date/time * calculations. Midnight (hour 0) will become 12, and hours in the afternoon will wrap * back around to values from 1-11. * @return True if the value is in the afternoon. You can use this value to determine whether to set the * PM indicator on the LCD. - * @note This function sort of abuses the watch_date_time struct; the date/time that results from calling + * @note This function sort of abuses the watch_date_time_t struct; the date/time that results from calling * this function is clamped to the hours of 1:00:00 AM through 12:59:59 PM. It no longer reflects a - * valid watch_date_time for writing to an RTC register. + * valid watch_date_time_t for writing to an RTC register. */ -bool watch_utility_convert_to_12_hour(watch_date_time *date_time); +bool watch_utility_convert_to_12_hour(watch_date_time_t *date_time); /** @brief Converts a time from a given time zone to another time zone. - * @param date_time The watch_date_time that you wish to convert + * @param date_time The watch_date_time_t that you wish to convert * @param origin_utc_offset The number of seconds from UTC in the origin time zone * @param destination_utc_offset The number of seconds from UTC in the destination time zone - * @return A watch_date_time for the given UNIX timestamp and UTC offset, or if outside the range that - * watch_date_time can represent, a watch_date_time with all fields set to 0. + * @return A watch_date_time_t for the given UNIX timestamp and UTC offset, or if outside the range that + * watch_date_time_t can represent, a watch_date_time_t with all fields set to 0. * @note Adapted from MIT-licensed code from musl, Copyright © 2005-2014 Rich Felker, et al.: * https://github.com/esmil/musl/blob/1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6/src/time/__secs_to_tm.c */ -watch_date_time watch_utility_date_time_convert_zone(watch_date_time date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset); +watch_date_time_t watch_utility_date_time_convert_zone(watch_date_time_t date_time, uint32_t origin_utc_offset, uint32_t destination_utc_offset); /** @brief Returns a temperature in degrees Celsius for a given thermistor voltage divider circuit. * @param value The raw analog reading from the thermistor pin (0-65535) diff --git a/watch-library/simulator/watch/watch_private.c b/watch-library/simulator/watch/watch_private.c index f809c536..6f97490b 100644 --- a/watch-library/simulator/watch/watch_private.c +++ b/watch-library/simulator/watch/watch_private.c @@ -42,7 +42,7 @@ int getentropy(void *buf, size_t buflen) { int _gettimeofday(struct timeval *tv, void *tzvp); int _gettimeofday(struct timeval *tv, void *tzvp) { (void)tzvp; - watch_date_time date_time = watch_rtc_get_date_time(); + watch_date_time_t date_time = watch_rtc_get_date_time(); // FIXME: this assumes the system time is UTC! Will break for any other time zone. tv->tv_sec = watch_utility_date_time_to_unix_time(date_time, 0); diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c index 2bb6074c..3b244f24 100644 --- a/watch-library/simulator/watch/watch_rtc.c +++ b/watch-library/simulator/watch/watch_rtc.c @@ -46,7 +46,7 @@ bool _watch_rtc_is_enabled(void) { void _watch_rtc_init(void) { } -void watch_rtc_set_date_time(watch_date_time date_time) { +void watch_rtc_set_date_time(watch_date_time_t date_time) { time_offset = EM_ASM_DOUBLE({ const year = 2020 + (($0 >> 26) & 0x3f); const month = ($0 >> 22) & 0xf; @@ -59,8 +59,8 @@ void watch_rtc_set_date_time(watch_date_time date_time) { }, date_time.reg); } -watch_date_time watch_rtc_get_date_time(void) { - watch_date_time retval; +watch_date_time_t watch_rtc_get_date_time(void) { + watch_date_time_t retval; retval.reg = EM_ASM_INT({ const date = new Date(Date.now() + $0); return date.getSeconds() | @@ -134,7 +134,7 @@ static void watch_invoke_alarm_callback(void *userData) { alarm_interval_id = emscripten_set_interval(watch_invoke_alarm_interval_callback, alarm_interval, NULL); } -void watch_rtc_register_alarm_callback(ext_irq_cb_t callback, watch_date_time alarm_time, watch_rtc_alarm_match mask) { +void watch_rtc_register_alarm_callback(ext_irq_cb_t callback, watch_date_time_t alarm_time, watch_rtc_alarm_match mask) { watch_rtc_disable_alarm_callback(); switch (mask) {