From 57e9f11a0c898e6d174d71e33f1b32efb904eb2b Mon Sep 17 00:00:00 2001 From: Dennisman219 Date: Wed, 27 Sep 2023 22:14:19 +0200 Subject: [PATCH] Minimal clock face --- movement/make/Makefile | 1 + movement/movement_faces.h | 1 + .../watch_faces/clock/minimal_clock_face.c | 115 ++++++++++++++++++ .../watch_faces/clock/minimal_clock_face.h | 56 +++++++++ 4 files changed, 173 insertions(+) create mode 100644 movement/watch_faces/clock/minimal_clock_face.c create mode 100644 movement/watch_faces/clock/minimal_clock_face.h diff --git a/movement/make/Makefile b/movement/make/Makefile index 625c772..56c21a6 100644 --- a/movement/make/Makefile +++ b/movement/make/Makefile @@ -118,6 +118,7 @@ SRCS += \ ../watch_faces/complication/flashlight_face.c \ ../watch_faces/clock/decimal_time_face.c \ ../watch_faces/clock/wyoscan_face.c \ + ../watch_faces/clock/minimal_clock_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_faces.h b/movement/movement_faces.h index ff34c06..92b82fb 100644 --- a/movement/movement_faces.h +++ b/movement/movement_faces.h @@ -95,6 +95,7 @@ #include "flashlight_face.h" #include "decimal_time_face.h" #include "wyoscan_face.h" +#include "minimal_clock_face.h" // New includes go above this line. #endif // MOVEMENT_FACES_H_ diff --git a/movement/watch_faces/clock/minimal_clock_face.c b/movement/watch_faces/clock/minimal_clock_face.c new file mode 100644 index 0000000..195a3ee --- /dev/null +++ b/movement/watch_faces/clock/minimal_clock_face.c @@ -0,0 +1,115 @@ +/* + * MIT License + * + * Copyright (c) 2023 Dennisman219 + * + * 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 +#include +#include "minimal_clock_face.h" + +static void _minimal_clock_face_update_display(movement_settings_t *settings) { + watch_date_time date_time = watch_rtc_get_date_time(); + char buffer[11]; + + if (!settings->bit.clock_mode_24h) { + date_time.unit.hour %= 12; + } + + sprintf(buffer, "%2d%02d ", date_time.unit.hour, date_time.unit.minute); + watch_display_string(buffer, 4); +} + +void minimal_clock_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(minimal_clock_state_t)); + memset(*context_ptr, 0, sizeof(minimal_clock_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 minimal_clock_face_activate(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; + // Handle any tasks related to your watch face coming on screen. + watch_set_colon(); +} + +bool minimal_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + (void) context; + + switch (event.event_type) { + case EVENT_ACTIVATE: + // Show your initial UI here. + _minimal_clock_face_update_display(settings); + break; + case EVENT_TICK: + // If needed, update your display here. + _minimal_clock_face_update_display(settings); + break; + case EVENT_LIGHT_BUTTON_UP: + // You can use the Light button for your own purposes. Note that by default, Movement will also + // illuminate the LED in response to EVENT_LIGHT_BUTTON_DOWN; to suppress that behavior, add an + // empty case for EVENT_LIGHT_BUTTON_DOWN. + 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); + _minimal_clock_face_update_display(settings); + break; + default: + // Movement's default loop handler will step in for any cases you don't handle above: + // * EVENT_LIGHT_BUTTON_DOWN lights the LED + // * EVENT_MODE_BUTTON_UP moves to the next watch face in the list + // * EVENT_MODE_LONG_PRESS returns to the first watch face (or skips to the secondary watch face, if configured) + // You can override any of these behaviors by adding a case for these events to this switch statement. + return movement_default_loop_handler(event, settings); + } + + // return true if the watch can enter standby mode. Generally speaking, you should always return true. + // Exceptions: + // * If you are displaying a color using the low-level watch_set_led_color function, you should return false. + // * If you are sounding the buzzer using the low-level watch_set_buzzer_on function, you should return false. + // Note that if you are driving the LED or buzzer using Movement functions like movement_illuminate_led or + // movement_play_alarm, you can still return true. This guidance only applies to the low-level watch_ functions. + return true; +} + +void minimal_clock_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/watch_faces/clock/minimal_clock_face.h b/movement/watch_faces/clock/minimal_clock_face.h new file mode 100644 index 0000000..1978689 --- /dev/null +++ b/movement/watch_faces/clock/minimal_clock_face.h @@ -0,0 +1,56 @@ +/* + * MIT License + * + * Copyright (c) 2023 Dennisman219 + * + * 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 MINIMAL_CLOCK_FACE_H_ +#define MINIMAL_CLOCK_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; +} minimal_clock_state_t; + +void minimal_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void minimal_clock_face_activate(movement_settings_t *settings, void *context); +bool minimal_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void minimal_clock_face_resign(movement_settings_t *settings, void *context); + +#define minimal_clock_face ((const watch_face_t){ \ + minimal_clock_face_setup, \ + minimal_clock_face_activate, \ + minimal_clock_face_loop, \ + minimal_clock_face_resign, \ + NULL, \ +}) + +#endif // MINIMAL_CLOCK_FACE_H_ +