diff --git a/watch-faces/clock/beats_face.c b/watch-faces/clock/beats_face.c index 16fc0b86..cb64206a 100644 --- a/watch-faces/clock/beats_face.c +++ b/watch-faces/clock/beats_face.c @@ -54,11 +54,13 @@ bool beats_face_loop(movement_event_t event, void *context) { uint32_t centibeats; watch_date_time_t date_time; + uint8_t bmt_hour; // BMT = Biel Mean Time switch (event.event_type) { case EVENT_ACTIVATE: case EVENT_TICK: - date_time = movement_get_local_date_time(); - centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_get_current_timezone_offset()); + date_time = movement_get_utc_date_time(); + bmt_hour = (date_time.unit.hour + 1) % 24; + centibeats = clock2beats(bmt_hour, date_time.unit.minute, date_time.unit.second, event.subsecond); if (centibeats == state->last_centibeat_displayed) { // we missed this update, try again next subsecond state->next_subsecond_update = (event.subsecond + 1) % BEAT_REFRESH_FREQUENCY; @@ -73,8 +75,9 @@ bool beats_face_loop(movement_event_t event, void *context) { break; case EVENT_LOW_ENERGY_UPDATE: if (!watch_sleep_animation_is_running()) watch_start_sleep_animation(432); - date_time = movement_get_local_date_time(); - centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_get_current_timezone_offset()); + date_time = movement_get_utc_date_time(); + bmt_hour = (date_time.unit.hour + 1) % 24; + centibeats = clock2beats(bmt_hour, date_time.unit.minute, date_time.unit.second, event.subsecond); sprintf(buf, "%4lu ", centibeats / 100); watch_display_text_with_fallback(WATCH_POSITION_TOP, "beat", "bt"); @@ -92,14 +95,11 @@ void beats_face_resign(void *context) { (void) context; } -uint32_t clock2beats(uint32_t hours, uint32_t minutes, uint32_t seconds, uint32_t subseconds, int16_t utc_offset) { - uint32_t retval = seconds * 1000 + (subseconds * 1000) / (BEAT_REFRESH_FREQUENCY); - retval += 60 * minutes * 1000; - retval += hours * 60 * 60 * 1000; - retval -= (utc_offset - 3600) * 1000; - - retval /= 864; // convert to centibeats - retval %= 100000; - - return retval; +uint32_t clock2beats(uint32_t hours, uint32_t minutes, uint32_t seconds, uint32_t subseconds) { + // Calculate total milliseconds since midnight + uint32_t ms = (hours * 3600 + minutes * 60 + seconds) * 1000 + (subseconds * 1000) / BEAT_REFRESH_FREQUENCY; + // 1 beat = 86.4 seconds = 86400 ms, so 1 centibeat = 864 ms + uint32_t centibeats = ms / 864; + centibeats %= 100000; + return centibeats; } diff --git a/watch-faces/clock/beats_face.h b/watch-faces/clock/beats_face.h index 66afdd89..d7b43b09 100644 --- a/watch-faces/clock/beats_face.h +++ b/watch-faces/clock/beats_face.h @@ -30,10 +30,17 @@ * * The Beat Time face displays the current Swatch Internet Time, or .beat time. * This is a decimal time system that divides the day into 1000 beats. + * 0 beats = 00:00:00.000 UTC+1, also known as BMT time - Biel Mean Time. + * + * 1 beat of time equals 86.4 seconds. * * The three large digits in the bottom row indicate the current beat, and the * two smaller digits (normally the seconds in Simple Clock) indicate the * fractional beat; so for example you can read “67214” as “beat 672.14”. + * + * This implementation uses UTC time, adds one hour to get BMT, and does not + * observe daylight saving time or local time zones as Swatch Internet Time + * does not do that. */ #include "movement.h" @@ -43,7 +50,7 @@ typedef struct { uint32_t last_centibeat_displayed; } beats_face_state_t; -uint32_t clock2beats(uint32_t hours, uint32_t minutes, uint32_t seconds, uint32_t subseconds, int16_t utc_offset); +uint32_t clock2beats(uint32_t hours, uint32_t minutes, uint32_t seconds, uint32_t subseconds); void beats_face_setup(uint8_t watch_face_index, void ** context_ptr); void beats_face_activate(void *context); bool beats_face_loop(movement_event_t event, void *context);