summaryrefslogtreecommitdiffstats
path: root/movement
diff options
context:
space:
mode:
Diffstat (limited to 'movement')
-rw-r--r--movement/make/Makefile1
-rw-r--r--movement/movement_config.h1
-rw-r--r--movement/movement_faces.h1
-rw-r--r--movement/watch_faces/sensor/phototransistor_readout_face.c104
-rw-r--r--movement/watch_faces/sensor/phototransistor_readout_face.h56
5 files changed, 163 insertions, 0 deletions
diff --git a/movement/make/Makefile b/movement/make/Makefile
index 58895862..e20aa500 100644
--- a/movement/make/Makefile
+++ b/movement/make/Makefile
@@ -96,6 +96,7 @@ SRCS += \
../watch_faces/complication/morsecalc_face.c \
../watch_faces/complication/rpn_calculator_face.c \
../watch_faces/complication/ships_bell_face.c \
+ ../watch_faces/sensor/phototransistor_readout_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.
diff --git a/movement/movement_config.h b/movement/movement_config.h
index 9e446d4d..8ee5d550 100644
--- a/movement/movement_config.h
+++ b/movement/movement_config.h
@@ -28,6 +28,7 @@
#include "movement_faces.h"
const watch_face_t watch_faces[] = {
+ phototransistor_readout_face,
simple_clock_face,
world_clock_face,
sunrise_sunset_face,
diff --git a/movement/movement_faces.h b/movement/movement_faces.h
index 806e82a5..4a197d49 100644
--- a/movement/movement_faces.h
+++ b/movement/movement_faces.h
@@ -74,6 +74,7 @@
#include "morsecalc_face.h"
#include "rpn_calculator_face.h"
#include "ships_bell_face.h"
+#include "phototransistor_readout_face.h"
// New includes go above this line.
#endif // MOVEMENT_FACES_H_
diff --git a/movement/watch_faces/sensor/phototransistor_readout_face.c b/movement/watch_faces/sensor/phototransistor_readout_face.c
new file mode 100644
index 00000000..3726a117
--- /dev/null
+++ b/movement/watch_faces/sensor/phototransistor_readout_face.c
@@ -0,0 +1,104 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Joey Castillo
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include "phototransistor_driver.h"
+#include "phototransistor_readout_face.h"
+
+void phototransistor_readout_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(phototransistor_readout_state_t));
+ memset(*context_ptr, 0, sizeof(phototransistor_readout_state_t));
+ // 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 phototransistor_readout_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+ phototransistor_driver_enable();
+ gpio_set_pin_function(A4, GPIO_PIN_FUNCTION_OFF);
+ gpio_set_pin_direction(A4, GPIO_DIRECTION_IN);
+ movement_request_tick_frequency(16);
+}
+
+bool phototransistor_readout_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ // Show your initial UI here.
+ watch_display_string("LT", 0);
+ break;
+ case EVENT_TICK:
+ // If needed, update your display here.
+ if (watch_get_pin_level(A4)) {
+ watch_display_string("HI", 8);
+ } else {
+ watch_display_string("LO", 8);
+ }
+ break;
+ 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 here,
+ // you should return false since the PWM driver does not operate in standby mode.
+ return true;
+}
+
+void phototransistor_readout_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+
+ phototransistor_driver_disable();
+}
+
diff --git a/movement/watch_faces/sensor/phototransistor_readout_face.h b/movement/watch_faces/sensor/phototransistor_readout_face.h
new file mode 100644
index 00000000..0e88420d
--- /dev/null
+++ b/movement/watch_faces/sensor/phototransistor_readout_face.h
@@ -0,0 +1,56 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Joey Castillo
+ *
+ * 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 PHOTOTRANSISTOR_READOUT_FACE_H_
+#define PHOTOTRANSISTOR_READOUT_FACE_H_
+
+#include "movement.h"
+
+/*
+ * A DESCRIPTION OF YOUR WATCH FACE
+ *
+ * and a description of how use it
+ *
+ */
+
+typedef struct {
+ // Anything you need to keep track of, put it here!
+ uint8_t unused;
+} phototransistor_readout_state_t;
+
+void phototransistor_readout_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void phototransistor_readout_face_activate(movement_settings_t *settings, void *context);
+bool phototransistor_readout_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void phototransistor_readout_face_resign(movement_settings_t *settings, void *context);
+
+#define phototransistor_readout_face ((const watch_face_t){ \
+ phototransistor_readout_face_setup, \
+ phototransistor_readout_face_activate, \
+ phototransistor_readout_face_loop, \
+ phototransistor_readout_face_resign, \
+ NULL, \
+})
+
+#endif // PHOTOTRANSISTOR_READOUT_FACE_H_
+