From 4679a51b4cb6a871d94536ff28dcd188b30832b7 Mon Sep 17 00:00:00 2001 From: Craig McQueen Date: Thu, 16 Jul 2026 18:19:46 +1000 Subject: [PATCH 1/8] Fix comments for bell and signal indicators * `WATCH_INDICATOR_SIGNAL` is for indicating alarm is on. * `WATCH_INDICATOR_BELL` is for indicating hourly chime in on. --- watch-library/shared/watch/watch_slcd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/watch-library/shared/watch/watch_slcd.h b/watch-library/shared/watch/watch_slcd.h index 43a4f849..2afe55dd 100644 --- a/watch-library/shared/watch/watch_slcd.h +++ b/watch-library/shared/watch/watch_slcd.h @@ -48,8 +48,8 @@ /// An enum listing the icons and indicators available on the watch. typedef enum { - WATCH_INDICATOR_SIGNAL = 0, ///< The hourly signal indicator; also useful for indicating that sensors are on. - WATCH_INDICATOR_BELL, ///< The small bell indicating that an alarm is set. + WATCH_INDICATOR_SIGNAL = 0, ///< The signal indicator indicating alarm is set; also useful for indicating that sensors are on. + WATCH_INDICATOR_BELL, ///< The small bell indicating hourly chime is on. WATCH_INDICATOR_PM, ///< The PM indicator, indicating that a time is in the afternoon. WATCH_INDICATOR_24H, ///< The 24H indicator, indicating that the watch is in a 24-hour mode. WATCH_INDICATOR_LAP, ///< The LAP indicator; the F-91W uses this in its stopwatch UI. On custom LCD it's a looped arrow. From 8913758a24a0a75d782f0c3d6d25fbb72c9f5009 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 27 Jul 2026 20:39:30 +0200 Subject: [PATCH 2/8] Fix wrong July day count in deadline_face settings table The local days_in_month table in _increment_date() listed July as having 30 days instead of 31, diverging from the correct table in _days_in_month(). This made July 31 unreachable when incrementing the day field in settings mode. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01PSucp94GA31sshe5AjvSzQ --- watch-faces/complication/deadline_face.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watch-faces/complication/deadline_face.c b/watch-faces/complication/deadline_face.c index ebad0e8b..f1254c7e 100644 --- a/watch-faces/complication/deadline_face.c +++ b/watch-faces/complication/deadline_face.c @@ -227,7 +227,7 @@ static void _correct_time_difference(int16_t *units, watch_date_time_t deadline) /* Increment date in settings mode. Function taken from `set_time_face.c` */ static void _increment_date(deadline_state_t *state, watch_date_time_t date_time) { - const uint8_t days_in_month[12] = { 31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31 }; + const uint8_t days_in_month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; switch (state->current_page) { case 0: From 0b7ea662fee0530272a7557e045a5f7643673744 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 27 Jul 2026 20:40:21 +0200 Subject: [PATCH 3/8] Fix day-increment overflow check in deadline_face settings date_time.unit.day is a 5-bit bitfield (max 31). Incrementing 31 directly in the bitfield wrapped to 0 via truncation before the day > days_in_month bounds check ever ran, so the overflow was never caught. The result decoded as "day 0" of the current month, i.e. the last day of the previous month, silently rolling the displayed date backwards (e.g. Aug 31 -> Jul 31 -> Jun 30). Compute the incremented day in a plain uint8_t local first, compare it against the month length, and only then write the final value into the bitfield. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01PSucp94GA31sshe5AjvSzQ --- watch-faces/complication/deadline_face.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/watch-faces/complication/deadline_face.c b/watch-faces/complication/deadline_face.c index f1254c7e..814701a0 100644 --- a/watch-faces/complication/deadline_face.c +++ b/watch-faces/complication/deadline_face.c @@ -237,17 +237,18 @@ static void _increment_date(deadline_state_t *state, watch_date_time_t date_time case 1: date_time.unit.month = (date_time.unit.month % 12) + 1; break; - case 2: - date_time.unit.day = date_time.unit.day + 1; - + case 2: { /* Check for leap years */ - int8_t days = days_in_month[date_time.unit.month - 1]; + uint8_t days = days_in_month[date_time.unit.month - 1]; if (date_time.unit.month == 2 && _is_leap(date_time.unit.year)) days++; - if (date_time.unit.day > days) - date_time.unit.day = 1; + /* Compute next day outside the 5-bit bitfield so overflow past 31 + * can be compared against `days` before it gets truncated. */ + uint8_t day = date_time.unit.day + 1; + date_time.unit.day = (day > days) ? 1 : day; break; + } case 3: date_time.unit.hour = (date_time.unit.hour + 1) % 24; break; From eacb6de737669fd24cb9d1e66394f2cdbda69f32 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 27 Jul 2026 20:41:36 +0200 Subject: [PATCH 4/8] Deduplicate month-length table in deadline_face _increment_date() kept its own copy of the days-per-month table and leap-year check, duplicating _days_in_month() in the same file. Two sources of truth is how the July day-count typo went unnoticed. Call _days_in_month() directly instead, leaving one table in the file. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01PSucp94GA31sshe5AjvSzQ --- watch-faces/complication/deadline_face.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/watch-faces/complication/deadline_face.c b/watch-faces/complication/deadline_face.c index 814701a0..a7e0aee7 100644 --- a/watch-faces/complication/deadline_face.c +++ b/watch-faces/complication/deadline_face.c @@ -227,8 +227,6 @@ static void _correct_time_difference(int16_t *units, watch_date_time_t deadline) /* Increment date in settings mode. Function taken from `set_time_face.c` */ static void _increment_date(deadline_state_t *state, watch_date_time_t date_time) { - const uint8_t days_in_month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - switch (state->current_page) { case 0: /* Only 10 years covered. Fix this sometime next decade */ @@ -238,10 +236,7 @@ static void _increment_date(deadline_state_t *state, watch_date_time_t date_time date_time.unit.month = (date_time.unit.month % 12) + 1; break; case 2: { - /* Check for leap years */ - uint8_t days = days_in_month[date_time.unit.month - 1]; - if (date_time.unit.month == 2 && _is_leap(date_time.unit.year)) - days++; + int days = _days_in_month(date_time.unit.month, date_time.unit.year); /* Compute next day outside the 5-bit bitfield so overflow past 31 * can be compared against `days` before it gets truncated. */ From c742e92e7f247f7623c150d7613594e981a31094 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 27 Jul 2026 22:11:52 +0200 Subject: [PATCH 5/8] Fix memory leak in lis2dw_monitor_face settings array state->settings was malloc'd in lis2dw_monitor_face_setup() outside the guard that only runs on first allocation of the face's context. setup() is called again every time the watch wakes from deep sleep (movement.c's app_setup() re-runs watch_faces[i].setup() for every face on wake), so each wake cycle allocated a new settings array and abandoned the previous pointer with no matching free. Since NUM_SETTINGS is a compile-time constant, make settings a fixed-size array embedded directly in lis2dw_monitor_state_t instead of a separately malloc'd pointer, so it's allocated exactly once along with the rest of the state and never leaks. --- watch-faces/sensor/lis2dw_monitor_face.c | 4 ---- watch-faces/sensor/lis2dw_monitor_face.h | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/watch-faces/sensor/lis2dw_monitor_face.c b/watch-faces/sensor/lis2dw_monitor_face.c index 8afb7d3e..3934fa59 100644 --- a/watch-faces/sensor/lis2dw_monitor_face.c +++ b/watch-faces/sensor/lis2dw_monitor_face.c @@ -31,9 +31,6 @@ /* Display frequency */ #define DISPLAY_FREQUENCY 8 -/* Settings */ -#define NUM_SETTINGS 7 - static void _settings_title_display(lis2dw_monitor_state_t *state, char *buf1, char *buf2) { char buf[10]; @@ -541,7 +538,6 @@ void lis2dw_monitor_face_setup(uint8_t watch_face_index, void **context_ptr) /* Initialize settings */ uint8_t settings_page = 0; - state->settings = malloc(NUM_SETTINGS * sizeof(lis2dw_settings_t)); state->settings[settings_page].display = _settings_mode_display; state->settings[settings_page].advance = _settings_mode_advance; settings_page++; diff --git a/watch-faces/sensor/lis2dw_monitor_face.h b/watch-faces/sensor/lis2dw_monitor_face.h index 51a98ecf..7dc0da47 100644 --- a/watch-faces/sensor/lis2dw_monitor_face.h +++ b/watch-faces/sensor/lis2dw_monitor_face.h @@ -56,13 +56,16 @@ typedef struct { void (*advance)(void *); } lis2dw_settings_t; +/* Number of settings pages */ +#define NUM_SETTINGS 7 + typedef struct { uint8_t axis:2; /* Axis to display */ lis2dw_reading_t reading; /* Current reading */ lis2dw_monitor_page_t page; /* Displayed page */ lis2dw_device_state_t ds; /* Device state */ uint8_t settings_page:3; /* Subpage in settings */ - lis2dw_settings_t *settings; /* Settings config */ + lis2dw_settings_t settings[NUM_SETTINGS]; /* Settings config */ uint8_t show_title:6; /* Display face title */ } lis2dw_monitor_state_t; From bf25776a668c7d59a8176642d5c7cce3f5b9f549 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 27 Jul 2026 22:12:22 +0200 Subject: [PATCH 6/8] Fix wrong format specifier for axis label _monitor_display() used %C (wide character, expects wint_t) instead of %c (plain char/int) to print the X/Y/Z axis label. Every other single-character display in the codebase uses %c; on the embedded build, without wide-char support in the C library, %C is not a valid conversion for the char actually being passed. --- watch-faces/sensor/lis2dw_monitor_face.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watch-faces/sensor/lis2dw_monitor_face.c b/watch-faces/sensor/lis2dw_monitor_face.c index 3934fa59..7c7d8327 100644 --- a/watch-faces/sensor/lis2dw_monitor_face.c +++ b/watch-faces/sensor/lis2dw_monitor_face.c @@ -384,7 +384,7 @@ static void _monitor_display(lis2dw_monitor_state_t *state) { char buf[10]; - snprintf(buf, sizeof(buf), " %C ", "XYZ"[state->axis]); + snprintf(buf, sizeof(buf), " %c ", "XYZ"[state->axis]); watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, buf, buf); snprintf(buf, sizeof(buf), "%2d", state->axis + 1); From cd18c95779cc39a255ac2720a54c7c4676188551 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 27 Jul 2026 22:33:06 +0200 Subject: [PATCH 7/8] Port of world_clock2 to second movement. Improvements: - The name of the time zone is displayed for a brief movement when cycling through the selected time zones. - The face now comes with pre-selected zones to show-case its functionality: Seattle, New York, UTC, Shanghai, and Tokyo. --- movement_faces.h | 1 + watch-faces.mk | 1 + watch-faces/clock/world_clock2_face.c | 437 ++++++++++++++++++++++++++ watch-faces/clock/world_clock2_face.h | 134 ++++++++ 4 files changed, 573 insertions(+) create mode 100644 watch-faces/clock/world_clock2_face.c create mode 100644 watch-faces/clock/world_clock2_face.h diff --git a/movement_faces.h b/movement_faces.h index 3c2f5b71..64064897 100644 --- a/movement_faces.h +++ b/movement_faces.h @@ -83,4 +83,5 @@ #include "tomato_face.h" #include "solar_time_face.h" #include "tide_face.h" +#include "world_clock2_face.h" // New includes go above this line. diff --git a/watch-faces.mk b/watch-faces.mk index c9e4a4f1..15246456 100644 --- a/watch-faces.mk +++ b/watch-faces.mk @@ -58,4 +58,5 @@ SRCS += \ ./watch-faces/complication/tomato_face.c \ ./watch-faces/clock/solar_time_face.c \ ./watch-faces/complication/tide_face.c \ + ./watch-faces/clock/world_clock2_face.c \ # New watch faces go above this line. diff --git a/watch-faces/clock/world_clock2_face.c b/watch-faces/clock/world_clock2_face.c new file mode 100644 index 00000000..5fe8720b --- /dev/null +++ b/watch-faces/clock/world_clock2_face.c @@ -0,0 +1,437 @@ +/* + * MIT License + * + * Copyright (c) 2023-2025 Konrad Rieck + * 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 +#include +#include "world_clock2_face.h" +#include "watch_utility.h" +#include "watch_common_display.h" +#include "zones.h" + +static bool refresh_face; + +/* Beep types */ +typedef enum { + BEEP_BUTTON, + BEEP_ENABLE, + BEEP_DISABLE +} beep_type_t; + +/* Simple macros for navigation */ +#define FORWARD +1 +#define BACKWARD -1 + +/* Constants */ +#define UTC_ZONE_INDEX 15 +#define NAME_DISPLAY_TIME 2 + +/* Pre-selected zones: Seattle, New York, UTC, Shanghai, Tokyo */ +#define SELECTED_ZONES {3, 8, 15, 32, 36, -1} + +/* Modulo function */ +static inline unsigned int mod(int a, int b) +{ + int r = a % b; + return r < 0 ? r + b : r; +} + +/* Convert watch date time to udatetime (Copied from movement.c) */ +static udatetime_t _movement_convert_date_time_to_udate(watch_date_time_t dt) +{ + /* *INDENT-OFF* */ + return (udatetime_t) { + .date.dayofmonth = dt.unit.day, + .date.dayofweek = dayofweek(UYEAR_FROM_YEAR(dt.unit.year + WATCH_RTC_REFERENCE_YEAR), dt.unit.month, dt.unit.day), + .date.month = dt.unit.month,.date.year = UYEAR_FROM_YEAR(dt.unit.year + WATCH_RTC_REFERENCE_YEAR), + .time.hour = dt.unit.hour, + .time.minute = dt.unit.minute, + .time.second = dt.unit.second + }; + /* *INDENT-ON* */ +} + +/* Find the next selected time zone */ +static inline uint8_t _next_selected_zone(world_clock2_state_t *state, int direction) +{ + uint8_t i = state->current_zone; + while (true) { + i = mod(i + direction, NUM_ZONE_NAMES); + /* Return next selected zone */ + if (state->zones[i].selected) { + return i; + } + /* Could not find a selected zone. Return UTC */ + if (i == state->current_zone) { + return UTC_ZONE_INDEX; + } + } +} + +/* Play beep sound based on type */ +static inline void _beep(beep_type_t beep_type) +{ + if (!movement_button_should_sound()) + return; + + switch (beep_type) { + case BEEP_BUTTON: + watch_buzzer_play_note(BUZZER_NOTE_C7, 50); + break; + + case BEEP_ENABLE: + watch_buzzer_play_note(BUZZER_NOTE_G7, 50); + watch_buzzer_play_note(BUZZER_NOTE_REST, 75); + watch_buzzer_play_note(BUZZER_NOTE_C8, 75); + break; + + case BEEP_DISABLE: + watch_buzzer_play_note(BUZZER_NOTE_C8, 50); + watch_buzzer_play_note(BUZZER_NOTE_REST, 75); + watch_buzzer_play_note(BUZZER_NOTE_G7, 75); + break; + } +} + +/* Display zone abbreviation on top */ +static void _display_zone_abbr(world_clock2_state_t *state, const char *abbr) +{ + char buf[11]; + + if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) { + /* Long abbreviation on custom LCD */ + sprintf(buf, "%-5s", abbr); + watch_display_text_with_fallback(WATCH_POSITION_TOP, buf, buf); + } else { + /* Short abbreviation with zone number on classic LCD */ + sprintf(buf, "%.2s%2d", abbr, state->current_zone); + watch_display_text(WATCH_POSITION_TOP_LEFT, buf); + watch_display_text(WATCH_POSITION_TOP_RIGHT, buf + 2); + } +} + +/* Get abbreviation for current zone */ +static void _get_zone_info(world_clock2_state_t *state, char *abbr, uoffset_t *offset) +{ + uzone_t zone_info; + udatetime_t dt; + char ds; + + watch_date_time_t utc_time = watch_rtc_get_date_time(); + unpack_zone(&zone_defns[state->current_zone], "", &zone_info); + dt = _movement_convert_date_time_to_udate(utc_time); + ds = get_current_offset(&zone_info, &dt, offset); + sprintf(abbr, zone_info.abrev_formatter, ds); +} + +/* Efficient time display taken from world_clock_face.c */ +static void _efficient_time_display(movement_event_t event, watch_date_time_t date_time, + uint32_t previous_date_time, char *buf) +{ + if ((date_time.reg >> 6) == (previous_date_time >> 6) + && event.event_type != EVENT_LOW_ENERGY_UPDATE) { + // everything before seconds is the same, don't waste cycles setting those segments. + watch_display_character_lp_seconds('0' + date_time.unit.second / 10, 8); + watch_display_character_lp_seconds('0' + date_time.unit.second % 10, 9); + } else if ((date_time.reg >> 12) == (previous_date_time >> 12) + && event.event_type != EVENT_LOW_ENERGY_UPDATE) { + // everything before minutes is the same. + sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second); + watch_display_text(WATCH_POSITION_MINUTES, buf); + watch_display_text(WATCH_POSITION_SECONDS, buf + 2); + } else { + // other stuff changed; let's do it all. + if (!movement_clock_mode_24h()) { + // if we are in 12 hour mode, do some cleanup. + if (date_time.unit.hour < 12) { + watch_clear_indicator(WATCH_INDICATOR_PM); + } else { + watch_set_indicator(WATCH_INDICATOR_PM); + } + date_time.unit.hour %= 12; + if (date_time.unit.hour == 0) + date_time.unit.hour = 12; + } + + /* Display colon and 24h indicator */ + watch_set_colon(); + if (movement_clock_mode_24h()) + watch_set_indicator(WATCH_INDICATOR_24H); + + /* Display day and time */ + sprintf(buf, "%02d%02d%02d", date_time.unit.hour, date_time.unit.minute, date_time.unit.second); + watch_display_text(WATCH_POSITION_HOURS, buf + 0); + watch_display_text(WATCH_POSITION_MINUTES, buf + 2); + + if (event.event_type == EVENT_LOW_ENERGY_UPDATE) { + if (!watch_sleep_animation_is_running()) { + watch_display_text(WATCH_POSITION_SECONDS, " "); + watch_start_sleep_animation(500); + watch_start_indicator_blink_if_possible(WATCH_INDICATOR_COLON, 500); + } + } else { + watch_display_text(WATCH_POSITION_SECONDS, buf + 4); + } + } +} + +static void _clock_display(movement_event_t event, world_clock2_state_t *state) +{ + char buf[11], zone_abbr[MAX_ZONE_NAME_LEN + 1], *zone_name; + watch_date_time_t date_time, utc_time; + uint32_t previous_date_time; + int32_t offset; + uoffset_t zone_offset; + + /* Update indicators and reset previous date time */ + if (refresh_face) { + watch_clear_indicator(WATCH_INDICATOR_SIGNAL); + state->previous_date_time = 0xFFFFFFFF; + refresh_face = false; + } + + /* Determine current time at time zone and store date/time */ + utc_time = watch_rtc_get_date_time(); + offset = movement_get_current_timezone_offset_for_zone(state->current_zone); + date_time = watch_utility_date_time_convert_zone(utc_time, 0, offset); + previous_date_time = state->previous_date_time; + state->previous_date_time = date_time.reg; + + if (state->show_zone_name > 0) { + /* Check for first call to display zone name */ + if (state->show_zone_name == NAME_DISPLAY_TIME) { + watch_clear_colon(); + watch_clear_indicator(WATCH_INDICATOR_24H); + watch_clear_indicator(WATCH_INDICATOR_PM); + zone_name = watch_utility_time_zone_name_at_index(state->current_zone); + watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, zone_name, zone_name); + } + state->show_zone_name--; + /* Check for last call to display zone name */ + if (state->show_zone_name == 0) { + refresh_face = true; + } + } else { + _efficient_time_display(event, date_time, previous_date_time, buf); + } + + _get_zone_info(state, zone_abbr, &zone_offset); + _display_zone_abbr(state, zone_abbr); +} + +static void _settings_display(movement_event_t event, world_clock2_state_t *state) +{ + char buf[11], zone_abbr[MAX_ZONE_NAME_LEN + 1], *zone_name; + uoffset_t zone_offset; + + /* Update indicator and colon on refresh */ + if (refresh_face) { + watch_clear_colon(); + watch_clear_indicator(WATCH_INDICATOR_24H); + watch_clear_indicator(WATCH_INDICATOR_PM); + refresh_face = false; + } + + /* Mark selected zone */ + if (state->zones[state->current_zone].selected) + watch_set_indicator(WATCH_INDICATOR_SIGNAL); + else + watch_clear_indicator(WATCH_INDICATOR_SIGNAL); + + /* Display zone abbreviation on top */ + _get_zone_info(state, zone_abbr, &zone_offset); + /* Blink up abbreviation */ + if (event.subsecond % 2) { + sprintf(zone_abbr, "%5s", " "); + } + _display_zone_abbr(state, zone_abbr); + + /* Display zone name or offset on bottom */ + if (state->show_zone_name > 0) { + zone_name = watch_utility_time_zone_name_at_index(state->current_zone); + watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, zone_name, zone_name); + } else { + sprintf(buf, " %3d%02d", zone_offset.hours, zone_offset.minutes); + watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, buf, buf); + } +} + +static bool _clock_loop(movement_event_t event, world_clock2_state_t *state) +{ + switch (event.event_type) { + case EVENT_ACTIVATE: + case EVENT_TICK: + case EVENT_LOW_ENERGY_UPDATE: + _clock_display(event, state); + break; + case EVENT_ALARM_BUTTON_UP: + refresh_face = true; + state->current_zone = _next_selected_zone(state, FORWARD); + state->show_zone_name = NAME_DISPLAY_TIME; + _clock_display(event, state); + break; + case EVENT_LIGHT_BUTTON_DOWN: + /* Do nothing. No light. */ + break; + case EVENT_LIGHT_BUTTON_UP: + refresh_face = true; + state->current_zone = _next_selected_zone(state, BACKWARD); + state->show_zone_name = NAME_DISPLAY_TIME; + _clock_display(event, state); + break; + case EVENT_LIGHT_LONG_PRESS: + /* Switch to settings mode */ + state->current_mode = WORLD_CLOCK2_MODE_SETTINGS; + state->show_zone_name = true; + refresh_face = true; + movement_request_tick_frequency(4); + _settings_display(event, state); + _beep(BEEP_BUTTON); + break; + case EVENT_MODE_BUTTON_UP: + /* Reset frequency and move to next face */ + movement_request_tick_frequency(1); + movement_move_to_next_face(); + break; + default: + return movement_default_loop_handler(event); + } + + return true; +} + +static bool _settings_loop(movement_event_t event, world_clock2_state_t *state) +{ + uint8_t zone; + + switch (event.event_type) { + case EVENT_ACTIVATE: + case EVENT_TICK: + case EVENT_LOW_ENERGY_UPDATE: + _settings_display(event, state); + break; + case EVENT_ALARM_BUTTON_UP: + state->current_zone = mod(state->current_zone + FORWARD, NUM_ZONE_NAMES); + _settings_display(event, state); + break; + case EVENT_LIGHT_BUTTON_UP: + state->current_zone = mod(state->current_zone + BACKWARD, NUM_ZONE_NAMES); + _settings_display(event, state); + break; + case EVENT_LIGHT_BUTTON_DOWN: + /* Do nothing. No light. */ + break; + case EVENT_ALARM_LONG_PRESS: + /* Toggle selection of current zone */ + zone = state->current_zone; + state->zones[zone].selected = !state->zones[zone].selected; + _settings_display(event, state); + if (state->zones[zone].selected) { + _beep(BEEP_ENABLE); + } else { + _beep(BEEP_DISABLE); + } + break; + case EVENT_LIGHT_LONG_PRESS: + state->show_zone_name = !state->show_zone_name; + _settings_display(event, state); + break; + case EVENT_MODE_BUTTON_UP: + /* Find next selected zone */ + if (!state->zones[state->current_zone].selected) + state->current_zone = _next_selected_zone(state, FORWARD); + + /* Switch to display mode */ + state->current_mode = WORLD_CLOCK2_MODE_CLOCK; + state->show_zone_name = NAME_DISPLAY_TIME; + refresh_face = true; + movement_request_tick_frequency(1); + _clock_display(event, state); + _beep(BEEP_BUTTON); + break; + default: + return movement_default_loop_handler(event); + } + + return true; +} + +void world_clock2_face_setup(uint8_t watch_face_index, void **context_ptr) +{ + (void) watch_face_index; + int8_t selected_zones[] = SELECTED_ZONES, *selected_zones_ptr; + + if (*context_ptr == NULL) { + *context_ptr = malloc(sizeof(world_clock2_state_t)); + memset(*context_ptr, 0, sizeof(world_clock2_state_t)); + + /* Start in settings mode */ + world_clock2_state_t *state = (world_clock2_state_t *) * context_ptr; + state->current_mode = WORLD_CLOCK2_MODE_CLOCK; + state->current_zone = UTC_ZONE_INDEX; + state->show_zone_name = NAME_DISPLAY_TIME; + + selected_zones_ptr = selected_zones; + while (*selected_zones_ptr != -1) { + state->zones[*selected_zones_ptr].selected = true; + selected_zones_ptr++; + } + } +} + +void world_clock2_face_activate(void *context) +{ + world_clock2_state_t *state = (world_clock2_state_t *) context; + + switch (state->current_mode) { + case WORLD_CLOCK2_MODE_CLOCK: + /* Normal tick frequency */ + movement_request_tick_frequency(1); + break; + case WORLD_CLOCK2_MODE_SETTINGS: + /* Faster frequency for blinking effect */ + movement_request_tick_frequency(4); + break; + } + + /* Set initial state */ + refresh_face = true; +} + +bool world_clock2_face_loop(movement_event_t event, void *context) +{ + world_clock2_state_t *state = (world_clock2_state_t *) context; + switch (state->current_mode) { + case WORLD_CLOCK2_MODE_CLOCK: + return _clock_loop(event, state); + case WORLD_CLOCK2_MODE_SETTINGS: + return _settings_loop(event, state); + } + return false; +} + +void world_clock2_face_resign(void *context) +{ + (void) context; +} diff --git a/watch-faces/clock/world_clock2_face.h b/watch-faces/clock/world_clock2_face.h new file mode 100644 index 00000000..eedff808 --- /dev/null +++ b/watch-faces/clock/world_clock2_face.h @@ -0,0 +1,134 @@ +/* + * MIT License + * + * Copyright (c) 2023 Konrad Rieck + * 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 WORLD_CLOCK2_FACE_H_ +#define WORLD_CLOCK2_FACE_H_ + +/* + * WORLD CLOCK 2 + * + * This is an alternative world clock face that allows the user to cycle + * through a list of selected time zones. It extends the original + * implementation by Joey Castillo. The face has two modes: clock mode + * and settings mode. + * + * Clock mode + * + * When the clock face is activated for the first time, it enters clock mode. + * The face displays the time of one of multiple selected time zones. It + * includes the following components: + * + * - The top of the face displays the first letters of the time zone + * abbreviation, such as "PS" for Pacific Standard Time on the classic + * display and "PST" on the custom display. + * + * - On the classic display, the upper-right corner additionally shows the + * index number of the time zone. This helps avoid confusion when multiple + * time zones have the same two-letter abbreviation. + * + * - The bottom of the face shows the name of the current zone time, such as + * "Tokyo" or "Berlin" for about a second when activating the face or cycling + * between time zones. + * + * - After displaying the zone name, the face displays the time of the time + * zone. There is no timeout, allowing users to keep the chosen time zone + * displayed for as long as they wish. + * + * The user can navigate through the selected time zones using the following + * buttons: + * + * - The ALARM button moves to the next selected time zone, while the LIGHT + * button moves to the previous zone. + * + * - A long press on the LIGHT button enters settings mode and enables the + * user to re-configure the selected time zones. + * + * Settings mode + * + * In settings mode, the user can select the time zones they want to display + * and cycle through. The face shows a summary of the current time zone: + * + * - The top of the face displays the first letters of the time zone + * abbreviation, such as "PS" for Pacific Standard Time on the classic + * display and "PST" on the custom display. The letters blink. + * + * - On the classic display, the upper-right corner additionally shows the + * index number of the time zone. This helps avoid confusion when multiple + * time zones have the same two-letter abbreviation. + * + * - The bottom display shows either the name of the time zone or its + * offset from UTC. For example, it either shows "Tokyo" or "9:00" + * for Japanese Standard Time. + * + * The user can navigate through the time zones and select them using the + * following buttons: + * + * - The ALARM button moves forward to the next time zone, while the LIGHT + * button moves backward to the previous zone. + * + * - A long press on the ALARM button (de)selects the current time zone, and + * the signal indicator (dis)appears at the top left. + * + * - A long press on the LIGHT button toggles the display of the time zone + * name or offset in the bottom display. + * + * - A press on the MODE button exits settings mode and returns to the + * clock mode. + */ + +#include "movement.h" +#include "zones.h" + +typedef enum { + WORLD_CLOCK2_MODE_CLOCK, + WORLD_CLOCK2_MODE_SETTINGS +} world_clock2_mode_t; + +typedef struct { + bool selected; +} world_clock2_zone_t; + +typedef struct { + world_clock2_zone_t zones[NUM_ZONE_NAMES]; + uint8_t current_zone; + world_clock2_mode_t current_mode; + uint32_t previous_date_time; + uint8_t show_zone_name; +} world_clock2_state_t; + +void world_clock2_face_setup(uint8_t watch_face_index, void **context_ptr); +void world_clock2_face_activate(void *context); +bool world_clock2_face_loop(movement_event_t event, void *context); +void world_clock2_face_resign(void *context); + +#define world_clock2_face ((const watch_face_t){ \ + world_clock2_face_setup, \ + world_clock2_face_activate, \ + world_clock2_face_loop, \ + world_clock2_face_resign, \ + NULL, \ +}) + +#endif /* WORLD_CLOCK2_FACE_H_ */ From 0557684ec13e29a70502c2c29cdd00a1754ec6c9 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 27 Jul 2026 22:34:04 +0200 Subject: [PATCH 8/8] Return to clock mode on inactivity timeout in settings _settings_loop() never handled EVENT_TIMEOUT, so leaving the watch face parked in settings mode (4Hz tick, blinking abbreviation) with no button presses meant it stayed there indefinitely instead of returning to the clock display like every other face's settings mode does on timeout. Factor the existing EVENT_MODE_BUTTON_UP transition logic into _exit_settings_mode() and reuse it for EVENT_TIMEOUT. --- watch-faces/clock/world_clock2_face.c | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/watch-faces/clock/world_clock2_face.c b/watch-faces/clock/world_clock2_face.c index 5fe8720b..7e799eea 100644 --- a/watch-faces/clock/world_clock2_face.c +++ b/watch-faces/clock/world_clock2_face.c @@ -321,6 +321,21 @@ static bool _clock_loop(movement_event_t event, world_clock2_state_t *state) return true; } +/* Leave settings mode and return to the clock display */ +static void _exit_settings_mode(movement_event_t event, world_clock2_state_t *state) +{ + /* Find next selected zone */ + if (!state->zones[state->current_zone].selected) + state->current_zone = _next_selected_zone(state, FORWARD); + + /* Switch to display mode */ + state->current_mode = WORLD_CLOCK2_MODE_CLOCK; + state->show_zone_name = NAME_DISPLAY_TIME; + refresh_face = true; + movement_request_tick_frequency(1); + _clock_display(event, state); +} + static bool _settings_loop(movement_event_t event, world_clock2_state_t *state) { uint8_t zone; @@ -358,18 +373,12 @@ static bool _settings_loop(movement_event_t event, world_clock2_state_t *state) _settings_display(event, state); break; case EVENT_MODE_BUTTON_UP: - /* Find next selected zone */ - if (!state->zones[state->current_zone].selected) - state->current_zone = _next_selected_zone(state, FORWARD); - - /* Switch to display mode */ - state->current_mode = WORLD_CLOCK2_MODE_CLOCK; - state->show_zone_name = NAME_DISPLAY_TIME; - refresh_face = true; - movement_request_tick_frequency(1); - _clock_display(event, state); + _exit_settings_mode(event, state); _beep(BEEP_BUTTON); break; + case EVENT_TIMEOUT: + _exit_settings_mode(event, state); + break; default: return movement_default_loop_handler(event); }