summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2021-12-01 10:43:01 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2021-12-01 10:43:01 -0500
commit0f89c11eba9b0312b0d2fa06f8a73395cfb66973 (patch)
tree8975ee924d29a149cbb784e7e5489f33b9d3d19a
parent36be251e893a0f9c186e409952c06e93d1031f7d (diff)
downloadSensor-Watch-0f89c11eba9b0312b0d2fa06f8a73395cfb66973.tar.gz
Sensor-Watch-0f89c11eba9b0312b0d2fa06f8a73395cfb66973.tar.bz2
Sensor-Watch-0f89c11eba9b0312b0d2fa06f8a73395cfb66973.zip
movement: remove floating point math from beats face
-rw-r--r--movement/watch_faces/complications/beats_face.c28
-rw-r--r--movement/watch_faces/complications/beats_face.h2
2 files changed, 15 insertions, 15 deletions
diff --git a/movement/watch_faces/complications/beats_face.c b/movement/watch_faces/complications/beats_face.c
index 119ddd50..9241bf73 100644
--- a/movement/watch_faces/complications/beats_face.c
+++ b/movement/watch_faces/complications/beats_face.c
@@ -20,24 +20,24 @@ bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void
(void) settings;
(void) context;
- char buf[14];
- float beats;
+ char buf[16];
+ uint32_t centibeats;
watch_date_time date_time;
switch (event.event_type) {
case EVENT_ACTIVATE:
case EVENT_TICK:
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]);
- sprintf(buf, "bt %6.0f", beats * 100);
+ 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 %6ld", centibeats);
watch_display_string(buf, 0);
break;
case EVENT_LOW_ENERGY_UPDATE:
if (!watch_tick_animation_is_running()) watch_start_tick_animation(432);
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]);
- sprintf(buf, "bt %4d ", (int)beats);
+ 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 %4ld ", centibeats / 100);
watch_display_string(buf, 0);
break;
@@ -63,14 +63,14 @@ void beats_face_resign(movement_settings_t *settings, void *context) {
movement_request_tick_frequency(1);
}
-float clock2beats(uint16_t hours, uint16_t minutes, uint16_t seconds, uint16_t subseconds, int16_t utc_offset) {
- float beats = seconds + ((float)subseconds / (float)BEAT_REFRESH_FREQUENCY);
- beats += 60 * minutes;
- beats += (float)hours * 60 * 60;
- beats -= (utc_offset - 60) * 60; // offset from utc + 1 since beats in in UTC+1
+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 - 60) * 60 * 1000;
- beats /= 86.4; // convert to beats
- while(beats > 1000) beats -= 1000; // beats %= 1000 but for a float
+ retval /= 864; // convert to centibeats
+ retval %= 100000;
- return beats;
+ return retval;
} \ No newline at end of file
diff --git a/movement/watch_faces/complications/beats_face.h b/movement/watch_faces/complications/beats_face.h
index fe34f5aa..343e9a27 100644
--- a/movement/watch_faces/complications/beats_face.h
+++ b/movement/watch_faces/complications/beats_face.h
@@ -3,7 +3,7 @@
#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_activate(movement_settings_t *settings, void *context);
bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void *context);