]> git.earman.xyz Git - sensor-watch.git/commitdiff
add 'hello there' face, demo for documentation
authorJoey Castillo <joeycastillo@utexas.edu>
Tue, 21 Dec 2021 18:30:20 +0000 (12:30 -0600)
committerJoey Castillo <joeycastillo@utexas.edu>
Tue, 21 Dec 2021 18:30:20 +0000 (12:30 -0600)
movement/make/Makefile
movement/movement_config.h
movement/watch_faces/demos/hello_there_face.c [new file with mode: 0644]
movement/watch_faces/demos/hello_there_face.h [new file with mode: 0644]

index b7a0e6e2276d7bdd6c352f10dcde3d3665cd1719..4910b10292d92c54d7ad9e78f6ac34f110408ae3 100755 (executable)
@@ -40,6 +40,7 @@ SRCS += \
   ../watch_faces/demos/voltage_face.c \
   ../watch_faces/demos/lis2dh_logging_face.c \
   ../watch_faces/demos/demo_face.c \
+  ../watch_faces/demos/hello_there_face.c \
   ../watch_faces/complications/beats_face.c \
   ../watch_faces/complications/day_one_face.c \
   ../watch_faces/complications/stopwatch_face.c \
index 6aeb0b83f2249343f414ab60008fc8b5a66018d7..047628adfa354356990a31b21d82d157d38d7302 100644 (file)
 #include "totp_face.h"
 #include "lis2dh_logging_face.h"
 #include "demo_face.h"
+#include "hello_there_face.h"
 
 const watch_face_t watch_faces[] = {
     simple_clock_face,
+    hello_there_face,
     preferences_face,
     set_time_face,
 };
diff --git a/movement/watch_faces/demos/hello_there_face.c b/movement/watch_faces/demos/hello_there_face.c
new file mode 100644 (file)
index 0000000..e023b9d
--- /dev/null
@@ -0,0 +1,56 @@
+#include <stdlib.h>
+#include <string.h>
+#include "hello_there_face.h"
+#include "watch.h"
+
+void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
+    (void) settings;
+    (void) watch_face_index;
+    if (*context_ptr == NULL) {
+        *context_ptr = malloc(sizeof(hello_there_state_t));
+        memset(*context_ptr, 0, sizeof(hello_there_state_t));
+    }
+}
+
+void hello_there_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    hello_there_state_t *state = (hello_there_state_t *)context;
+    state->current_word = 0;
+    state->animating = true;
+}
+
+bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    hello_there_state_t *state = (hello_there_state_t *)context;
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+        case EVENT_TICK:
+            if (state->animating) {
+                if (state->current_word == 0) watch_display_string("Hello ", 4);
+                else watch_display_string(" there", 4);
+                state->current_word = (state->current_word + 1) % 2;
+            }
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            movement_illuminate_led();
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            state->animating = !state->animating;   
+            break;
+        case EVENT_TIMEOUT:
+            movement_move_to_face(0);
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void hello_there_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+}
diff --git a/movement/watch_faces/demos/hello_there_face.h b/movement/watch_faces/demos/hello_there_face.h
new file mode 100644 (file)
index 0000000..0174b6f
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef HELLO_THERE_FACE_H_
+#define HELLO_THERE_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+    uint8_t current_word;
+    bool animating;
+} hello_there_state_t;
+
+void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void hello_there_face_activate(movement_settings_t *settings, void *context);
+bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void hello_there_face_resign(movement_settings_t *settings, void *context);
+
+static const watch_face_t hello_there_face = {
+    hello_there_face_setup,
+    hello_there_face_activate,
+    hello_there_face_loop,
+    hello_there_face_resign,
+    NULL
+};
+
+#endif // HELLO_THERE_FACE_H_