diff options
author | joeycastillo <joeycastillo@utexas.edu> | 2021-11-11 06:30:44 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 06:30:44 -0600 |
commit | 323e6dfebaa8f98e0b7c503da1c85fbfa5d268d9 (patch) | |
tree | 7730756096827133f8f9a0fe5cd0b73d959f2397 | |
parent | 1b4bfe35c2ee402314a4aab503bc6d5890eeee91 (diff) | |
parent | b0ec40ae460063f711cac963b2e7a0d826c710d7 (diff) | |
download | Sensor-Watch-323e6dfebaa8f98e0b7c503da1c85fbfa5d268d9.tar.gz Sensor-Watch-323e6dfebaa8f98e0b7c503da1c85fbfa5d268d9.tar.bz2 Sensor-Watch-323e6dfebaa8f98e0b7c503da1c85fbfa5d268d9.zip |
Merge pull request #21 from tahnok/stopwatch_face
Add stopwatch face to movement
-rwxr-xr-x | movement/make/Makefile | 1 | ||||
-rw-r--r-- | movement/movement_config.h | 1 | ||||
-rw-r--r-- | movement/watch_faces/complications/stopwatch_face.c | 76 | ||||
-rw-r--r-- | movement/watch_faces/complications/stopwatch_face.h | 26 |
4 files changed, 104 insertions, 0 deletions
diff --git a/movement/make/Makefile b/movement/make/Makefile index aecd6b58..b595d2dd 100755 --- a/movement/make/Makefile +++ b/movement/make/Makefile @@ -36,6 +36,7 @@ SRCS += \ ../watch_faces/demos/voltage_face.c \ ../watch_faces/complications/beats_face.c \ ../watch_faces/complications/day_one_face.c \ + ../watch_faces/complications/stopwatch_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 70bedc22..fa5ddf18 100644 --- a/movement/movement_config.h +++ b/movement/movement_config.h @@ -11,6 +11,7 @@ #include "beats_face.h" #include "day_one_face.h" #include "voltage_face.h" +#include "stopwatch_face.h" const watch_face_t watch_faces[] = { simple_clock_face, diff --git a/movement/watch_faces/complications/stopwatch_face.c b/movement/watch_faces/complications/stopwatch_face.c new file mode 100644 index 00000000..d1d1ee73 --- /dev/null +++ b/movement/watch_faces/complications/stopwatch_face.c @@ -0,0 +1,76 @@ +#include <stdlib.h> +#include <string.h> +#include "stopwatch_face.h" +#include "watch.h" + +void stopwatch_face_setup(movement_settings_t *settings, void ** context_ptr) { + (void) settings; + if (*context_ptr == NULL) *context_ptr = malloc(sizeof(stopwatch_state_t)); +} + +void stopwatch_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + memset(context, 0, sizeof(stopwatch_state_t)); +} + +bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + + stopwatch_state_t *stopwatch_state = (stopwatch_state_t *)context; + char buf[14]; + + switch (event.event_type) { + case EVENT_ACTIVATE: + watch_set_colon(); + stopwatch_state->running = false; + watch_display_string("st 00000", 0); + break; + case EVENT_TICK: + if (stopwatch_state->running) { + stopwatch_state->seconds++; + if (stopwatch_state->seconds == 60) { + stopwatch_state->minutes++; + stopwatch_state->seconds = 0; + } + if (stopwatch_state->minutes == 60) { + stopwatch_state->hours++; + stopwatch_state->minutes = 0; + } + } + + sprintf(buf, "st%2d%02d%02d", stopwatch_state->hours, stopwatch_state->minutes, stopwatch_state->seconds); + 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(); + if (!stopwatch_state->running) { + stopwatch_state->seconds = 0; + stopwatch_state->minutes = 0; + stopwatch_state->hours = 0; + watch_display_string("st 00000", 0); + } + break; + case EVENT_ALARM_BUTTON_DOWN: + stopwatch_state->running = !stopwatch_state->running; + break; + case EVENT_TIMEOUT: + // explicitly ignore the timeout event so we stay on screen + break; + case EVENT_LOW_ENERGY_UPDATE: + stopwatch_state->running = false; + watch_set_indicator(WATCH_INDICATOR_BELL); + break; + default: + break; + } + + return true; +} + +void stopwatch_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +}
\ No newline at end of file diff --git a/movement/watch_faces/complications/stopwatch_face.h b/movement/watch_faces/complications/stopwatch_face.h new file mode 100644 index 00000000..537c01ce --- /dev/null +++ b/movement/watch_faces/complications/stopwatch_face.h @@ -0,0 +1,26 @@ +#ifndef STOPWATCH_FACE_H_ +#define STOPWATCH_FACE_H_ + +#include "movement.h" + +typedef struct { + bool running; + uint8_t seconds; + uint8_t minutes; + uint8_t hours; +} stopwatch_state_t; + +void stopwatch_face_setup(movement_settings_t *settings, void ** context_ptr); +void stopwatch_face_activate(movement_settings_t *settings, void *context); +bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void stopwatch_face_resign(movement_settings_t *settings, void *context); + +static const watch_face_t stopwatch_face = { + stopwatch_face_setup, + stopwatch_face_activate, + stopwatch_face_loop, + stopwatch_face_resign, + NULL +}; + +#endif // STOPWATCH_FACE_H_
\ No newline at end of file |