summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoshber <800692+joshber@users.noreply.github.com>2022-07-25 11:57:12 -0400
committerGitHub <noreply@github.com>2022-07-25 11:57:12 -0400
commitf120d66a98cac17fd69169500e148ffbc6eccd69 (patch)
treea567fbe36f25c30edefda112e22fabcfd502a7d8
parentb234db74fe3f70254860715cc4bb828a30290fb2 (diff)
downloadSensor-Watch-f120d66a98cac17fd69169500e148ffbc6eccd69.tar.gz
Sensor-Watch-f120d66a98cac17fd69169500e148ffbc6eccd69.tar.bz2
Sensor-Watch-f120d66a98cac17fd69169500e148ffbc6eccd69.zip
Wake Face (#77)
Co-authored-by: Josh Berson <low.note0488@fastmail.com>
-rw-r--r--movement/alt_fw/focus.h1
-rw-r--r--movement/alt_fw/timers.h43
-rwxr-xr-xmovement/make/Makefile2
-rw-r--r--movement/movement_faces.h2
-rw-r--r--movement/watch_faces/complication/wake_face.c159
-rw-r--r--movement/watch_faces/complication/wake_face.h53
6 files changed, 260 insertions, 0 deletions
diff --git a/movement/alt_fw/focus.h b/movement/alt_fw/focus.h
index 865459e8..ab5525a5 100644
--- a/movement/alt_fw/focus.h
+++ b/movement/alt_fw/focus.h
@@ -32,6 +32,7 @@ const watch_face_t watch_faces[] = {
tomato_face,
stopwatch_face,
countdown_face,
+ wake_face, // added by @joshber 2022-07-23, per @joeycastillo
preferences_face,
set_time_face,
diff --git a/movement/alt_fw/timers.h b/movement/alt_fw/timers.h
new file mode 100644
index 00000000..c4d27f50
--- /dev/null
+++ b/movement/alt_fw/timers.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 MOVEMENT_CONFIG_H_
+#define MOVEMENT_CONFIG_H_
+
+#include "movement_faces.h"
+
+const watch_face_t watch_faces[] = {
+ simple_clock_face,
+ wake_face,
+ interval_face,
+ stopwatch_face,
+ sunrise_sunset_face,
+
+ preferences_face,
+ set_time_face,
+};
+
+#define MOVEMENT_NUM_FACES (sizeof(watch_faces) / sizeof(watch_face_t))
+
+#endif // MOVEMENT_CONFIG_H_
diff --git a/movement/make/Makefile b/movement/make/Makefile
index 7c7cf2d6..22e5f31b 100755
--- a/movement/make/Makefile
+++ b/movement/make/Makefile
@@ -62,6 +62,8 @@ SRCS += \
../watch_faces/complication/astronomy_face.c \
../watch_faces/complication/tomato_face.c \
../watch_faces/complication/probability_face.c \
+ ../watch_faces/complication/wake_face.c \
+# wake_face.c: Josh Berson, 2022-07-04
# 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 7c51b6ff..e18f3683 100644
--- a/movement/movement_faces.h
+++ b/movement/movement_faces.h
@@ -53,6 +53,8 @@
#include "astronomy_face.h"
#include "tomato_face.h"
#include "probability_face.h"
+#include "wake_face.h"
+// #include "interval_face.h"
// New includes go above this line.
#endif // MOVEMENT_FACES_H_
diff --git a/movement/watch_faces/complication/wake_face.c b/movement/watch_faces/complication/wake_face.c
new file mode 100644
index 00000000..4c265c75
--- /dev/null
+++ b/movement/watch_faces/complication/wake_face.c
@@ -0,0 +1,159 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Josh Berson, building on Wesley Ellis’ countdown_face.c
+ *
+ * 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 <threads.h>
+
+#include "wake_face.h"
+#include "watch.h"
+#include "watch_utility.h"
+
+/*
+ UI Notes
+ º Light advances hour by 1
+ º Light long press advances hour by 6
+ º Alarm advances minute by 10
+ º Alarm long press cycles through signal modes (just one at the moment)
+*/
+
+//
+// Private
+//
+
+static
+void _wake_face_update_display(movement_settings_t *settings, wake_face_state_t *state) {
+ (void) settings;
+ uint8_t hour = state->hour;
+
+ watch_clear_display();
+ if ( settings->bit.clock_mode_24h )
+ watch_set_indicator(WATCH_INDICATOR_24H);
+ else {
+ if ( hour >= 12 )
+ watch_set_indicator(WATCH_INDICATOR_PM);
+ hour = hour % 12 ? hour % 12 : 12;
+ }
+
+ if ( state->mode )
+ watch_set_indicator(WATCH_INDICATOR_BELL);
+
+ static char lcdbuf[11];
+ sprintf(lcdbuf, "WA %2d%02d ", hour, state->minute);
+
+ watch_set_colon();
+ watch_display_string(lcdbuf, 0);
+}
+
+//
+// Exported
+//
+
+void wake_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(wake_face_state_t));
+ wake_face_state_t *state = (wake_face_state_t *)*context_ptr;
+ memset(*context_ptr, 0, sizeof(wake_face_state_t));
+
+ state->hour = 5;
+ state->minute = 0;
+ state->mode = 0;
+ }
+}
+
+void wake_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+void wake_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
+bool wake_face_wants_background_task(movement_settings_t *settings, void *context) {
+ (void) settings;
+ wake_face_state_t *state = (wake_face_state_t *)context;
+
+ bool rc = false;
+ if ( state->mode ) {
+ watch_date_time now = watch_rtc_get_date_time();
+ rc = state->hour==now.unit.hour && state->minute==now.unit.minute;
+ // We’re at the mercy of the wants_background_task handler
+ // In Safari, the emulator triggers at the ›end‹ of the minute
+ // Converting to Unix timestamps and taking a difference between now and wake
+ // is not an easy win — because the timestamp for wake has to rely on now
+ // for its date. So first we’d have to see if the TOD of wake is after that
+ // of now. If it is, take tomorrow’s date, calculating month and year rollover
+ // if need be.
+ }
+ return rc;
+}
+
+bool wake_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ (void) settings;
+ wake_face_state_t *state = (wake_face_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ case EVENT_TICK:
+ _wake_face_update_display(settings, state);
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ state->hour = (state->hour + 1) % 24;
+ _wake_face_update_display(settings, state);
+ break;
+ case EVENT_LIGHT_LONG_PRESS:
+ state->hour = (state->hour + 6) % 24;
+ _wake_face_update_display(settings, state);
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ state->minute = (state->minute + 10) % 60;
+ _wake_face_update_display(settings, state);
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ state->mode ^= 1;
+ _wake_face_update_display(settings, state);
+ break;
+ case EVENT_BACKGROUND_TASK:
+ movement_play_alarm();
+ // 2022-07-23: Thx @joeycastillo for the dedicated “alarm” signal
+ break;
+ case EVENT_MODE_BUTTON_UP:
+ movement_move_to_next_face();
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ case EVENT_LOW_ENERGY_UPDATE:
+ default:
+ break;
+ }
+
+ return true;
+} \ No newline at end of file
diff --git a/movement/watch_faces/complication/wake_face.h b/movement/watch_faces/complication/wake_face.h
new file mode 100644
index 00000000..c091c8f3
--- /dev/null
+++ b/movement/watch_faces/complication/wake_face.h
@@ -0,0 +1,53 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Josh Berson
+ *
+ * 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 WAKE_FACE_H_
+#define WAKE_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+ uint32_t hour : 5;
+ uint32_t minute : 6;
+ uint32_t mode : 1;
+} wake_face_state_t;
+
+void wake_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void **context_ptr);
+void wake_face_activate(movement_settings_t *settings, void *context);
+bool wake_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void wake_face_resign(movement_settings_t *settings, void *context);
+bool wake_face_wants_background_task(movement_settings_t *settings, void *context);
+
+#define wake_face ((const watch_face_t){ \
+ wake_face_setup, \
+ wake_face_activate, \
+ wake_face_loop, \
+ wake_face_resign, \
+ wake_face_wants_background_task \
+})
+
+#endif // WAKE_FACE_H_
+