From 01b7f30cefd43bccb66e3f27c878dd671546e613 Mon Sep 17 00:00:00 2001 From: Vaipex <86567086+Vaipex@users.noreply.github.com> Date: Sun, 3 Aug 2025 17:16:34 +0000 Subject: [PATCH] Added simple coin flip watch face (#63) --- movement_faces.h | 1 + watch-faces.mk | 1 + .../complication/simple_coin_flip_face.c | 178 ++++++++++++++++++ .../complication/simple_coin_flip_face.h | 60 ++++++ 4 files changed, 240 insertions(+) create mode 100644 watch-faces/complication/simple_coin_flip_face.c create mode 100644 watch-faces/complication/simple_coin_flip_face.h diff --git a/movement_faces.h b/movement_faces.h index ca270cc3..ded8e789 100644 --- a/movement_faces.h +++ b/movement_faces.h @@ -63,6 +63,7 @@ #include "tally_face.h" #include "probability_face.h" #include "ke_decimal_time_face.h" +#include "simple_coin_flip_face.h" #include "lis2dw_monitor_face.h" #include "wareki_face.h" #include "deadline_face.h" diff --git a/watch-faces.mk b/watch-faces.mk index 91a0d9e9..6b326424 100644 --- a/watch-faces.mk +++ b/watch-faces.mk @@ -38,6 +38,7 @@ SRCS += \ ./watch-faces/complication/kitchen_conversions_face.c \ ./watch-faces/complication/periodic_table_face.c \ ./watch-faces/clock/ke_decimal_time_face.c \ + ./watch-faces/complication/simple_coin_flip_face.c \ ./watch-faces/sensor/lis2dw_monitor_face.c \ ./watch-faces/complication/wareki_face.c \ ./watch-faces/complication/deadline_face.c \ diff --git a/watch-faces/complication/simple_coin_flip_face.c b/watch-faces/complication/simple_coin_flip_face.c new file mode 100644 index 00000000..446832be --- /dev/null +++ b/watch-faces/complication/simple_coin_flip_face.c @@ -0,0 +1,178 @@ +/* + * MIT License + * + * Copyright (c) 2023 Wesley Aptekar-Cassels + * Copyright (c) 2025 Vaipex + * + * 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 "simple_coin_flip_face.h" + +void simple_coin_flip_face_setup(uint8_t watch_face_index, void ** context_ptr) { + (void) watch_face_index; + if (*context_ptr == NULL) { + *context_ptr = malloc(sizeof(simple_coin_flip_face_state_t)); + memset(*context_ptr, 0, sizeof(simple_coin_flip_face_state_t)); + } +} + +void simple_coin_flip_face_activate(void *context) { + simple_coin_flip_face_state_t *state = (simple_coin_flip_face_state_t *)context; +} + +static uint32_t get_random(uint32_t max) { + #if __EMSCRIPTEN__ + return rand() % max; + #else + return arc4random_uniform(max); + #endif + +} + +void draw_start_face() { + watch_clear_display(); + if (watch_get_lcd_type() == WATCH_LCD_TYPE_CLASSIC) { + watch_display_text(WATCH_POSITION_BOTTOM, " Flip"); + } else { + watch_display_text(WATCH_POSITION_BOTTOM, "Flip"); + } +} + +void set_pixels(int pixels[3][4][2], int j_len) { + for(int loopruns = 0; loopruns<2; loopruns++) { + for(int i = 0; i<3; i++) { + watch_clear_display(); + for(int j = 0; jis_start_face && !state->active){ + if(state->inactivity_ticks >= 15){ + state->is_start_face = false; + state->inactivity_ticks = 0; + draw_start_face(); + }else{ + state->inactivity_ticks++; + } + } else { + state->inactivity_ticks = 0; + } + break; + //execute same action for light and alarm button + case EVENT_LIGHT_BUTTON_UP: + case EVENT_ALARM_BUTTON_UP: + if (!state->active) { + state->active = true; + _blink_face_update_lcd(state); + state->active = false; + state->is_start_face = false; + state->inactivity_ticks = 0; + } + break; + case EVENT_TIMEOUT: + movement_move_to_face(0); + break; + case EVENT_LOW_ENERGY_UPDATE: + break; + default: + return movement_default_loop_handler(event); + } + + return true; +} + +void simple_coin_flip_face_resign(void *context) { + (void) context; +} + diff --git a/watch-faces/complication/simple_coin_flip_face.h b/watch-faces/complication/simple_coin_flip_face.h new file mode 100644 index 00000000..f5c95a4b --- /dev/null +++ b/watch-faces/complication/simple_coin_flip_face.h @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2023 Wesley Aptekar-Cassels + * Copyright (c) 2025 Vaipex + * + * 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" + +/* + * A extremely simple coin flip face updated from Wesley Aptekar-Cassels version. + * + * Press ALARM or LIGHT to flip a coin, after a short animation it will display + * "Heads" or "Tails". Press ALARM or LIGHT to flip again. + * + * This is for people who want a simpler UI than probability_face or + * randonaut_face. While those have more features, this one is more immediately + * obvious - useful, for instance, if you are using a coin flip to agree on + * something with someone, and want the operation to be clear to someone who + * has not had anything explained to them. + */ + +typedef struct { + bool active; + bool is_start_face; + uint8_t inactivity_ticks; +} simple_coin_flip_face_state_t; + +void simple_coin_flip_face_setup(uint8_t watch_face_index, void ** context_ptr); +void simple_coin_flip_face_activate(void *context); +bool simple_coin_flip_face_loop(movement_event_t event, void *context); +void simple_coin_flip_face_resign(void *context); + +#define simple_coin_flip_face ((const watch_face_t){ \ + simple_coin_flip_face_setup, \ + simple_coin_flip_face_activate, \ + simple_coin_flip_face_loop, \ + simple_coin_flip_face_resign, \ + NULL, \ +})