summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Aptekar-Cassels <me@wesleyac.com>2024-01-21 02:03:41 -0500
committerGitHub <noreply@github.com>2024-01-21 02:03:41 -0500
commit332728b51194adb9ae72a845ff230fc62da74e08 (patch)
tree888997f4d133e3fee2afb21e633ea5e44724b230
parent233036ff59f59080967f38682dc595a80ec7bb19 (diff)
parentf16ce6a7670c8e26d46623fdbf928d4d8aa2c1fb (diff)
downloadSensor-Watch-332728b51194adb9ae72a845ff230fc62da74e08.tar.gz
Sensor-Watch-332728b51194adb9ae72a845ff230fc62da74e08.tar.bz2
Sensor-Watch-332728b51194adb9ae72a845ff230fc62da74e08.zip
Merge pull request #318 from WesleyAC/watch-face-simple-coin-flip
Add simple_coin_flip_face
-rw-r--r--movement/make/Makefile1
-rw-r--r--movement/movement_faces.h1
-rw-r--r--movement/watch_faces/complication/simple_coin_flip_face.c139
-rw-r--r--movement/watch_faces/complication/simple_coin_flip_face.h62
4 files changed, 203 insertions, 0 deletions
diff --git a/movement/make/Makefile b/movement/make/Makefile
index df11a9ab..82bae622 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/complication/simple_coin_flip_face.c \
../watch_faces/complication/solstice_face.c \
../watch_faces/complication/couch_to_5k_face.c \
../watch_faces/clock/minute_repeater_decimal_face.c \
diff --git a/movement/movement_faces.h b/movement/movement_faces.h
index a3ccc130..d232f0a7 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 "simple_coin_flip_face.h"
#include "solstice_face.h"
#include "couch_to_5k_face.h"
#include "minute_repeater_decimal_face.h"
diff --git a/movement/watch_faces/complication/simple_coin_flip_face.c b/movement/watch_faces/complication/simple_coin_flip_face.c
new file mode 100644
index 00000000..64431f9d
--- /dev/null
+++ b/movement/watch_faces/complication/simple_coin_flip_face.c
@@ -0,0 +1,139 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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.
+ */
+
+#if __EMSCRIPTEN__
+#include <time.h>
+#else
+#include "saml22j18a.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "simple_coin_flip_face.h"
+
+#define SIMPLE_COIN_FLIP_REQUIRE_LONG_PRESS_FOR_REFLIP true
+
+void simple_coin_flip_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(simple_coin_flip_state_t));
+ memset(*context_ptr, 0, sizeof(simple_coin_flip_state_t));
+ }
+}
+
+void simple_coin_flip_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
+static uint32_t get_random(uint32_t max) {
+ #if __EMSCRIPTEN__
+ return rand() % max;
+ #else
+ return arc4random_uniform(max);
+ #endif
+}
+
+static void animation_0() {
+ watch_display_string(" ", 8);
+ watch_set_pixel(0, 3);
+ watch_set_pixel(0, 6);
+}
+
+static void animation_1() {
+ watch_display_string(" ", 8);
+ watch_set_pixel(1, 3);
+ watch_set_pixel(1, 5);
+}
+
+static void animation_2() {
+ watch_display_string(" ", 8);
+ watch_set_pixel(2, 2);
+ watch_set_pixel(2, 4);
+}
+
+bool simple_coin_flip_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ simple_coin_flip_state_t *state = (simple_coin_flip_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ watch_display_string("flip", 5);
+ state->animation_frame = 0;
+ break;
+ case EVENT_TICK:
+ switch (state->animation_frame) {
+ case 0:
+ case 7:
+ return true;
+ case 1:
+ movement_request_tick_frequency(8);
+ watch_display_string(" ", 4);
+ // fallthrough
+ case 5:
+ animation_0();
+ break;
+ case 2:
+ case 4:
+ animation_1();
+ break;
+ case 3:
+ animation_2();
+ break;
+ case 6:
+ movement_request_tick_frequency(1);
+ if (get_random(2)) {
+ watch_display_string("Heads ", 4);
+ } else {
+ watch_display_string(" Tails", 4);
+ }
+ break;
+ }
+ state->animation_frame++;
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ case EVENT_ALARM_BUTTON_UP:
+ if (!SIMPLE_COIN_FLIP_REQUIRE_LONG_PRESS_FOR_REFLIP || state->animation_frame == 0) {
+ state->animation_frame = 1;
+ }
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ case EVENT_LIGHT_LONG_PRESS:
+ state->animation_frame = 1;
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ default:
+ return movement_default_loop_handler(event, settings);
+ }
+
+ return true;
+}
+
+void simple_coin_flip_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
diff --git a/movement/watch_faces/complication/simple_coin_flip_face.h b/movement/watch_faces/complication/simple_coin_flip_face.h
new file mode 100644
index 00000000..f5e223b8
--- /dev/null
+++ b/movement/watch_faces/complication/simple_coin_flip_face.h
@@ -0,0 +1,62 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 SIMPLE_COIN_FLIP_FACE_H_
+#define SIMPLE_COIN_FLIP_FACE_H_
+
+#include "movement.h"
+
+/*
+ * A extremely simple coin flip face.
+ *
+ * Press ALARM or LIGHT to flip a coin, after a short animation it will display
+ * "Heads" or "Tails". Long-press to flip again (you can change a #define to
+ * allow a short-press to reflip as well, if you'd like).
+ *
+ * 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 {
+ uint8_t animation_frame;
+} simple_coin_flip_state_t;
+
+void simple_coin_flip_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void simple_coin_flip_face_activate(movement_settings_t *settings, void *context);
+bool simple_coin_flip_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void simple_coin_flip_face_resign(movement_settings_t *settings, 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, \
+})
+
+#endif // SIMPLE_COIN_FLIP_FACE_H_
+