movement: remove floating point math from beats face

This commit is contained in:
Joey Castillo 2021-12-01 10:43:01 -05:00
parent 36be251e89
commit 0f89c11eba
2 changed files with 15 additions and 15 deletions

View File

@ -20,24 +20,24 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void
(void) settings; (void) settings;
(void) context; (void) context;
char buf[14]; char buf[16];
float beats; uint32_t centibeats;
watch_date_time date_time; watch_date_time date_time;
switch (event.event_type) { switch (event.event_type) {
case EVENT_ACTIVATE: case EVENT_ACTIVATE:
case EVENT_TICK: case EVENT_TICK:
date_time = watch_rtc_get_date_time(); date_time = watch_rtc_get_date_time();
beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]); centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]);
sprintf(buf, "bt %6.0f", beats * 100); sprintf(buf, "bt %6ld", centibeats);
watch_display_string(buf, 0); watch_display_string(buf, 0);
break; break;
case EVENT_LOW_ENERGY_UPDATE: case EVENT_LOW_ENERGY_UPDATE:
if (!watch_tick_animation_is_running()) watch_start_tick_animation(432); if (!watch_tick_animation_is_running()) watch_start_tick_animation(432);
date_time = watch_rtc_get_date_time(); date_time = watch_rtc_get_date_time();
beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]); centibeats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, movement_timezone_offsets[settings->bit.time_zone]);
sprintf(buf, "bt %4d ", (int)beats); sprintf(buf, "bt %4ld ", centibeats / 100);
watch_display_string(buf, 0); watch_display_string(buf, 0);
break; break;
@ -63,14 +63,14 @@ void beats_face_resign(movement_settings_t *settings, void *context) {
movement_request_tick_frequency(1); movement_request_tick_frequency(1);
} }
float clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds, uint16_t subseconds, int16_t utc_offset) { uint32_t clock2beats(uint32_t hours, uint32_t minutes, uint32_t seconds, uint32_t subseconds, int16_t utc_offset) {
float beats = seconds + ((float)subseconds / (float)BEAT_REFRESH_FREQUENCY); uint32_t retval = seconds * 1000 + (subseconds * 1000) / (BEAT_REFRESH_FREQUENCY);
beats += 60 * minutes; retval += 60 * minutes * 1000;
beats += (float)hours * 60 * 60; retval += hours * 60 * 60 * 1000;
beats -= (utc_offset - 60) * 60; // offset from utc + 1 since beats in in UTC+1 retval -= (utc_offset - 60) * 60 * 1000;
beats /= 86.4; // convert to beats retval /= 864; // convert to centibeats
while(beats > 1000) beats -= 1000; // beats %= 1000 but for a float retval %= 100000;
return beats; return retval;
} }

View File

@ -3,7 +3,7 @@
#include "movement.h" #include "movement.h"
float clock2beats(uint16_t, uint16_t, uint16_t, uint16_t, int16_t); uint32_t clock2beats(uint32_t hours, uint32_t minutes, uint32_t seconds, uint32_t subseconds, int16_t utc_offset);
void beats_face_setup(movement_settings_t *settings, void ** context_ptr); void beats_face_setup(movement_settings_t *settings, void ** context_ptr);
void beats_face_activate(movement_settings_t *settings, void *context); void beats_face_activate(movement_settings_t *settings, void *context);
bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void *context); bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void *context);