From a7c0fb7dfddf3f318d54f8a1f0c690a43586134a Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 20 Jul 2024 14:35:37 -0400 Subject: [PATCH 1/4] Added ability to add presets to the sunrise and sunset face --- .../complication/sunrise_sunset_face.c | 34 ++++++++++++++++--- .../complication/sunrise_sunset_face.h | 15 ++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 7330c42..7eeb512 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -37,6 +37,8 @@ #include #endif +static const uint8_t _location_count = sizeof(longLatPresets) / sizeof(long_lat_presets_t); + static void _sunrise_sunset_set_expiration(sunrise_sunset_state_t *state, watch_date_time next_rise_set) { uint32_t timestamp = watch_utility_date_time_to_unix_time(next_rise_set, 0); state->rise_set_expires = watch_utility_date_time_from_unix_time(timestamp + 60, 0); @@ -46,7 +48,13 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s char buf[14]; double rise, set, minutes, seconds; bool show_next_match = false; - movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); + movement_location_t movement_location; + if (state->longLatToUse == 0) + movement_location = (movement_location_t) watch_get_backup_data(1); + else{ + movement_location.bit.latitude = longLatPresets[state->longLatToUse].latitude; + movement_location.bit.longitude = longLatPresets[state->longLatToUse].longitude; + } if (movement_location.reg == 0) { watch_display_string("RI no Loc", 0); @@ -109,7 +117,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM); else watch_clear_indicator(WATCH_INDICATOR_PM); } - sprintf(buf, "rI%2d%2d%02d ", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute); + sprintf(buf, "rI%2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); watch_display_string(buf, 0); return; } else { @@ -136,7 +144,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM); else watch_clear_indicator(WATCH_INDICATOR_PM); } - sprintf(buf, "SE%2d%2d%02d ", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute); + sprintf(buf, "SE%2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, longLatPresets[state->longLatToUse].name); watch_display_string(buf, 0); return; } else { @@ -351,7 +359,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti _sunrise_sunset_face_update_location_register(state); } _sunrise_sunset_face_update_settings_display(event, context); - } else { + } else if (_location_count == 1) { movement_illuminate_led(); } if (state->page == 0) { @@ -359,6 +367,16 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti _sunrise_sunset_face_update(settings, state); } break; + case EVENT_LIGHT_LONG_PRESS: + if (_location_count == 1) break; + else if (!state->page) movement_illuminate_led(); + break; + case EVENT_LIGHT_BUTTON_UP: + if (state->page == 0) { + state->longLatToUse = (state->longLatToUse + 1) % _location_count; + _sunrise_sunset_face_update(settings, state); + } + break; case EVENT_ALARM_BUTTON_UP: if (state->page) { _sunrise_sunset_face_advance_digit(state); @@ -369,13 +387,19 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti } break; case EVENT_ALARM_LONG_PRESS: - if (state->page == 0) { + if (state->page == 0 && state->longLatToUse == 0) { state->page++; state->active_digit = 0; watch_clear_display(); movement_request_tick_frequency(4); _sunrise_sunset_face_update_settings_display(event, context); } + else{ + state->active_digit = 0; + state->page = 0; + _sunrise_sunset_face_update_location_register(state); + _sunrise_sunset_face_update(settings, state); + } break; case EVENT_TIMEOUT: if (watch_get_backup_data(1) == 0) { diff --git a/movement/watch_faces/complication/sunrise_sunset_face.h b/movement/watch_faces/complication/sunrise_sunset_face.h index 16e65b7..2265724 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.h +++ b/movement/watch_faces/complication/sunrise_sunset_face.h @@ -53,6 +53,7 @@ typedef struct { uint8_t active_digit; bool location_changed; watch_date_time rise_set_expires; + uint8_t longLatToUse; sunrise_sunset_lat_lon_settings_t working_latitude; sunrise_sunset_lat_lon_settings_t working_longitude; } sunrise_sunset_state_t; @@ -70,4 +71,18 @@ void sunrise_sunset_face_resign(movement_settings_t *settings, void *context); NULL, \ }) +typedef struct { + char name[2]; + int16_t latitude; + int16_t longitude; +} long_lat_presets_t; + +static const long_lat_presets_t longLatPresets[] = +{ + { .name = " "}, // Default, the long and lat get replaced by what's set in the watch +// { .name = "Ny", .latitude = 4072, .longitude = -7401 }, // New York City, NY +// { .name = "LA", .latitude = 3405, .longitude = -11824 }, // New York City, NY +// { .name = "dE", .latitude = 4221, .longitude = -8305 }, // Detroit, MI +}; + #endif // SUNRISE_SUNSET_FACE_H_ From a3d23ab45eba5aeddb6b882258f76256dac9b6a4 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 20 Jul 2024 14:46:42 -0400 Subject: [PATCH 2/4] Long press of Alarm goes back to default --- movement/watch_faces/complication/sunrise_sunset_face.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 7eeb512..99a8c1e 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -372,7 +372,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti else if (!state->page) movement_illuminate_led(); break; case EVENT_LIGHT_BUTTON_UP: - if (state->page == 0) { + if (state->page == 0 && _location_count > 1) { state->longLatToUse = (state->longLatToUse + 1) % _location_count; _sunrise_sunset_face_update(settings, state); } @@ -387,7 +387,12 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti } break; case EVENT_ALARM_LONG_PRESS: - if (state->page == 0 && state->longLatToUse == 0) { + if (state->page == 0) { + if (state->longLatToUse != 0) { + state->longLatToUse = 0; + _sunrise_sunset_face_update(settings, state); + break; + } state->page++; state->active_digit = 0; watch_clear_display(); From 9ee319c888ce2abbea3292a6236f47ed6e8b398a Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 20 Jul 2024 14:48:32 -0400 Subject: [PATCH 3/4] Typo in comment --- movement/watch_faces/complication/sunrise_sunset_face.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/movement/watch_faces/complication/sunrise_sunset_face.h b/movement/watch_faces/complication/sunrise_sunset_face.h index 2265724..6474f0f 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.h +++ b/movement/watch_faces/complication/sunrise_sunset_face.h @@ -81,7 +81,7 @@ static const long_lat_presets_t longLatPresets[] = { { .name = " "}, // Default, the long and lat get replaced by what's set in the watch // { .name = "Ny", .latitude = 4072, .longitude = -7401 }, // New York City, NY -// { .name = "LA", .latitude = 3405, .longitude = -11824 }, // New York City, NY +// { .name = "LA", .latitude = 3405, .longitude = -11824 }, // Los Angeles, CA // { .name = "dE", .latitude = 4221, .longitude = -8305 }, // Detroit, MI }; From a13c8c35b84ae8555fbbd4268437a6f9c59d4207 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 20 Jul 2024 15:59:42 -0400 Subject: [PATCH 4/4] Code review commit --- movement/watch_faces/complication/sunrise_sunset_face.c | 2 +- movement/watch_faces/complication/sunrise_sunset_face.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 99a8c1e..ad2f533 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -399,7 +399,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti movement_request_tick_frequency(4); _sunrise_sunset_face_update_settings_display(event, context); } - else{ + else { state->active_digit = 0; state->page = 0; _sunrise_sunset_face_update_location_register(state); diff --git a/movement/watch_faces/complication/sunrise_sunset_face.h b/movement/watch_faces/complication/sunrise_sunset_face.h index 6474f0f..df5fda5 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.h +++ b/movement/watch_faces/complication/sunrise_sunset_face.h @@ -53,9 +53,9 @@ typedef struct { uint8_t active_digit; bool location_changed; watch_date_time rise_set_expires; - uint8_t longLatToUse; sunrise_sunset_lat_lon_settings_t working_latitude; sunrise_sunset_lat_lon_settings_t working_longitude; + uint8_t longLatToUse; } sunrise_sunset_state_t; void sunrise_sunset_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);