]> git.earman.xyz Git - sensor-watch.git/commitdiff
movement: add template for watch face generator
authorJoey Castillo <joeycastillo@utexas.edu>
Tue, 25 Jan 2022 22:12:56 +0000 (17:12 -0500)
committerJoey Castillo <joeycastillo@utexas.edu>
Tue, 25 Jan 2022 22:12:56 +0000 (17:12 -0500)
movement/make/Makefile
movement/movement_faces.h
movement/template/template.c [new file with mode: 0644]
movement/template/template.h [new file with mode: 0644]

index 0834eec55ef908f7938ea577913f09e7d5990a60..b70d7092c8394432581fc95a2f5526eff1490037 100755 (executable)
@@ -50,6 +50,7 @@ SRCS += \
   ../watch_faces/complication/sunrise_sunset_face.c \
   ../watch_faces/complication/countdown_face.c \
   ../watch_faces/complication/blinky_face.c \
+# New watch faces go above this line.
 
 # Leave this line at the bottom of the file; it has all the targets for making your project.
 include $(TOP)/rules.mk
index 6c99ccdc61fd93be1b44cb368450e7d93f178825..ce810b839b6669acab5f7e62335ba86b18140932 100644 (file)
@@ -44,5 +44,6 @@
 #include "sunrise_sunset_face.h"
 #include "countdown_face.h"
 #include "blinky_face.h"
+// New includes go above this line.
 
 #endif // MOVEMENT_FACES_H_
diff --git a/movement/template/template.c b/movement/template/template.c
new file mode 100644 (file)
index 0000000..3f60be9
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) <#year#> <#author_name#>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "<#watch_face_name#>_face.h"
+
+void <#watch_face_name#>_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
+    (void) settings;
+    if (*context_ptr == NULL) {
+        *context_ptr = malloc(sizeof(<#watch_face_name#>_state_t));
+        memset(*context_ptr, 0, sizeof(<#watch_face_name#>));
+        // Do any one-time tasks in here; the inside of this conditional happens only at boot.
+    }
+    // Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep.
+}
+
+void <#watch_face_name#>_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    <#watch_face_name#>_state_t *state = (<#watch_face_name#>_state_t *)context;
+
+    // Handle any tasks related to your watch face coming on screen.
+}
+
+bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    <#watch_face_name#>_state_t *state = (<#watch_face_name#>_state_t *)context;
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+            // Show your initial UI here.
+            break;
+        case EVENT_TICK:
+            // If needed, update your display here.
+        case EVENT_MODE_BUTTON_UP:
+            // You shouldn't need to change this case; Mode almost always moves to the next watch face.
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            // If you have other uses for the Light button, you can opt not to illuminate the LED for this event.
+            movement_illuminate_led();
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            // Just in case you have need for another button.
+            break;
+        case EVENT_TIMEOUT:
+            // Your watch face will receive this event after a period of inactivity. If it makes sense to resign,
+            // you may uncomment this line to move back to the first watch face in the list:
+            // movement_move_to_face(0);
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+            // If you did not resign in EVENT_TIMEOUT, you can use this event to update the display once a minute.
+            // Avoid displaying fast-updating values like seconds, since the display won't update again for 60 seconds.
+            // You should also consider starting the tick animation, to show the wearer that this is sleep mode:
+            // watch_start_tick_animation(500);
+            break;
+        default:
+            break;
+    }
+
+    // return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer nere,
+    // you should return false since the PWM driver does not operate in standby mode.
+    return true;
+}
+
+void <#watch_face_name#>_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+
+    // handle any cleanup before your watch face goes off-screen.
+}
diff --git a/movement/template/template.h b/movement/template/template.h
new file mode 100644 (file)
index 0000000..29f6634
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) <#year#> <#author_name#>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef <#WATCH_FACE_NAME#>_FACE_H_
+#define <#WATCH_FACE_NAME#>_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+    // Anything you need to keep track of, put it here!
+    uint8_t unused;
+} <#watch_face_name#>_state_t;
+
+void <#watch_face_name#>_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void <#watch_face_name#>_face_activate(movement_settings_t *settings, void *context);
+bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void <#watch_face_name#>_face_resign(movement_settings_t *settings, void *context);
+
+#define <#watch_face_name#>_face ((const watch_face_t){ \
+    <#watch_face_name#>_face_setup, \
+    <#watch_face_name#>_face_activate, \
+    <#watch_face_name#>_face_loop, \
+    <#watch_face_name#>_face_resign, \
+    NULL, \
+})
+
+#endif // <#WATCH_FACE_NAME#>_FACE_H_