diff options
Diffstat (limited to 'movement/watch_faces/demo')
-rw-r--r-- | movement/watch_faces/demo/character_set_face.c | 75 | ||||
-rw-r--r-- | movement/watch_faces/demo/character_set_face.h | 43 | ||||
-rw-r--r-- | movement/watch_faces/demo/demo_face.c | 141 | ||||
-rw-r--r-- | movement/watch_faces/demo/demo_face.h | 43 | ||||
-rw-r--r-- | movement/watch_faces/demo/hello_there_face.c | 112 | ||||
-rw-r--r-- | movement/watch_faces/demo/hello_there_face.h | 48 | ||||
-rw-r--r-- | movement/watch_faces/demo/lis2dh_logging_face.c | 215 | ||||
-rw-r--r-- | movement/watch_faces/demo/lis2dh_logging_face.h | 66 | ||||
-rw-r--r-- | movement/watch_faces/demo/voltage_face.c | 91 | ||||
-rw-r--r-- | movement/watch_faces/demo/voltage_face.h | 43 |
10 files changed, 877 insertions, 0 deletions
diff --git a/movement/watch_faces/demo/character_set_face.c b/movement/watch_faces/demo/character_set_face.c new file mode 100644 index 00000000..6aa42083 --- /dev/null +++ b/movement/watch_faces/demo/character_set_face.c @@ -0,0 +1,75 @@ +/* + * 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 "character_set_face.h" +#include "watch.h" + +void character_set_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(char)); +} + +void character_set_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + char *c = (char *)context; + *c = '@'; + movement_request_tick_frequency(0); +} + +bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + char *c = (char *)context; + char buf[11]; + switch (event.event_type) { + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_BUTTON_DOWN: + movement_illuminate_led(); + break; + case EVENT_ALARM_BUTTON_UP: + *c = (*c) + 1; + if (*c & 0x80) *c = ' '; + // fall through + case EVENT_ACTIVATE: + sprintf(buf, "%c%c%c%c%c%c%c%c%c%c", *c, *c, *c, *c, *c, *c, *c, *c, *c, *c); + watch_display_string(buf, 0); + break; + case EVENT_TIMEOUT: + movement_move_to_face(0); + break; + default: + break; + } + + return true; +} + +void character_set_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +} diff --git a/movement/watch_faces/demo/character_set_face.h b/movement/watch_faces/demo/character_set_face.h new file mode 100644 index 00000000..82627aed --- /dev/null +++ b/movement/watch_faces/demo/character_set_face.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef CHARACTER_SET_FACE_H_ +#define CHARACTER_SET_FACE_H_ + +#include "movement.h" + +void character_set_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void character_set_face_activate(movement_settings_t *settings, void *context); +bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void character_set_face_resign(movement_settings_t *settings, void *context); + +#define character_set_face ((const watch_face_t){ \ + character_set_face_setup, \ + character_set_face_activate, \ + character_set_face_loop, \ + character_set_face_resign, \ + NULL, \ +}) + +#endif // CHARACTER_SET_FACE_H_ diff --git a/movement/watch_faces/demo/demo_face.c b/movement/watch_faces/demo/demo_face.c new file mode 100644 index 00000000..c9a929a1 --- /dev/null +++ b/movement/watch_faces/demo/demo_face.c @@ -0,0 +1,141 @@ +/* + * 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 "demo_face.h" +#include "watch.h" + +typedef enum { + DEMO_FACE_TIME = 0, + DEMO_FACE_WORLD_TIME, + DEMO_FACE_BEATS, + DEMO_FACE_TOTP, + DEMO_FACE_TEMP_F, + DEMO_FACE_TEMP_C, + DEMO_FACE_TEMP_LOG_1, + DEMO_FACE_TEMP_LOG_2, + DEMO_FACE_DAY_ONE, + DEMO_FACE_STOPWATCH, + DEMO_FACE_PULSOMETER, + DEMO_FACE_BATTERY_VOLTAGE, + DEMO_FACE_NUM_FACES +} demo_face_index_t; + +void demo_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(demo_face_index_t)); + memset(*context_ptr, 0, sizeof(demo_face_index_t)); + } +} + +void demo_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; + movement_request_tick_frequency(0); + // ensure the watch never enters low energy mode + settings->bit.le_interval = 0; + settings->bit.led_duration = 3; +} + +bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + demo_face_index_t *screen = (demo_face_index_t *)context; + switch (event.event_type) { + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_BUTTON_DOWN: + movement_illuminate_led(); + break; + case EVENT_ALARM_BUTTON_UP: + *screen = ((*screen) + 1) % DEMO_FACE_NUM_FACES; + // fall through + case EVENT_ACTIVATE: + switch (*screen) { + case DEMO_FACE_TIME: + watch_display_string("TH10101036", 0); + watch_set_colon(); + break; + case DEMO_FACE_WORLD_TIME: + watch_display_string("UT10 21036", 0); + watch_set_indicator(WATCH_INDICATOR_PM); + break; + case DEMO_FACE_BEATS: + watch_display_string("bt 64125", 0); + watch_clear_indicator(WATCH_INDICATOR_PM); + watch_clear_colon(); + break; + case DEMO_FACE_TOTP: + watch_display_string("2F29808494", 0); + break; + case DEMO_FACE_TEMP_F: + watch_display_string("TE 72.1#F", 0); + break; + case DEMO_FACE_TEMP_C: + watch_display_string("TE 22.3#C", 0); + break; + case DEMO_FACE_TEMP_LOG_1: + watch_display_string("TL 43.6#F", 0); + break; + case DEMO_FACE_TEMP_LOG_2: + watch_display_string("AT 6100000", 0); + watch_set_colon(); + break; + case DEMO_FACE_DAY_ONE: + watch_clear_colon(); + watch_display_string("DA 12879", 0); + break; + case DEMO_FACE_STOPWATCH: + watch_display_string("ST 01042 ", 0); + watch_set_colon(); + break; + case DEMO_FACE_PULSOMETER: + watch_display_string(" 68 bpn", 0); + watch_clear_colon(); + break; + case DEMO_FACE_BATTERY_VOLTAGE: + watch_display_string("BA 2.97 V", 0); + break; + case DEMO_FACE_NUM_FACES: + // we won't get here, but silence the warning + break; + } + break; + case EVENT_TIMEOUT: + // ignore timeout + break; + default: + break; + } + + return true; +} + +void demo_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +} diff --git a/movement/watch_faces/demo/demo_face.h b/movement/watch_faces/demo/demo_face.h new file mode 100644 index 00000000..026e0d10 --- /dev/null +++ b/movement/watch_faces/demo/demo_face.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef DEMO_FACE_H_ +#define DEMO_FACE_H_ + +#include "movement.h" + +void demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void demo_face_activate(movement_settings_t *settings, void *context); +bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void demo_face_resign(movement_settings_t *settings, void *context); + +#define demo_face ((const watch_face_t){ \ + demo_face_setup, \ + demo_face_activate, \ + demo_face_loop, \ + demo_face_resign, \ + NULL, \ +}) + +#endif // DEMO_FACE_H_ diff --git a/movement/watch_faces/demo/hello_there_face.c b/movement/watch_faces/demo/hello_there_face.c new file mode 100644 index 00000000..f21cb762 --- /dev/null +++ b/movement/watch_faces/demo/hello_there_face.c @@ -0,0 +1,112 @@ +/* + * 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 "hello_there_face.h" +#include "watch.h" + +void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { + // These next two lines just silence the compiler warnings associated with unused parameters. + // We have no use for the settings or the watch_face_index, so we make that explicit here. + (void) settings; + (void) watch_face_index; + // At boot, context_ptr will be NULL indicating that we don't have anyplace to store our context. + if (*context_ptr == NULL) { + // in this case, we allocate an area of memory sufficient to store the stuff we need to track. + *context_ptr = malloc(sizeof(hello_there_state_t)); + } +} + +void hello_there_face_activate(movement_settings_t *settings, void *context) { + // same as above: silence the warning, we don't need to check the settings. + (void) settings; + // we do however need to set some things in our context. Here we cast it to the correct type... + hello_there_state_t *state = (hello_there_state_t *)context; + // ...and set the initial state of our watch face. We start out displaying the word 'Hello', + state->current_word = 0; + // and animate by default. + 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: + // on activate and tick, if we are animating, + if (state->animating) { + // we display the current word, + if (state->current_word == 0) watch_display_string("Hello ", 4); + else watch_display_string(" there", 4); + // and increment it so that it will update on the next tick. + state->current_word = (state->current_word + 1) % 2; + } + break; + case EVENT_LIGHT_BUTTON_UP: + // when the user presses 'light', we illuminate the LED. We could override this if + // our UI needed an additional button for input, consuming the light button press + // but not illuminating the LED. + movement_illuminate_led(); + break; + case EVENT_MODE_BUTTON_UP: + // when the user presses 'mode', we tell movement to move to the next watch face. + // movement will call our resign function, clear the screen, and transfer control + // to the next watch face in the list. + movement_move_to_next_face(); + break; + case EVENT_ALARM_BUTTON_UP: + // when the user presses 'alarm', we toggle the state of the animation. If animating, + // we stop; if stopped, we resume. + state->animating = !state->animating; + break; + case EVENT_LOW_ENERGY_UPDATE: + // This low energy mode update occurs once a minute, if the watch face is in the + // foreground when Movement enters low energy mode. We have the option of supporting + // this mode, but since our watch face animates once a second, the "Hello there" face + // isn't very useful in this mode. So we choose not to support it. (continued below) + break; + case EVENT_TIMEOUT: + // ... Instead, we respond to the timeout event. This event happens after a configurable + // interval on screen (1-30 minutes). The watch will give us this event as a chance to + // resign control if we want to, and in this case, we do. + // This function will return the watch to the first screen (usually a simple clock), + // and it will do it long before the watch enters low energy mode. This ensures we + // won't be on screen, and thus opts us out of getting the EVENT_LOW_ENERGY_UPDATE above. + movement_move_to_face(0); + default: + break; + } + + return true; +} + +void hello_there_face_resign(movement_settings_t *settings, void *context) { + // our watch face, like most watch faces, has nothing special to do when resigning. + // watch faces that enable a peripheral or interact with a sensor may want to turn it off here. + (void) settings; + (void) context; +} diff --git a/movement/watch_faces/demo/hello_there_face.h b/movement/watch_faces/demo/hello_there_face.h new file mode 100644 index 00000000..1140bb20 --- /dev/null +++ b/movement/watch_faces/demo/hello_there_face.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#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); + +#define hello_there_face ((const watch_face_t){ \ + hello_there_face_setup, \ + hello_there_face_activate, \ + hello_there_face_loop, \ + hello_there_face_resign, \ + NULL, \ +}) + +#endif // HELLO_THERE_FACE_H_ diff --git a/movement/watch_faces/demo/lis2dh_logging_face.c b/movement/watch_faces/demo/lis2dh_logging_face.c new file mode 100644 index 00000000..31d1cad7 --- /dev/null +++ b/movement/watch_faces/demo/lis2dh_logging_face.c @@ -0,0 +1,215 @@ +/* + * 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 "lis2dh_logging_face.h" +#include "lis2dh.h" +#include "watch.h" + +// This watch face is just for testing; if we want to build accelerometer support, it will likely have to be part of Movement itself. +// The watch face only logs events when it is on screen and not in low energy mode, so you should set LE mode to Never when using it +// and make it the first watch face in the list (so we come back to it from other modes). +// On an interrupt, it flashes the Signal icon, and displays the axis or axes that were over the threshold. +// The main display contains, from left to right, the number of interrupt events that were detected in each of the last three minutes. +// Pressing the alarm button enters the log mode, where the main display shows the number of interrupts detected in each of the last +// 24 hours (the hour is shown in the top right digit and AM/PM indicator, if the clock is set to 12 hour mode) + +static void _lis2dh_logging_face_update_display(movement_settings_t *settings, lis2dh_logger_state_t *logger_state, lis2dh_interrupt_state interrupt_state) { + char buf[14]; + char time_indication_character; + int8_t pos; + watch_date_time date_time; + + if (logger_state->log_ticks) { + pos = (logger_state->data_points - 1 - logger_state->display_index) % LIS2DH_LOGGING_NUM_DATA_POINTS; + if (pos < 0) { + watch_clear_colon(); + sprintf(buf, "NO data "); + } else { + date_time = logger_state->data[pos].timestamp; + watch_set_colon(); + if (settings->bit.clock_mode_24h) { + watch_set_indicator(WATCH_INDICATOR_24H); + } else { + if (date_time.unit.hour > 11) watch_set_indicator(WATCH_INDICATOR_PM); + date_time.unit.hour %= 12; + if (date_time.unit.hour == 0) date_time.unit.hour = 12; + } + switch (logger_state->axis_index) { + case 0: + sprintf(buf, "3A%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts + logger_state->data[pos].y_interrupts + logger_state->data[pos].z_interrupts); + break; + case 1: + sprintf(buf, "XA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts); + break; + case 2: + sprintf(buf, "YA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].y_interrupts); + break; + case 3: + sprintf(buf, "ZA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].z_interrupts); + break; + } + } + } else { + date_time = watch_rtc_get_date_time(); + watch_clear_colon(); + watch_clear_indicator(WATCH_INDICATOR_PM); + watch_clear_indicator(WATCH_INDICATOR_24H); + if ((59 - date_time.unit.second) < 10) time_indication_character = '0' + (59 - date_time.unit.second); + else time_indication_character = (date_time.unit.second % 2) ? 'i' : '_'; + sprintf(buf, "%c%c%c%c%2d%2d%2d", + (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) ? 'Y' : ' ', + (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) ? 'X' : ' ', + (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) ? 'Z' : ' ', + time_indication_character, + logger_state->interrupts[0], + logger_state->interrupts[1], + logger_state->interrupts[2]); + } + watch_display_string(buf, 0); +} + +static void _lis2dh_logging_face_log_data(lis2dh_logger_state_t *logger_state) { + watch_date_time date_time = watch_rtc_get_date_time(); + // we get this call 15 minutes late; i.e. at 6:15 we're logging events for 6:00. + // so: if we're at the top of the hour, roll the hour back too (7:00 task logs data for 6:45) + if (date_time.unit.minute == 0) date_time.unit.hour = (date_time.unit.hour + 23) % 24; + + // // then roll the minute back. + date_time.unit.minute = (date_time.unit.minute + 45) % 60; + + size_t pos = logger_state->data_points % LIS2DH_LOGGING_NUM_DATA_POINTS; + logger_state->data[pos].timestamp.reg = date_time.reg; + logger_state->data[pos].x_interrupts = logger_state->x_interrupts_this_hour; + logger_state->data[pos].y_interrupts = logger_state->y_interrupts_this_hour; + logger_state->data[pos].z_interrupts = logger_state->z_interrupts_this_hour; + logger_state->data_points++; + logger_state->x_interrupts_this_hour = 0; + logger_state->y_interrupts_this_hour = 0; + logger_state->z_interrupts_this_hour = 0; +} + +void lis2dh_logging_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(lis2dh_logger_state_t)); + memset(*context_ptr, 0, sizeof(lis2dh_logger_state_t)); + gpio_set_pin_direction(A0, GPIO_DIRECTION_OUT); + gpio_set_pin_function(A0, GPIO_PIN_FUNCTION_OFF); + gpio_set_pin_level(A0, true); + watch_enable_i2c(); + lis2dh_begin(); + lis2dh_set_data_rate(LIS2DH_DATA_RATE_10_HZ); + lis2dh_configure_aoi_int1( + LIS2DH_INTERRUPT_CONFIGURATION_OR | + LIS2DH_INTERRUPT_CONFIGURATION_X_HIGH_ENABLE | + LIS2DH_INTERRUPT_CONFIGURATION_Y_HIGH_ENABLE | + LIS2DH_INTERRUPT_CONFIGURATION_Z_HIGH_ENABLE, 96, 0, true); + } +} + +void lis2dh_logging_face_activate(movement_settings_t *settings, void *context) { + lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context; + // force two settings: never enter low energy mode, and always snap back to screen 0. + // this assumes the accelerometer face is first in the watch_faces list. + settings->bit.le_interval = 0; + settings->bit.to_always = true; + + logger_state->display_index = 0; + logger_state->log_ticks = 0; + watch_enable_digital_input(A1); +} + +bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context; + lis2dh_interrupt_state interrupt_state = 0; + + switch (event.event_type) { + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_LONG_PRESS: + movement_illuminate_led(); + break; + case EVENT_LIGHT_BUTTON_DOWN: + logger_state->axis_index = (logger_state->axis_index + 1) % 4; + logger_state->log_ticks = 255; + _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state); + break; + case EVENT_ALARM_BUTTON_UP: + if (logger_state->log_ticks) logger_state->display_index = (logger_state->display_index + 1) % LIS2DH_LOGGING_NUM_DATA_POINTS; + logger_state->log_ticks = 255; + logger_state->axis_index = 0; + _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state); + break; + case EVENT_ACTIVATE: + case EVENT_TICK: + if (logger_state->log_ticks > 0) { + logger_state->log_ticks--; + } else { + logger_state->display_index = 0; + } + if (watch_get_pin_level(A1)) { + watch_set_indicator(WATCH_INDICATOR_SIGNAL); + interrupt_state = lis2dh_get_int1_state(); + logger_state->interrupts[0]++; + if (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) logger_state->x_interrupts_this_hour++; + if (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) logger_state->y_interrupts_this_hour++; + if (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) logger_state->z_interrupts_this_hour++; + } else { + watch_clear_indicator(WATCH_INDICATOR_SIGNAL); + } + _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state); + break; + case EVENT_BACKGROUND_TASK: + _lis2dh_logging_face_log_data(logger_state); + break; + default: + break; + } + + return true; +} + +void lis2dh_logging_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; + watch_disable_digital_input(A1); +} + +bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context) { + (void) settings; + lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context; + watch_date_time date_time = watch_rtc_get_date_time(); + + // this is kind of an abuse of the API, but, let's use the 1 minute tick to shift all our data over. + logger_state->interrupts[2] = logger_state->interrupts[1]; + logger_state->interrupts[1] = logger_state->interrupts[0]; + logger_state->interrupts[0] = 0; + + // and do our logging task every 15 minutes + return (date_time.unit.minute % 15) == 0; +} diff --git a/movement/watch_faces/demo/lis2dh_logging_face.h b/movement/watch_faces/demo/lis2dh_logging_face.h new file mode 100644 index 00000000..49366542 --- /dev/null +++ b/movement/watch_faces/demo/lis2dh_logging_face.h @@ -0,0 +1,66 @@ +/* + * 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. + */ + +#ifndef LIS2DH_LOGGING_FACE_H_ +#define LIS2DH_LOGGING_FACE_H_ + +#include "movement.h" +#include "watch.h" + +#define LIS2DH_LOGGING_NUM_DATA_POINTS (96) + +typedef struct { + watch_date_time timestamp; + uint32_t x_interrupts; + uint32_t y_interrupts; + uint32_t z_interrupts; +} lis2dh_logger_data_point_t; + +typedef struct { + uint8_t display_index; // the index we are displaying on screen + uint8_t axis_index; // the index we are displaying on screen + uint8_t log_ticks; // when the user taps the ALARM button, we enter log mode + int32_t data_points; // the absolute number of data points logged + uint8_t interrupts[3]; // the number of interrupts we have logged in each of the last 3 minutes + uint32_t x_interrupts_this_hour; // the number of interrupts we have logged in the last hour + uint32_t y_interrupts_this_hour; // the number of interrupts we have logged in the last hour + uint32_t z_interrupts_this_hour; // the number of interrupts we have logged in the last hour + lis2dh_logger_data_point_t data[LIS2DH_LOGGING_NUM_DATA_POINTS]; +} lis2dh_logger_state_t; + +void lis2dh_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void lis2dh_logging_face_activate(movement_settings_t *settings, void *context); +bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void lis2dh_logging_face_resign(movement_settings_t *settings, void *context); +bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context); + +#define lis2dh_logging_face ((const watch_face_t){ \ + lis2dh_logging_face_setup, \ + lis2dh_logging_face_activate, \ + lis2dh_logging_face_loop, \ + lis2dh_logging_face_resign, \ + lis2dh_logging_face_wants_background_task, \ +}) + +#endif // LIS2DH_LOGGING_FACE_H_ diff --git a/movement/watch_faces/demo/voltage_face.c b/movement/watch_faces/demo/voltage_face.c new file mode 100644 index 00000000..24346aa3 --- /dev/null +++ b/movement/watch_faces/demo/voltage_face.c @@ -0,0 +1,91 @@ +/* + * 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 "voltage_face.h" +#include "watch.h" + +static void _voltage_face_update_display(void) { + char buf[14]; + float voltage = (float)watch_get_vcc_voltage() / 1000.0; + sprintf(buf, "BA %4.2f V", voltage); + // printf("%s\n", buf); + watch_display_string(buf, 0); +} + +void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { + (void) settings; + (void) watch_face_index; + (void) context_ptr; +} + +void voltage_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; + watch_enable_adc(); + // if we set the reference voltage here, watch_get_vcc_voltage won't do it over and over + watch_set_analog_reference_voltage(ADC_REFERENCE_INTREF); +} + +bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) settings; + (void) context; + watch_date_time date_time; + switch (event.event_type) { + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_BUTTON_DOWN: + movement_illuminate_led(); + break; + case EVENT_ACTIVATE: + _voltage_face_update_display(); + break; + case EVENT_TICK: + date_time = watch_rtc_get_date_time(); + if (date_time.unit.second % 5 == 4) { + watch_set_indicator(WATCH_INDICATOR_SIGNAL); + } else if (date_time.unit.second % 5 == 0) { + _voltage_face_update_display(); + watch_clear_indicator(WATCH_INDICATOR_SIGNAL); + } + break; + case EVENT_LOW_ENERGY_UPDATE: + watch_display_string("BA SLEEP ", 0); + break; + default: + break; + } + + return true; +} + +void voltage_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; + // make sure to restore the default in the end. + watch_set_analog_reference_voltage(ADC_REFERENCE_VCC); + watch_disable_adc(); +} diff --git a/movement/watch_faces/demo/voltage_face.h b/movement/watch_faces/demo/voltage_face.h new file mode 100644 index 00000000..dc5e631b --- /dev/null +++ b/movement/watch_faces/demo/voltage_face.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef VOLTAGE_FACE_H_ +#define VOLTAGE_FACE_H_ + +#include "movement.h" + +void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void voltage_face_activate(movement_settings_t *settings, void *context); +bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void voltage_face_resign(movement_settings_t *settings, void *context); + +#define voltage_face ((const watch_face_t){ \ + voltage_face_setup, \ + voltage_face_activate, \ + voltage_face_loop, \ + voltage_face_resign, \ + NULL, \ +}) + +#endif // VOLTAGE_FACE_H_ |