]> git.earman.xyz Git - sensor-watch.git/commitdiff
move accelerometer and light to sensor, not demo folder
authorJoey Castillo <joeycastillo@utexas.edu>
Sun, 18 May 2025 02:19:45 +0000 (22:19 -0400)
committerJoey Castillo <joeycastillo@utexas.edu>
Sun, 18 May 2025 02:19:45 +0000 (22:19 -0400)
watch-faces.mk
watch-faces/demo/accelerometer_status_face.c [deleted file]
watch-faces/demo/accelerometer_status_face.h [deleted file]
watch-faces/demo/light_sensor_face.c [deleted file]
watch-faces/demo/light_sensor_face.h [deleted file]
watch-faces/sensor/accelerometer_status_face.c [new file with mode: 0644]
watch-faces/sensor/accelerometer_status_face.h [new file with mode: 0644]
watch-faces/sensor/light_sensor_face.c [new file with mode: 0644]
watch-faces/sensor/light_sensor_face.h [new file with mode: 0644]

index c07c9aa61da939a0472f240194cf9a37481424bd..d3c2159881613db371ea609cb1b40e79c83c1612 100644 (file)
@@ -9,9 +9,10 @@ SRCS += \
   ./watch-faces/complication/sunrise_sunset_face.c \
   ./watch-faces/complication/moon_phase_face.c \
   ./watch-faces/complication/days_since_face.c \
-  ./watch-faces/demo/accelerometer_status_face.c \
   ./watch-faces/demo/all_segments_face.c \
   ./watch-faces/demo/character_set_face.c \
+  ./watch-faces/sensor/accelerometer_status_face.c \
+  ./watch-faces/sensor/light_sensor_face.c \
   ./watch-faces/sensor/temperature_display_face.c \
   ./watch-faces/sensor/temperature_logging_face.c \
   ./watch-faces/sensor/activity_logging_face.c \
@@ -19,7 +20,6 @@ SRCS += \
   ./watch-faces/settings/set_time_face.c \
   ./watch-faces/settings/preferences_face.c \
   ./watch-faces/settings/settings_face.c \
-  ./watch-faces/demo/light_sensor_face.c \
   ./watch-faces/io/chirpy_demo_face.c \
   ./watch-faces/io/irda_upload_face.c \
 # New watch faces go above this line.
diff --git a/watch-faces/demo/accelerometer_status_face.c b/watch-faces/demo/accelerometer_status_face.c
deleted file mode 100644 (file)
index a358a8b..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2022 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 "accelerometer_status_face.h"
-#include "lis2dw.h"
-#include "tc.h"
-#include "watch.h"
-
-static void _accelerometer_status_face_update_display(accel_interrupt_count_state_t *state) {
-    (void) state;
-
-    // Accelerometer title
-    watch_display_text_with_fallback(WATCH_POSITION_TOP, "ACCEL", "AC");
-
-    // sensing is live!
-    watch_set_indicator(WATCH_INDICATOR_SIGNAL);
-
-    // Sleep/active state
-    if (HAL_GPIO_A4_read()) watch_display_text(WATCH_POSITION_BOTTOM, "Still ");
-    else watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, "Active", " ACtiv");
-}
-
-void accelerometer_status_face_setup(uint8_t watch_face_index, void ** context_ptr) {
-    (void) watch_face_index;
-    if (*context_ptr == NULL) {
-        *context_ptr = malloc(sizeof(accel_interrupt_count_state_t));
-        memset(*context_ptr, 0, sizeof(accel_interrupt_count_state_t));
-    }
-}
-
-void accelerometer_status_face_activate(void *context) {
-    accel_interrupt_count_state_t *state = (accel_interrupt_count_state_t *)context;
-
-    // never in settings mode at the start
-    state->is_setting = false;
-
-    // update more quickly to catch changes, also to blink setting
-    movement_request_tick_frequency(4);
-
-    // fetch current threshold from accelerometer
-    state->threshold = lis2dw_get_wakeup_threshold();
-}
-
-bool accelerometer_status_face_loop(movement_event_t event, void *context) {
-    accel_interrupt_count_state_t *state = (accel_interrupt_count_state_t *)context;
-
-    if (state->is_setting) {
-        watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
-        switch (event.event_type) {
-            case EVENT_LIGHT_BUTTON_DOWN:
-                state->new_threshold = (state->new_threshold + 1) % 64;
-                // fall through
-            case EVENT_TICK:
-                {
-                    char buf[11];
-                    if (event.subsecond % 2) {
-                        watch_display_text(WATCH_POSITION_BOTTOM, "      ");
-                    } else {
-                        watch_display_text(WATCH_POSITION_TOP_RIGHT, "  ");
-                        watch_display_text_with_fallback(WATCH_POSITION_TOP, "WAKth", "TH");
-                        watch_display_float_with_best_effort(state->new_threshold * 0.03125, " G");
-                        printf("%s\n", buf);
-                    }
-                }
-                break;
-            case EVENT_ALARM_BUTTON_UP:
-                lis2dw_configure_wakeup_threshold(state->new_threshold);
-                state->threshold = state->new_threshold;
-                state->is_setting = false;
-                break;
-            case EVENT_TIMEOUT:
-                movement_move_to_face(0);
-                break;
-            default:
-                movement_default_loop_handler(event);
-                break;
-        }
-    } else {
-        switch (event.event_type) {
-            case EVENT_ACTIVATE:
-            case EVENT_TICK:
-                _accelerometer_status_face_update_display(state);
-                break;
-            case EVENT_LOW_ENERGY_UPDATE:
-                // start tick animation if necessary
-                if (!watch_sleep_animation_is_running()) watch_start_sleep_animation(1000);
-                // update the display
-                _accelerometer_status_face_update_display(state);
-                // on classic LCD, clear seconds since they interfere with the sleep animation.
-                if (watch_get_lcd_type() == WATCH_LCD_TYPE_CLASSIC) watch_display_text(WATCH_POSITION_SECONDS, "  ");
-                break;
-            case EVENT_ALARM_LONG_PRESS:
-                state->new_threshold = state->threshold;
-                state->is_setting = true;
-                return false;
-            default:
-                movement_default_loop_handler(event);
-                break;
-        }
-    }
-
-    return true;
-}
-
-void accelerometer_status_face_resign(void *context) {
-    (void) context;
-}
diff --git a/watch-faces/demo/accelerometer_status_face.h b/watch-faces/demo/accelerometer_status_face.h
deleted file mode 100644 (file)
index 2b152d5..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2022 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.
- */
-
-#pragma once
-
-/*
- * Accelerometer Interrupt Counter
- *
- * This is an experimental watch face for counting the number of interrupts that
- * the Sensor Watch Motion acceleromoeter board fires. I expect it will be removed
- * once we integrate accelerometer functionality more deeply into Movement.
- */
-
-#include "movement.h"
-#include "watch.h"
-
-typedef struct {
-    uint8_t new_threshold;
-    uint8_t threshold;
-    bool is_setting;
-} accel_interrupt_count_state_t;
-
-void accelerometer_status_face_setup(uint8_t watch_face_index, void ** context_ptr);
-void accelerometer_status_face_activate(void *context);
-bool accelerometer_status_face_loop(movement_event_t event, void *context);
-void accelerometer_status_face_resign(void *context);
-
-#define accelerometer_status_face ((const watch_face_t){ \
-    accelerometer_status_face_setup, \
-    accelerometer_status_face_activate, \
-    accelerometer_status_face_loop, \
-    accelerometer_status_face_resign, \
-    NULL, \
-})
diff --git a/watch-faces/demo/light_sensor_face.c b/watch-faces/demo/light_sensor_face.c
deleted file mode 100644 (file)
index a3f0223..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2024 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 "light_sensor_face.h"
-#include "tc.h"
-#include "eic.h"
-#include "usb.h"
-#include "adc.h"
-
-#ifdef HAS_IR_SENSOR
-
-void light_sensor_face_setup(uint8_t watch_face_index, void ** context_ptr) {
-    (void) watch_face_index;
-    if (*context_ptr == NULL) {
-        *context_ptr = malloc(sizeof(light_sensor_state_t));
-        memset(*context_ptr, 0, sizeof(light_sensor_state_t));
-        // Do any one-time tasks in here; the inside of this conditional happens only at boot.
-    }    
-}
-
-void light_sensor_face_activate(void *context) {
-    light_sensor_state_t *state = (light_sensor_state_t *)context;
-    (void) state;
-    HAL_GPIO_IR_ENABLE_out();
-    HAL_GPIO_IR_ENABLE_clr();
-    HAL_GPIO_IRSENSE_pmuxen(HAL_GPIO_PMUX_ADC);
-    adc_init();
-    adc_enable();
-    movement_request_tick_frequency(8);
-}
-
-bool light_sensor_face_loop(movement_event_t event, void *context) {
-    light_sensor_state_t *state = (light_sensor_state_t *)context;
-    (void) state;
-
-    switch (event.event_type) {
-        case EVENT_NONE:
-        case EVENT_ACTIVATE:
-        case EVENT_TICK:
-        {
-            char buf[14];
-            uint16_t light_level = adc_get_analog_value(HAL_GPIO_IRSENSE_pin());
-            snprintf(buf, 14, "LL  %-6d", light_level);
-            watch_display_text(WATCH_POSITION_FULL, buf);
-            printf("%s\n", buf);
-        }
-            break;
-        case EVENT_LIGHT_BUTTON_UP:
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            break;
-        case EVENT_TIMEOUT:
-            break;
-        case EVENT_LOW_ENERGY_UPDATE:
-            watch_display_text(WATCH_POSITION_TOP_RIGHT, " <");
-            break;
-        default:
-            return movement_default_loop_handler(event);
-    }
-
-    return false;
-}
-
-void light_sensor_face_resign(void *context) {
-    (void) context;
-
-    adc_disable();
-    HAL_GPIO_IRSENSE_pmuxdis();
-    HAL_GPIO_IRSENSE_off();
-    HAL_GPIO_IR_ENABLE_off();
-}
-
-#endif // HAS_IR_SENSOR
diff --git a/watch-faces/demo/light_sensor_face.h b/watch-faces/demo/light_sensor_face.h
deleted file mode 100644 (file)
index 29ee4cb..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2024 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.
- */
-
-#pragma once
-
-#include "movement.h"
-
-#ifdef HAS_IR_SENSOR
-
-/*
- * LIGHT SENSOR PLAYGROUND
- *
- * Temporary watch face for playing with the light sensor.
- *
- */
-
-typedef struct {
-    // Anything you need to keep track of, put it here!
-    uint8_t unused;
-} light_sensor_state_t;
-
-void light_sensor_face_setup(uint8_t watch_face_index, void ** context_ptr);
-void light_sensor_face_activate(void *context);
-bool light_sensor_face_loop(movement_event_t event, void *context);
-void light_sensor_face_resign(void *context);
-
-#define light_sensor_face ((const watch_face_t){ \
-    light_sensor_face_setup, \
-    light_sensor_face_activate, \
-    light_sensor_face_loop, \
-    light_sensor_face_resign, \
-    NULL, \
-})
-
-#endif // HAS_IR_SENSOR
diff --git a/watch-faces/sensor/accelerometer_status_face.c b/watch-faces/sensor/accelerometer_status_face.c
new file mode 100644 (file)
index 0000000..a358a8b
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 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 "accelerometer_status_face.h"
+#include "lis2dw.h"
+#include "tc.h"
+#include "watch.h"
+
+static void _accelerometer_status_face_update_display(accel_interrupt_count_state_t *state) {
+    (void) state;
+
+    // Accelerometer title
+    watch_display_text_with_fallback(WATCH_POSITION_TOP, "ACCEL", "AC");
+
+    // sensing is live!
+    watch_set_indicator(WATCH_INDICATOR_SIGNAL);
+
+    // Sleep/active state
+    if (HAL_GPIO_A4_read()) watch_display_text(WATCH_POSITION_BOTTOM, "Still ");
+    else watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, "Active", " ACtiv");
+}
+
+void accelerometer_status_face_setup(uint8_t watch_face_index, void ** context_ptr) {
+    (void) watch_face_index;
+    if (*context_ptr == NULL) {
+        *context_ptr = malloc(sizeof(accel_interrupt_count_state_t));
+        memset(*context_ptr, 0, sizeof(accel_interrupt_count_state_t));
+    }
+}
+
+void accelerometer_status_face_activate(void *context) {
+    accel_interrupt_count_state_t *state = (accel_interrupt_count_state_t *)context;
+
+    // never in settings mode at the start
+    state->is_setting = false;
+
+    // update more quickly to catch changes, also to blink setting
+    movement_request_tick_frequency(4);
+
+    // fetch current threshold from accelerometer
+    state->threshold = lis2dw_get_wakeup_threshold();
+}
+
+bool accelerometer_status_face_loop(movement_event_t event, void *context) {
+    accel_interrupt_count_state_t *state = (accel_interrupt_count_state_t *)context;
+
+    if (state->is_setting) {
+        watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
+        switch (event.event_type) {
+            case EVENT_LIGHT_BUTTON_DOWN:
+                state->new_threshold = (state->new_threshold + 1) % 64;
+                // fall through
+            case EVENT_TICK:
+                {
+                    char buf[11];
+                    if (event.subsecond % 2) {
+                        watch_display_text(WATCH_POSITION_BOTTOM, "      ");
+                    } else {
+                        watch_display_text(WATCH_POSITION_TOP_RIGHT, "  ");
+                        watch_display_text_with_fallback(WATCH_POSITION_TOP, "WAKth", "TH");
+                        watch_display_float_with_best_effort(state->new_threshold * 0.03125, " G");
+                        printf("%s\n", buf);
+                    }
+                }
+                break;
+            case EVENT_ALARM_BUTTON_UP:
+                lis2dw_configure_wakeup_threshold(state->new_threshold);
+                state->threshold = state->new_threshold;
+                state->is_setting = false;
+                break;
+            case EVENT_TIMEOUT:
+                movement_move_to_face(0);
+                break;
+            default:
+                movement_default_loop_handler(event);
+                break;
+        }
+    } else {
+        switch (event.event_type) {
+            case EVENT_ACTIVATE:
+            case EVENT_TICK:
+                _accelerometer_status_face_update_display(state);
+                break;
+            case EVENT_LOW_ENERGY_UPDATE:
+                // start tick animation if necessary
+                if (!watch_sleep_animation_is_running()) watch_start_sleep_animation(1000);
+                // update the display
+                _accelerometer_status_face_update_display(state);
+                // on classic LCD, clear seconds since they interfere with the sleep animation.
+                if (watch_get_lcd_type() == WATCH_LCD_TYPE_CLASSIC) watch_display_text(WATCH_POSITION_SECONDS, "  ");
+                break;
+            case EVENT_ALARM_LONG_PRESS:
+                state->new_threshold = state->threshold;
+                state->is_setting = true;
+                return false;
+            default:
+                movement_default_loop_handler(event);
+                break;
+        }
+    }
+
+    return true;
+}
+
+void accelerometer_status_face_resign(void *context) {
+    (void) context;
+}
diff --git a/watch-faces/sensor/accelerometer_status_face.h b/watch-faces/sensor/accelerometer_status_face.h
new file mode 100644 (file)
index 0000000..2b152d5
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 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.
+ */
+
+#pragma once
+
+/*
+ * Accelerometer Interrupt Counter
+ *
+ * This is an experimental watch face for counting the number of interrupts that
+ * the Sensor Watch Motion acceleromoeter board fires. I expect it will be removed
+ * once we integrate accelerometer functionality more deeply into Movement.
+ */
+
+#include "movement.h"
+#include "watch.h"
+
+typedef struct {
+    uint8_t new_threshold;
+    uint8_t threshold;
+    bool is_setting;
+} accel_interrupt_count_state_t;
+
+void accelerometer_status_face_setup(uint8_t watch_face_index, void ** context_ptr);
+void accelerometer_status_face_activate(void *context);
+bool accelerometer_status_face_loop(movement_event_t event, void *context);
+void accelerometer_status_face_resign(void *context);
+
+#define accelerometer_status_face ((const watch_face_t){ \
+    accelerometer_status_face_setup, \
+    accelerometer_status_face_activate, \
+    accelerometer_status_face_loop, \
+    accelerometer_status_face_resign, \
+    NULL, \
+})
diff --git a/watch-faces/sensor/light_sensor_face.c b/watch-faces/sensor/light_sensor_face.c
new file mode 100644 (file)
index 0000000..a3f0223
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2024 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 "light_sensor_face.h"
+#include "tc.h"
+#include "eic.h"
+#include "usb.h"
+#include "adc.h"
+
+#ifdef HAS_IR_SENSOR
+
+void light_sensor_face_setup(uint8_t watch_face_index, void ** context_ptr) {
+    (void) watch_face_index;
+    if (*context_ptr == NULL) {
+        *context_ptr = malloc(sizeof(light_sensor_state_t));
+        memset(*context_ptr, 0, sizeof(light_sensor_state_t));
+        // Do any one-time tasks in here; the inside of this conditional happens only at boot.
+    }    
+}
+
+void light_sensor_face_activate(void *context) {
+    light_sensor_state_t *state = (light_sensor_state_t *)context;
+    (void) state;
+    HAL_GPIO_IR_ENABLE_out();
+    HAL_GPIO_IR_ENABLE_clr();
+    HAL_GPIO_IRSENSE_pmuxen(HAL_GPIO_PMUX_ADC);
+    adc_init();
+    adc_enable();
+    movement_request_tick_frequency(8);
+}
+
+bool light_sensor_face_loop(movement_event_t event, void *context) {
+    light_sensor_state_t *state = (light_sensor_state_t *)context;
+    (void) state;
+
+    switch (event.event_type) {
+        case EVENT_NONE:
+        case EVENT_ACTIVATE:
+        case EVENT_TICK:
+        {
+            char buf[14];
+            uint16_t light_level = adc_get_analog_value(HAL_GPIO_IRSENSE_pin());
+            snprintf(buf, 14, "LL  %-6d", light_level);
+            watch_display_text(WATCH_POSITION_FULL, buf);
+            printf("%s\n", buf);
+        }
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            break;
+        case EVENT_TIMEOUT:
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+            watch_display_text(WATCH_POSITION_TOP_RIGHT, " <");
+            break;
+        default:
+            return movement_default_loop_handler(event);
+    }
+
+    return false;
+}
+
+void light_sensor_face_resign(void *context) {
+    (void) context;
+
+    adc_disable();
+    HAL_GPIO_IRSENSE_pmuxdis();
+    HAL_GPIO_IRSENSE_off();
+    HAL_GPIO_IR_ENABLE_off();
+}
+
+#endif // HAS_IR_SENSOR
diff --git a/watch-faces/sensor/light_sensor_face.h b/watch-faces/sensor/light_sensor_face.h
new file mode 100644 (file)
index 0000000..29ee4cb
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2024 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.
+ */
+
+#pragma once
+
+#include "movement.h"
+
+#ifdef HAS_IR_SENSOR
+
+/*
+ * LIGHT SENSOR PLAYGROUND
+ *
+ * Temporary watch face for playing with the light sensor.
+ *
+ */
+
+typedef struct {
+    // Anything you need to keep track of, put it here!
+    uint8_t unused;
+} light_sensor_state_t;
+
+void light_sensor_face_setup(uint8_t watch_face_index, void ** context_ptr);
+void light_sensor_face_activate(void *context);
+bool light_sensor_face_loop(movement_event_t event, void *context);
+void light_sensor_face_resign(void *context);
+
+#define light_sensor_face ((const watch_face_t){ \
+    light_sensor_face_setup, \
+    light_sensor_face_activate, \
+    light_sensor_face_loop, \
+    light_sensor_face_resign, \
+    NULL, \
+})
+
+#endif // HAS_IR_SENSOR