summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Ellis <wesleyjellis@gmail.com>2021-10-22 22:00:52 -0400
committerWesley Ellis <wesleyjellis@gmail.com>2021-10-23 15:45:20 -0400
commit66e95e4ab85444b2bdda32e7d04e7df138c52cc5 (patch)
tree520b128f8e2f1b763914a826eeb608d0775b6393
parentf1a706792e995f45b6b6f2ef70b2318253002249 (diff)
downloadSensor-Watch-66e95e4ab85444b2bdda32e7d04e7df138c52cc5.tar.gz
Sensor-Watch-66e95e4ab85444b2bdda32e7d04e7df138c52cc5.tar.bz2
Sensor-Watch-66e95e4ab85444b2bdda32e7d04e7df138c52cc5.zip
Port beats to movement framework
-rwxr-xr-xmovement/make/Makefile1
-rw-r--r--movement/movement_config.h1
-rw-r--r--movement/watch_faces/complications/beats_face.c75
-rw-r--r--movement/watch_faces/complications/beats_face.h20
4 files changed, 97 insertions, 0 deletions
diff --git a/movement/make/Makefile b/movement/make/Makefile
index b65d1a47..9ff13b59 100755
--- a/movement/make/Makefile
+++ b/movement/make/Makefile
@@ -32,6 +32,7 @@ SRCS += \
../watch_faces/thermistor/thermistor_driver.c \
../watch_faces/thermistor/thermistor_readout_face.c \
../watch_faces/demos/character_set_face.c \
+ ../watch_faces/complications/beats_face.c \
# Leave this line at the bottom of the file; it has all the targets for making your project.
include $(TOP)/rules.mk
diff --git a/movement/movement_config.h b/movement/movement_config.h
index 99bffdd2..22daf2cb 100644
--- a/movement/movement_config.h
+++ b/movement/movement_config.h
@@ -7,6 +7,7 @@
#include "pulsometer_face.h"
#include "thermistor_readout_face.h"
#include "character_set_face.h"
+#include "beats_face.h"
const watch_face_t watch_faces[] = {
simple_clock_face,
diff --git a/movement/watch_faces/complications/beats_face.c b/movement/watch_faces/complications/beats_face.c
new file mode 100644
index 00000000..73a82719
--- /dev/null
+++ b/movement/watch_faces/complications/beats_face.c
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <string.h>
+#include "beats_face.h"
+#include "watch.h"
+
+const uint8_t UTC_OFFSET = 4; // set to your current UTC offset to see correct beats time
+const uint8_t BEAT_REFRESH_FREQUENCY = 8;
+
+void beats_face_setup(movement_settings_t *settings, void ** context_ptr) {
+ (void) settings;
+ (void) context_ptr;
+}
+
+void beats_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+ movement_request_tick_frequency(BEAT_REFRESH_FREQUENCY);
+}
+
+bool beats_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+
+ char buf[14];
+ float beats;
+
+ watch_date_time date_time;
+ switch (event.event_type) {
+ 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, UTC_OFFSET);
+ sprintf(buf, "bt %6.0f", beats * 100);
+
+ watch_display_string(buf, 0);
+ break;
+ case EVENT_LOW_ENERGY_UPDATE:
+ date_time = watch_rtc_get_date_time();
+ beats = clock2beats(date_time.unit.hour, date_time.unit.minute, date_time.unit.second, event.subsecond, UTC_OFFSET);
+ sprintf(buf, "bt %4d ", (int)beats);
+
+ watch_display_string(buf, 0);
+ break;
+ case EVENT_MODE_BUTTON_UP:
+ movement_move_to_next_face();
+ break;
+ case EVENT_LIGHT_BUTTON_DOWN:
+ movement_illuminate_led();
+ break;
+ case EVENT_ALARM_BUTTON_DOWN:
+ case EVENT_ALARM_BUTTON_UP:
+ case EVENT_ALARM_LONG_PRESS:
+ default:
+ break;
+ }
+
+ return true;
+}
+
+void beats_face_resign(movement_settings_t *settings, void *context) {
+ (void) 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 + 1) * 60 * 60; // offset from utc + 1 since beats in in UTC+1
+
+ beats /= 86.4; // convert to beats
+ while(beats > 1000) beats -= 1000; // beats %= 1000 but for a float
+
+ return beats;
+} \ No newline at end of file
diff --git a/movement/watch_faces/complications/beats_face.h b/movement/watch_faces/complications/beats_face.h
new file mode 100644
index 00000000..fe34f5aa
--- /dev/null
+++ b/movement/watch_faces/complications/beats_face.h
@@ -0,0 +1,20 @@
+#ifndef BEATS_FACE_H_
+#define BEATS_FACE_H_
+
+#include "movement.h"
+
+float clock2beats(uint16_t, uint16_t, uint16_t, uint16_t, int16_t);
+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);
+void beats_face_resign(movement_settings_t *settings, void *context);
+
+static const watch_face_t beats_face = {
+ beats_face_setup,
+ beats_face_activate,
+ beats_face_loop,
+ beats_face_resign,
+ NULL
+};
+
+#endif // BEATS_FACE_H_ \ No newline at end of file