From d5d00bce791946e8cab55ddf3627895562d4c37e Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Mon, 27 May 2024 09:25:55 -0400 Subject: [PATCH 1/9] Added times where chiming does not occur --- movement/movement.c | 18 +++++ movement/movement.h | 21 +++++- movement/movement_config.h | 25 +++++++ .../watch_faces/clock/simple_clock_face.c | 4 + .../watch_faces/settings/preferences_face.c | 73 +++++++++++++++++-- 5 files changed, 133 insertions(+), 8 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index 0f7be1933..e41d0932c 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -105,6 +105,21 @@ of debounce time. #define MOVEMENT_DEFAULT_LED_DURATION 1 #endif +// Default to not always chiming every hour +#ifndef MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS +#define MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS 0 +#endif + +// Default to beginning a chime at 7am +#ifndef MOVEMENT_DEFAULT_HOURLY_CHIME_START +#define MOVEMENT_DEFAULT_HOURLY_CHIME_START 1 +#endif + +// Default to beginning a chime at 9pm +#ifndef MOVEMENT_DEFAULT_HOURLY_CHIME_END +#define MOVEMENT_DEFAULT_HOURLY_CHIME_END 1 +#endif + // Default to no set location latitude #ifndef MOVEMENT_DEFAULT_LATITUDE #define MOVEMENT_DEFAULT_LATITUDE 0 @@ -430,6 +445,9 @@ void app_init(void) { movement_state.settings.bit.to_interval = MOVEMENT_DEFAULT_TIMEOUT_INTERVAL; movement_state.settings.bit.le_interval = MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL; movement_state.settings.bit.led_duration = MOVEMENT_DEFAULT_LED_DURATION; + movement_state.settings.bit.hourly_chime_always = MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS; + movement_state.settings.bit.hourly_chime_start = MOVEMENT_DEFAULT_HOURLY_CHIME_START; + movement_state.settings.bit.hourly_chime_end = MOVEMENT_DEFAULT_HOURLY_CHIME_END; movement_state.location.bit.latitude = MOVEMENT_DEFAULT_LATITUDE; movement_state.location.bit.longitude = MOVEMENT_DEFAULT_LONGITUDE; movement_state.birthdate.bit.year = MOVEMENT_DEFAULT_BIRTHDATE_YEAR; diff --git a/movement/movement.h b/movement/movement.h index 57067e9d3..f2b421b37 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -62,7 +62,10 @@ typedef union { bool clock_mode_24h : 1; // indicates whether clock should use 12 or 24 hour mode. bool use_imperial_units : 1; // indicates whether to use metric units (the default) or imperial. bool alarm_enabled : 1; // indicates whether there is at least one alarm enabled. - uint8_t reserved : 6; // room for more preferences if needed. + bool hourly_chime_always : 1; // if true, then ignore the + uint8_t hourly_chime_start : 2; // 0: 6am; 1: 7am; 2: 10am; 3: 12pm; + uint8_t hourly_chime_end : 2; // 0: 8pm; 1: 9pm; 2: 10pm; 3: 12am; + bool reserved : 1; // room for more preferences if needed. } bit; uint32_t reg; } movement_settings_t; @@ -318,4 +321,20 @@ void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note); uint8_t movement_claim_backup_register(void); +static const uint8_t Hourly_Chime_Start[] = +{ + 6, // 6am + 7, // 7am + 10, // 10am + 12 // 12pm +}; + +static const uint8_t Hourly_Chime_End[] = +{ + 20, // 8pm + 21, // 9pm + 22, // 10pm + 00 // 12am +}; + #endif // MOVEMENT_H_ diff --git a/movement/movement_config.h b/movement/movement_config.h index abceacf1c..53ab67b82 100644 --- a/movement/movement_config.h +++ b/movement/movement_config.h @@ -111,4 +111,29 @@ const watch_face_t watch_faces[] = { #define MOVEMENT_DEFAULT_BIRTHDATE_MONTH 0 #define MOVEMENT_DEFAULT_BIRTHDATE_DAY 0 +/* Set if the watch will chime every hour and ignorethe start and end chimes + * Valid values are: + * 0: Use the Start and End values + * 1: Chime every hour + */ +#define MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS 0 + +/* When hourly chiming should begin (MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS must be 0) + * Valid values are: + * 0: 6am + * 1: 7am + * 2: 10am + * 3: 12pm + */ +#define MOVEMENT_DEFAULT_HOURLY_CHIME_START 1 + +/* When hourly chiming should end (MOVEMENT_DEFAULT_HOURLY_CHIME_ALWAYS must be 0) + * Valid values are: + * 0: 8pm + * 1: 9pm + * 2: 10pm + * 3: 12am + */ +#define MOVEMENT_DEFAULT_HOURLY_CHIME_END 1 + #endif // MOVEMENT_CONFIG_H_ diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index ac4ec2ee5..c98d5a4e4 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -162,6 +162,10 @@ bool simple_clock_face_wants_background_task(movement_settings_t *settings, void if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); + uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; + uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (chime_end == 0) chime_end = 24; + if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/settings/preferences_face.c b/movement/watch_faces/settings/preferences_face.c index 22979773e..886d0d195 100644 --- a/movement/watch_faces/settings/preferences_face.c +++ b/movement/watch_faces/settings/preferences_face.c @@ -26,19 +26,21 @@ #include "preferences_face.h" #include "watch.h" -#define PREFERENCES_FACE_NUM_PREFERENCES (7) +#define PREFERENCES_FACE_NUM_PREFERENCES (9) const char preferences_face_titles[PREFERENCES_FACE_NUM_PREFERENCES][11] = { "CL ", // Clock: 12 or 24 hour "BT Beep ", // Buttons: should they beep? "TO ", // Timeout: how long before we snap back to the clock face? "LE ", // Low Energy mode: how long before it engages? + "HCSt ", // Hourly Chime Start + "HCEn ", // Hourly Chime End "LT ", // Light: duration #ifdef WATCH_IS_BLUE_BOARD "LT blu ", // Light: blue component (for watches with blue LED) #else "LT grn ", // Light: green component #endif - "LT red ", // Light: red component + "LT red " // Light: red component }; void preferences_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { @@ -53,6 +55,31 @@ void preferences_face_activate(movement_settings_t *settings, void *context) { movement_request_tick_frequency(4); // we need to manually blink some pixels } +static void _watch_display_hourly_chime_string(movement_settings_t *settings, uint8_t hour){ + char buf[4]; + if (settings->bit.hourly_chime_always){ + watch_display_string(" Always", 4); + } + else{ + if (!settings->bit.clock_mode_24h) { + // if we are in 12 hour mode, do some cleanup. + if (hour < 12) { + watch_clear_indicator(WATCH_INDICATOR_PM); + } else { + watch_set_indicator(WATCH_INDICATOR_PM); + } + hour %= 12; + if (hour == 0) hour = 12; + } + if (hour > 9) + sprintf(buf, "%2d", hour); + else + sprintf(buf, " %d", hour); + watch_display_string(buf, 6); + } +} + + bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { uint8_t current_page = *((uint8_t *)context); switch (event.event_type) { @@ -83,12 +110,38 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings settings->bit.le_interval = settings->bit.le_interval + 1; break; case 4: - settings->bit.led_duration = settings->bit.led_duration + 1; + if (settings->bit.hourly_chime_always){ + settings->bit.hourly_chime_always = false; + settings->bit.hourly_chime_start = 0; + } + else if (settings->bit.hourly_chime_start == 3){ + settings->bit.hourly_chime_always = true; + settings->bit.hourly_chime_start = 0; + } + else{ + settings->bit.hourly_chime_start = settings->bit.hourly_chime_start + 1; + } break; case 5: - settings->bit.led_green_color = settings->bit.led_green_color + 1; + if (settings->bit.hourly_chime_always){ + settings->bit.hourly_chime_always = false; + settings->bit.hourly_chime_end = 0; + } + else if (settings->bit.hourly_chime_end == 3){ + settings->bit.hourly_chime_always = true; + settings->bit.hourly_chime_end = 0; + } + else{ + settings->bit.hourly_chime_end = settings->bit.hourly_chime_end + 1; + } break; case 6: + settings->bit.led_duration = settings->bit.led_duration + 1; + break; + case 7: + settings->bit.led_green_color = settings->bit.led_green_color + 1; + break; + case 8: settings->bit.led_red_color = settings->bit.led_red_color + 1; break; } @@ -161,6 +214,12 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings } break; case 4: + _watch_display_hourly_chime_string(settings, Hourly_Chime_Start[settings->bit.hourly_chime_start]); + break; + case 5: + _watch_display_hourly_chime_string(settings, Hourly_Chime_End[settings->bit.hourly_chime_end]); + break; + case 6: if (settings->bit.led_duration) { sprintf(buf, " %1d SeC", settings->bit.led_duration * 2 - 1); watch_display_string(buf, 4); @@ -168,11 +227,11 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings watch_display_string("no LEd", 4); } break; - case 5: + case 7: sprintf(buf, "%2d", settings->bit.led_green_color); watch_display_string(buf, 8); break; - case 6: + case 8: sprintf(buf, "%2d", settings->bit.led_red_color); watch_display_string(buf, 8); break; @@ -180,7 +239,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings } // on LED color select screns, preview the color. - if (current_page >= 5) { + if (current_page >= 7) { watch_set_led_color(settings->bit.led_red_color ? (0xF | settings->bit.led_red_color << 4) : 0, settings->bit.led_green_color ? (0xF | settings->bit.led_green_color << 4) : 0); // return false so the watch stays awake (needed for the PWM driver to function). From 138a6541984c021f247c719e3b0dc4dde3501f8c Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Mon, 3 Jun 2024 16:55:40 -0400 Subject: [PATCH 2/9] All clocks that have hourly chimes now don't chime in the quiet preriod --- movement/watch_faces/clock/minute_repeater_decimal_face.c | 4 ++++ movement/watch_faces/clock/repetition_minute_face.c | 4 ++++ movement/watch_faces/clock/simple_clock_bin_led_face.c | 4 ++++ movement/watch_faces/clock/weeknumber_clock_face.c | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index 2cedc3075..9357ca3b2 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -233,6 +233,10 @@ bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *set if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); + uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; + uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (chime_end == 0) chime_end = 24; + if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index e9e5e3197..7db1fbb4e 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -216,6 +216,10 @@ bool repetition_minute_face_wants_background_task(movement_settings_t *settings, if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); + uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; + uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (chime_end == 0) chime_end = 24; + if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index cf39c1886..2351aff0e 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -217,6 +217,10 @@ bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settin if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); + uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; + uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (chime_end == 0) chime_end = 24; + if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 81df58475..3e6852b48 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -151,6 +151,10 @@ bool weeknumber_clock_face_wants_background_task(movement_settings_t *settings, if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); + uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; + uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (chime_end == 0) chime_end = 24; + if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; return date_time.unit.minute == 0; } From dcafdead5488510d03e31fb0c4ee65b1b826bb8b Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Fri, 30 Aug 2024 13:52:21 -0400 Subject: [PATCH 3/9] Included logic on clock_face and changed the time view on preferences --- movement/watch_faces/clock/clock_face.c | 4 ++++ movement/watch_faces/settings/preferences_face.c | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 20a02e7dc..e84b9f7f8 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -285,6 +285,10 @@ bool clock_face_wants_background_task(movement_settings_t *settings, void *conte if (!state->time_signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); + uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; + uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (chime_end == 0) chime_end = 24; + if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/settings/preferences_face.c b/movement/watch_faces/settings/preferences_face.c index 886d0d195..47be53608 100644 --- a/movement/watch_faces/settings/preferences_face.c +++ b/movement/watch_faces/settings/preferences_face.c @@ -56,8 +56,9 @@ void preferences_face_activate(movement_settings_t *settings, void *context) { } static void _watch_display_hourly_chime_string(movement_settings_t *settings, uint8_t hour){ - char buf[4]; + char buf[6]; if (settings->bit.hourly_chime_always){ + watch_clear_indicator(WATCH_INDICATOR_PM); watch_display_string(" Always", 4); } else{ @@ -72,10 +73,11 @@ static void _watch_display_hourly_chime_string(movement_settings_t *settings, ui if (hour == 0) hour = 12; } if (hour > 9) - sprintf(buf, "%2d", hour); + sprintf(buf, "%2d00", hour); else - sprintf(buf, " %d", hour); - watch_display_string(buf, 6); + sprintf(buf, " %d00", hour); + watch_set_colon(); + watch_display_string(buf, 4); } } @@ -158,6 +160,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings watch_display_string((char *)preferences_face_titles[current_page], 0); // blink active setting on even-numbered quarter-seconds + watch_clear_colon(); if (event.subsecond % 2) { char buf[8]; switch (current_page) { From dafb1fdd11cbcdda7305fa9f79410644ea8b1dab Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 7 Sep 2024 07:59:39 -0400 Subject: [PATCH 4/9] Added ability for the simple_clock_face to use sunrise or sunset as the time to turn the hourly beep on or off --- movement/movement.h | 8 +-- movement/movement_config.h | 4 +- .../watch_faces/clock/simple_clock_face.c | 53 +++++++++++++++++-- .../watch_faces/settings/preferences_face.c | 10 +++- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/movement/movement.h b/movement/movement.h index f2b421b37..9340f9179 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -63,8 +63,8 @@ typedef union { bool use_imperial_units : 1; // indicates whether to use metric units (the default) or imperial. bool alarm_enabled : 1; // indicates whether there is at least one alarm enabled. bool hourly_chime_always : 1; // if true, then ignore the - uint8_t hourly_chime_start : 2; // 0: 6am; 1: 7am; 2: 10am; 3: 12pm; - uint8_t hourly_chime_end : 2; // 0: 8pm; 1: 9pm; 2: 10pm; 3: 12am; + uint8_t hourly_chime_start : 2; // 0: 6am; 1: 7am; 2: 10am; 3: 12pm or sunrise in long and lat set; + uint8_t hourly_chime_end : 2; // 0: 8pm; 1: 9pm; 2: 10pm; 3: 12am or sunset in long and lat set; bool reserved : 1; // room for more preferences if needed. } bit; uint32_t reg; @@ -326,7 +326,7 @@ static const uint8_t Hourly_Chime_Start[] = 6, // 6am 7, // 7am 10, // 10am - 12 // 12pm + 12 // 12pm if no long and lat set; sunset otherwise }; static const uint8_t Hourly_Chime_End[] = @@ -334,7 +334,7 @@ static const uint8_t Hourly_Chime_End[] = 20, // 8pm 21, // 9pm 22, // 10pm - 00 // 12am + 00 // 12am if no long and lat set; sunrise otherwise }; #endif // MOVEMENT_H_ diff --git a/movement/movement_config.h b/movement/movement_config.h index 53ab67b82..b0c9b017d 100644 --- a/movement/movement_config.h +++ b/movement/movement_config.h @@ -123,7 +123,7 @@ const watch_face_t watch_faces[] = { * 0: 6am * 1: 7am * 2: 10am - * 3: 12pm + * 3: 12pm or sunrise in long and lat set; */ #define MOVEMENT_DEFAULT_HOURLY_CHIME_START 1 @@ -132,7 +132,7 @@ const watch_face_t watch_faces[] = { * 0: 8pm * 1: 9pm * 2: 10pm - * 3: 12am + * 3: 12am or sunset in long and lat set; */ #define MOVEMENT_DEFAULT_HOURLY_CHIME_END 1 diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index c98d5a4e4..2f385c136 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -27,6 +27,52 @@ #include "watch.h" #include "watch_utility.h" #include "watch_private_display.h" +#include "sunriset.h" + +static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { + *start_hour = Hourly_Chime_Start[hourly_chime_start]; + *end_hour = Hourly_Chime_End[hourly_chime_end]; +} + +static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { + time += hours_from_utc; + uint8_t hour_to_start = (uint8_t)time; + double minutes = (time - hour_to_start) * 60; + if (!use_end_of_hour) return hour_to_start; + if (minutes >= 0.5) + hour_to_start = (hour_to_start + 1) % 24; + return hour_to_start; +} + +static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t hourly_chime_start = settings->bit.hourly_chime_start; + uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + if (hourly_chime_start != 3 && hourly_chime_end != 3) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; + watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC + movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); + if (movement_location.reg == 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + double rise, set; + uint8_t rise_hour, set_hour; + double lat = (double)movement_location.bit.latitude / 100.0; + double lon = (double)movement_location.bit.longitude / 100.0; + double hours_from_utc = ((double)tz) / 60.0; + uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); + if (result != 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); + set_hour = _time_to_chime_hour(set, hours_from_utc, false); + *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; +} static void _update_alarm_indicator(bool settings_alarm_enabled, simple_clock_state_t *state) { state->alarm_enabled = settings_alarm_enabled; @@ -162,10 +208,11 @@ bool simple_clock_face_wants_background_task(movement_settings_t *settings, void if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; - uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (date_time.unit.minute != 0) return false; + uint8_t chime_start, chime_end; + _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; - return date_time.unit.minute == 0; + return true; } diff --git a/movement/watch_faces/settings/preferences_face.c b/movement/watch_faces/settings/preferences_face.c index 47be53608..c9d75c6df 100644 --- a/movement/watch_faces/settings/preferences_face.c +++ b/movement/watch_faces/settings/preferences_face.c @@ -217,10 +217,16 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings } break; case 4: - _watch_display_hourly_chime_string(settings, Hourly_Chime_Start[settings->bit.hourly_chime_start]); + if (watch_get_backup_data(1) && settings->bit.hourly_chime_start == 3) + watch_display_string("SUNRIS", 4); + else + _watch_display_hourly_chime_string(settings, Hourly_Chime_Start[settings->bit.hourly_chime_start]); break; case 5: - _watch_display_hourly_chime_string(settings, Hourly_Chime_End[settings->bit.hourly_chime_end]); + if (watch_get_backup_data(1) && settings->bit.hourly_chime_end == 3) + watch_display_string("SUNSET", 4); + else + _watch_display_hourly_chime_string(settings, Hourly_Chime_End[settings->bit.hourly_chime_end]); break; case 6: if (settings->bit.led_duration) { From e399a1742dcd2d9784066d735b8c447e1896a529 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 7 Sep 2024 08:06:15 -0400 Subject: [PATCH 5/9] All faces can now use sunrise or sunset --- movement/watch_faces/clock/clock_face.c | 53 +++++++++++++++++-- .../clock/minute_repeater_decimal_face.c | 53 +++++++++++++++++-- .../clock/repetition_minute_face.c | 53 +++++++++++++++++-- .../clock/simple_clock_bin_led_face.c | 53 +++++++++++++++++-- .../watch_faces/clock/weeknumber_clock_face.c | 53 +++++++++++++++++-- 5 files changed, 250 insertions(+), 15 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index e84b9f7f8..3909fd20e 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -35,6 +35,7 @@ #include "watch.h" #include "watch_utility.h" #include "watch_private_display.h" +#include "sunriset.h" // 2.2 volts will happen when the battery has maybe 5-10% remaining? // we can refine this later. @@ -52,6 +53,51 @@ typedef struct { bool battery_low; } clock_state_t; +static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { + *start_hour = Hourly_Chime_Start[hourly_chime_start]; + *end_hour = Hourly_Chime_End[hourly_chime_end]; +} + +static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { + time += hours_from_utc; + uint8_t hour_to_start = (uint8_t)time; + double minutes = (time - hour_to_start) * 60; + if (!use_end_of_hour) return hour_to_start; + if (minutes >= 0.5) + hour_to_start = (hour_to_start + 1) % 24; + return hour_to_start; +} + +static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t hourly_chime_start = settings->bit.hourly_chime_start; + uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + if (hourly_chime_start != 3 && hourly_chime_end != 3) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; + watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC + movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); + if (movement_location.reg == 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + double rise, set; + uint8_t rise_hour, set_hour; + double lat = (double)movement_location.bit.latitude / 100.0; + double lon = (double)movement_location.bit.longitude / 100.0; + double hours_from_utc = ((double)tz) / 60.0; + uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); + if (result != 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); + set_hour = _time_to_chime_hour(set, hours_from_utc, false); + *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; +} + static bool clock_is_in_24h_mode(movement_settings_t *settings) { #ifdef CLOCK_FACE_24H_ONLY return true; @@ -285,10 +331,11 @@ bool clock_face_wants_background_task(movement_settings_t *settings, void *conte if (!state->time_signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; - uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (date_time.unit.minute != 0) return false; + uint8_t chime_start, chime_end; + _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; - return date_time.unit.minute == 0; + return true; } diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index 9357ca3b2..2787cbe4b 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -42,6 +42,52 @@ #include "watch.h" #include "watch_utility.h" #include "watch_private_display.h" +#include "sunriset.h" + +static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { + *start_hour = Hourly_Chime_Start[hourly_chime_start]; + *end_hour = Hourly_Chime_End[hourly_chime_end]; +} + +static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { + time += hours_from_utc; + uint8_t hour_to_start = (uint8_t)time; + double minutes = (time - hour_to_start) * 60; + if (!use_end_of_hour) return hour_to_start; + if (minutes >= 0.5) + hour_to_start = (hour_to_start + 1) % 24; + return hour_to_start; +} + +static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t hourly_chime_start = settings->bit.hourly_chime_start; + uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + if (hourly_chime_start != 3 && hourly_chime_end != 3) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; + watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC + movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); + if (movement_location.reg == 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + double rise, set; + uint8_t rise_hour, set_hour; + double lat = (double)movement_location.bit.latitude / 100.0; + double lon = (double)movement_location.bit.longitude / 100.0; + double hours_from_utc = ((double)tz) / 60.0; + uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); + if (result != 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); + set_hour = _time_to_chime_hour(set, hours_from_utc, false); + *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; +} void mrd_play_hour_chime(void) { watch_buzzer_play_note(BUZZER_NOTE_C6, 75); @@ -233,10 +279,11 @@ bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *set if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; - uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (date_time.unit.minute != 0) return false; + uint8_t chime_start, chime_end; + _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; - return date_time.unit.minute == 0; + return true; } diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index 7db1fbb4e..30112268e 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -27,6 +27,52 @@ #include "watch.h" #include "watch_utility.h" #include "watch_private_display.h" +#include "sunriset.h" + +static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { + *start_hour = Hourly_Chime_Start[hourly_chime_start]; + *end_hour = Hourly_Chime_End[hourly_chime_end]; +} + +static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { + time += hours_from_utc; + uint8_t hour_to_start = (uint8_t)time; + double minutes = (time - hour_to_start) * 60; + if (!use_end_of_hour) return hour_to_start; + if (minutes >= 0.5) + hour_to_start = (hour_to_start + 1) % 24; + return hour_to_start; +} + +static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t hourly_chime_start = settings->bit.hourly_chime_start; + uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + if (hourly_chime_start != 3 && hourly_chime_end != 3) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; + watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC + movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); + if (movement_location.reg == 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + double rise, set; + uint8_t rise_hour, set_hour; + double lat = (double)movement_location.bit.latitude / 100.0; + double lon = (double)movement_location.bit.longitude / 100.0; + double hours_from_utc = ((double)tz) / 60.0; + uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); + if (result != 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); + set_hour = _time_to_chime_hour(set, hours_from_utc, false); + *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; +} void play_hour_chime(void) { watch_buzzer_play_note(BUZZER_NOTE_C6, 75); @@ -216,10 +262,11 @@ bool repetition_minute_face_wants_background_task(movement_settings_t *settings, if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; - uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (date_time.unit.minute != 0) return false; + uint8_t chime_start, chime_end; + _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; - return date_time.unit.minute == 0; + return true; } diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index 2351aff0e..4520fc732 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -28,6 +28,52 @@ #include "watch.h" #include "watch_utility.h" #include "watch_private_display.h" +#include "sunriset.h" + +static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { + *start_hour = Hourly_Chime_Start[hourly_chime_start]; + *end_hour = Hourly_Chime_End[hourly_chime_end]; +} + +static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { + time += hours_from_utc; + uint8_t hour_to_start = (uint8_t)time; + double minutes = (time - hour_to_start) * 60; + if (!use_end_of_hour) return hour_to_start; + if (minutes >= 0.5) + hour_to_start = (hour_to_start + 1) % 24; + return hour_to_start; +} + +static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t hourly_chime_start = settings->bit.hourly_chime_start; + uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + if (hourly_chime_start != 3 && hourly_chime_end != 3) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; + watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC + movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); + if (movement_location.reg == 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + double rise, set; + uint8_t rise_hour, set_hour; + double lat = (double)movement_location.bit.latitude / 100.0; + double lon = (double)movement_location.bit.longitude / 100.0; + double hours_from_utc = ((double)tz) / 60.0; + uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); + if (result != 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); + set_hour = _time_to_chime_hour(set, hours_from_utc, false); + *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; +} static void _update_alarm_indicator(bool settings_alarm_enabled, simple_clock_bin_led_state_t *state) { state->alarm_enabled = settings_alarm_enabled; @@ -217,10 +263,11 @@ bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settin if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; - uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (date_time.unit.minute != 0) return false; + uint8_t chime_start, chime_end; + _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; - return date_time.unit.minute == 0; + return true; } diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 3e6852b48..66a6fb023 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -26,6 +26,52 @@ #include "weeknumber_clock_face.h" #include "watch.h" #include "watch_utility.h" +#include "sunriset.h" + +static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { + *start_hour = Hourly_Chime_Start[hourly_chime_start]; + *end_hour = Hourly_Chime_End[hourly_chime_end]; +} + +static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { + time += hours_from_utc; + uint8_t hour_to_start = (uint8_t)time; + double minutes = (time - hour_to_start) * 60; + if (!use_end_of_hour) return hour_to_start; + if (minutes >= 0.5) + hour_to_start = (hour_to_start + 1) % 24; + return hour_to_start; +} + +static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t hourly_chime_start = settings->bit.hourly_chime_start; + uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + if (hourly_chime_start != 3 && hourly_chime_end != 3) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; + watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC + movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); + if (movement_location.reg == 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + double rise, set; + uint8_t rise_hour, set_hour; + double lat = (double)movement_location.bit.latitude / 100.0; + double lon = (double)movement_location.bit.longitude / 100.0; + double hours_from_utc = ((double)tz) / 60.0; + uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); + if (result != 0) { + _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); + return; + } + rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); + set_hour = _time_to_chime_hour(set, hours_from_utc, false); + *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; +} static void _update_alarm_indicator(bool settings_alarm_enabled, weeknumber_clock_state_t *state) { state->alarm_enabled = settings_alarm_enabled; @@ -151,10 +197,11 @@ bool weeknumber_clock_face_wants_background_task(movement_settings_t *settings, if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t chime_start = Hourly_Chime_Start[settings->bit.hourly_chime_start]; - uint8_t chime_end = Hourly_Chime_End[settings->bit.hourly_chime_end]; + if (date_time.unit.minute != 0) return false; + uint8_t chime_start, chime_end; + _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; - return date_time.unit.minute == 0; + return true; } From 1ff9954c1c0552d4da9b601b0082bbd1aed78970 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 7 Sep 2024 08:36:35 -0400 Subject: [PATCH 6/9] No longer run full sunrise logic if hourly_chime_always is set --- movement/watch_faces/clock/clock_face.c | 3 ++- movement/watch_faces/clock/minute_repeater_decimal_face.c | 3 ++- movement/watch_faces/clock/repetition_minute_face.c | 3 ++- movement/watch_faces/clock/simple_clock_bin_led_face.c | 3 ++- movement/watch_faces/clock/simple_clock_face.c | 3 ++- movement/watch_faces/clock/weeknumber_clock_face.c | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 3909fd20e..430ff71be 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -332,10 +332,11 @@ bool clock_face_wants_background_task(movement_settings_t *settings, void *conte watch_date_time date_time = watch_rtc_get_date_time(); if (date_time.unit.minute != 0) return false; + if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; - if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; + if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; return true; } diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index 2787cbe4b..b12b4a3a2 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -280,10 +280,11 @@ bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *set watch_date_time date_time = watch_rtc_get_date_time(); if (date_time.unit.minute != 0) return false; + if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; - if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; + if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; return true; } diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index 30112268e..76cc2930f 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -263,10 +263,11 @@ bool repetition_minute_face_wants_background_task(movement_settings_t *settings, watch_date_time date_time = watch_rtc_get_date_time(); if (date_time.unit.minute != 0) return false; + if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; - if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; + if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; return true; } diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index 4520fc732..495537442 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -264,10 +264,11 @@ bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settin watch_date_time date_time = watch_rtc_get_date_time(); if (date_time.unit.minute != 0) return false; + if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; - if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; + if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; return true; } diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index 2f385c136..d3e551571 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -209,10 +209,11 @@ bool simple_clock_face_wants_background_task(movement_settings_t *settings, void watch_date_time date_time = watch_rtc_get_date_time(); if (date_time.unit.minute != 0) return false; + if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; - if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; + if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; return true; } diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 66a6fb023..a1a1dab3d 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -198,10 +198,11 @@ bool weeknumber_clock_face_wants_background_task(movement_settings_t *settings, watch_date_time date_time = watch_rtc_get_date_time(); if (date_time.unit.minute != 0) return false; + if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); if (chime_end == 0) chime_end = 24; - if (!settings->bit.hourly_chime_always && (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end)) return false; + if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; return true; } From 613f17fe3c6922d73a089303a5844e152fb62990 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Tue, 10 Sep 2024 08:41:30 -0400 Subject: [PATCH 7/9] If the sunrise function does not run correctly, then don't chime --- movement/watch_faces/clock/clock_face.c | 20 ++++++++----------- .../clock/minute_repeater_decimal_face.c | 20 ++++++++----------- .../clock/repetition_minute_face.c | 20 ++++++++----------- .../clock/simple_clock_bin_led_face.c | 20 ++++++++----------- .../watch_faces/clock/simple_clock_face.c | 20 ++++++++----------- .../watch_faces/clock/weeknumber_clock_face.c | 20 ++++++++----------- 6 files changed, 48 insertions(+), 72 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 430ff71be..01d0e9fb8 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -53,11 +53,6 @@ typedef struct { bool battery_low; } clock_state_t; -static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { - *start_hour = Hourly_Chime_Start[hourly_chime_start]; - *end_hour = Hourly_Chime_End[hourly_chime_end]; -} - static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { time += hours_from_utc; uint8_t hour_to_start = (uint8_t)time; @@ -69,17 +64,18 @@ static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_ } static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t init_val = 0xFF; uint8_t hourly_chime_start = settings->bit.hourly_chime_start; uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + *start_hour = (hourly_chime_start == 3) ? init_val : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? init_val : Hourly_Chime_End[hourly_chime_end]; if (hourly_chime_start != 3 && hourly_chime_end != 3) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); if (movement_location.reg == 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } double rise, set; @@ -89,13 +85,14 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); set_hour = _time_to_chime_hour(set, hours_from_utc, false); - *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; - *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; + if (*start_hour == init_val) *start_hour = rise_hour; + if (*end_hour == init_val) *end_hour = set_hour; + if (*start_hour == 0) *start_hour = 24; + if (*end_hour == 0) *end_hour = 24; } static bool clock_is_in_24h_mode(movement_settings_t *settings) { @@ -335,8 +332,7 @@ bool clock_face_wants_background_task(movement_settings_t *settings, void *conte if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); - if (chime_end == 0) chime_end = 24; - if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; + if ((24 >= chime_start && date_time.unit.hour < chime_start) || (24 >= chime_end && date_time.unit.hour >= chime_end)) return false; return true; } diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index b12b4a3a2..e9f94a2b7 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -44,11 +44,6 @@ #include "watch_private_display.h" #include "sunriset.h" -static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { - *start_hour = Hourly_Chime_Start[hourly_chime_start]; - *end_hour = Hourly_Chime_End[hourly_chime_end]; -} - static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { time += hours_from_utc; uint8_t hour_to_start = (uint8_t)time; @@ -60,17 +55,18 @@ static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_ } static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t init_val = 0xFF; uint8_t hourly_chime_start = settings->bit.hourly_chime_start; uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + *start_hour = (hourly_chime_start == 3) ? init_val : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? init_val : Hourly_Chime_End[hourly_chime_end]; if (hourly_chime_start != 3 && hourly_chime_end != 3) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); if (movement_location.reg == 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } double rise, set; @@ -80,13 +76,14 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); set_hour = _time_to_chime_hour(set, hours_from_utc, false); - *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; - *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; + if (*start_hour == init_val) *start_hour = rise_hour; + if (*end_hour == init_val) *end_hour = set_hour; + if (*start_hour == 0) *start_hour = 24; + if (*end_hour == 0) *end_hour = 24; } void mrd_play_hour_chime(void) { @@ -283,8 +280,7 @@ bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *set if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); - if (chime_end == 0) chime_end = 24; - if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; + if ((24 >= chime_start && date_time.unit.hour < chime_start) || (24 >= chime_end && date_time.unit.hour >= chime_end)) return false; return true; } diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index 76cc2930f..ff4ac8466 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -29,11 +29,6 @@ #include "watch_private_display.h" #include "sunriset.h" -static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { - *start_hour = Hourly_Chime_Start[hourly_chime_start]; - *end_hour = Hourly_Chime_End[hourly_chime_end]; -} - static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { time += hours_from_utc; uint8_t hour_to_start = (uint8_t)time; @@ -45,17 +40,18 @@ static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_ } static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t init_val = 0xFF; uint8_t hourly_chime_start = settings->bit.hourly_chime_start; uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + *start_hour = (hourly_chime_start == 3) ? init_val : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? init_val : Hourly_Chime_End[hourly_chime_end]; if (hourly_chime_start != 3 && hourly_chime_end != 3) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); if (movement_location.reg == 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } double rise, set; @@ -65,13 +61,14 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); set_hour = _time_to_chime_hour(set, hours_from_utc, false); - *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; - *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; + if (*start_hour == init_val) *start_hour = rise_hour; + if (*end_hour == init_val) *end_hour = set_hour; + if (*start_hour == 0) *start_hour = 24; + if (*end_hour == 0) *end_hour = 24; } void play_hour_chime(void) { @@ -266,8 +263,7 @@ bool repetition_minute_face_wants_background_task(movement_settings_t *settings, if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); - if (chime_end == 0) chime_end = 24; - if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; + if ((24 >= chime_start && date_time.unit.hour < chime_start) || (24 >= chime_end && date_time.unit.hour >= chime_end)) return false; return true; } diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index 495537442..c1f7d0fab 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -30,11 +30,6 @@ #include "watch_private_display.h" #include "sunriset.h" -static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { - *start_hour = Hourly_Chime_Start[hourly_chime_start]; - *end_hour = Hourly_Chime_End[hourly_chime_end]; -} - static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { time += hours_from_utc; uint8_t hour_to_start = (uint8_t)time; @@ -46,17 +41,18 @@ static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_ } static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t init_val = 0xFF; uint8_t hourly_chime_start = settings->bit.hourly_chime_start; uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + *start_hour = (hourly_chime_start == 3) ? init_val : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? init_val : Hourly_Chime_End[hourly_chime_end]; if (hourly_chime_start != 3 && hourly_chime_end != 3) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); if (movement_location.reg == 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } double rise, set; @@ -66,13 +62,14 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); set_hour = _time_to_chime_hour(set, hours_from_utc, false); - *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; - *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; + if (*start_hour == init_val) *start_hour = rise_hour; + if (*end_hour == init_val) *end_hour = set_hour; + if (*start_hour == 0) *start_hour = 24; + if (*end_hour == 0) *end_hour = 24; } static void _update_alarm_indicator(bool settings_alarm_enabled, simple_clock_bin_led_state_t *state) { @@ -267,8 +264,7 @@ bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settin if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); - if (chime_end == 0) chime_end = 24; - if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; + if ((24 >= chime_start && date_time.unit.hour < chime_start) || (24 >= chime_end && date_time.unit.hour >= chime_end)) return false; return true; } diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index d3e551571..b3dcd8a14 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -29,11 +29,6 @@ #include "watch_private_display.h" #include "sunriset.h" -static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { - *start_hour = Hourly_Chime_Start[hourly_chime_start]; - *end_hour = Hourly_Chime_End[hourly_chime_end]; -} - static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { time += hours_from_utc; uint8_t hour_to_start = (uint8_t)time; @@ -45,17 +40,18 @@ static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_ } static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t init_val = 0xFF; uint8_t hourly_chime_start = settings->bit.hourly_chime_start; uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + *start_hour = (hourly_chime_start == 3) ? init_val : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? init_val : Hourly_Chime_End[hourly_chime_end]; if (hourly_chime_start != 3 && hourly_chime_end != 3) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); if (movement_location.reg == 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } double rise, set; @@ -65,13 +61,14 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); set_hour = _time_to_chime_hour(set, hours_from_utc, false); - *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; - *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; + if (*start_hour == init_val) *start_hour = rise_hour; + if (*end_hour == init_val) *end_hour = set_hour; + if (*start_hour == 0) *start_hour = 24; + if (*end_hour == 0) *end_hour = 24; } static void _update_alarm_indicator(bool settings_alarm_enabled, simple_clock_state_t *state) { @@ -212,8 +209,7 @@ bool simple_clock_face_wants_background_task(movement_settings_t *settings, void if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); - if (chime_end == 0) chime_end = 24; - if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; + if ((24 >= chime_start && date_time.unit.hour < chime_start) || (24 >= chime_end && date_time.unit.hour >= chime_end)) return false; return true; } diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index a1a1dab3d..5c2162bb1 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -28,11 +28,6 @@ #include "watch_utility.h" #include "sunriset.h" -static void _load_default_chime_times(uint8_t hourly_chime_start, uint8_t hourly_chime_end, uint8_t *start_hour, uint8_t *end_hour) { - *start_hour = Hourly_Chime_Start[hourly_chime_start]; - *end_hour = Hourly_Chime_End[hourly_chime_end]; -} - static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_end_of_hour) { time += hours_from_utc; uint8_t hour_to_start = (uint8_t)time; @@ -44,17 +39,18 @@ static uint8_t _time_to_chime_hour(double time, double hours_from_utc, bool use_ } static void _get_chime_times(watch_date_time date_time, movement_settings_t *settings, uint8_t *start_hour, uint8_t *end_hour) { + uint8_t init_val = 0xFF; uint8_t hourly_chime_start = settings->bit.hourly_chime_start; uint8_t hourly_chime_end = settings->bit.hourly_chime_end; + *start_hour = (hourly_chime_start == 3) ? init_val : Hourly_Chime_Start[hourly_chime_start]; + *end_hour = (hourly_chime_end == 3) ? init_val : Hourly_Chime_End[hourly_chime_end]; if (hourly_chime_start != 3 && hourly_chime_end != 3) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } int16_t tz = movement_timezone_offsets[settings->bit.time_zone]; watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1); if (movement_location.reg == 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } double rise, set; @@ -64,13 +60,14 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { - _load_default_chime_times(hourly_chime_start, hourly_chime_end, start_hour, end_hour); return; } rise_hour = _time_to_chime_hour(rise, hours_from_utc, true); set_hour = _time_to_chime_hour(set, hours_from_utc, false); - *start_hour = (hourly_chime_start == 3) ? rise_hour : Hourly_Chime_Start[hourly_chime_start]; - *end_hour = (hourly_chime_end == 3) ? set_hour : Hourly_Chime_End[hourly_chime_end]; + if (*start_hour == init_val) *start_hour = rise_hour; + if (*end_hour == init_val) *end_hour = set_hour; + if (*start_hour == 0) *start_hour = 24; + if (*end_hour == 0) *end_hour = 24; } static void _update_alarm_indicator(bool settings_alarm_enabled, weeknumber_clock_state_t *state) { @@ -201,8 +198,7 @@ bool weeknumber_clock_face_wants_background_task(movement_settings_t *settings, if (settings->bit.hourly_chime_always) return true; uint8_t chime_start, chime_end; _get_chime_times(date_time, settings, &chime_start, &chime_end); - if (chime_end == 0) chime_end = 24; - if (date_time.unit.hour < chime_start || date_time.unit.hour >= chime_end) return false; + if ((24 >= chime_start && date_time.unit.hour < chime_start) || (24 >= chime_end && date_time.unit.hour >= chime_end)) return false; return true; } From 1271b2e7b5849922ca427fa2684107c2e2907918 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sat, 21 Sep 2024 08:22:06 -0400 Subject: [PATCH 8/9] Fixed quirk from directly casting lat into double where time offset is double UT --- movement/watch_faces/clock/clock_face.c | 6 ++++-- movement/watch_faces/clock/minute_repeater_decimal_face.c | 6 ++++-- movement/watch_faces/clock/repetition_minute_face.c | 6 ++++-- movement/watch_faces/clock/simple_clock_bin_led_face.c | 6 ++++-- movement/watch_faces/clock/simple_clock_face.c | 6 ++++-- movement/watch_faces/clock/weeknumber_clock_face.c | 6 ++++-- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 01d0e9fb8..fef00927f 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -80,8 +80,10 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set } double rise, set; uint8_t rise_hour, set_hour; - double lat = (double)movement_location.bit.latitude / 100.0; - double lon = (double)movement_location.bit.longitude / 100.0; + int16_t lat_centi = (int16_t)movement_location.bit.latitude; + int16_t lon_centi = (int16_t)movement_location.bit.longitude; + double lat = (double)lat_centi / 100.0; + double lon = (double)lon_centi / 100.0; double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index e9f94a2b7..a709e7894 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -71,8 +71,10 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set } double rise, set; uint8_t rise_hour, set_hour; - double lat = (double)movement_location.bit.latitude / 100.0; - double lon = (double)movement_location.bit.longitude / 100.0; + int16_t lat_centi = (int16_t)movement_location.bit.latitude; + int16_t lon_centi = (int16_t)movement_location.bit.longitude; + double lat = (double)lat_centi / 100.0; + double lon = (double)lon_centi / 100.0; double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index ff4ac8466..589090dce 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -56,8 +56,10 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set } double rise, set; uint8_t rise_hour, set_hour; - double lat = (double)movement_location.bit.latitude / 100.0; - double lon = (double)movement_location.bit.longitude / 100.0; + int16_t lat_centi = (int16_t)movement_location.bit.latitude; + int16_t lon_centi = (int16_t)movement_location.bit.longitude; + double lat = (double)lat_centi / 100.0; + double lon = (double)lon_centi / 100.0; double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index c1f7d0fab..681b54433 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -57,8 +57,10 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set } double rise, set; uint8_t rise_hour, set_hour; - double lat = (double)movement_location.bit.latitude / 100.0; - double lon = (double)movement_location.bit.longitude / 100.0; + int16_t lat_centi = (int16_t)movement_location.bit.latitude; + int16_t lon_centi = (int16_t)movement_location.bit.longitude; + double lat = (double)lat_centi / 100.0; + double lon = (double)lon_centi / 100.0; double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index b3dcd8a14..751f9acaf 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -56,8 +56,10 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set } double rise, set; uint8_t rise_hour, set_hour; - double lat = (double)movement_location.bit.latitude / 100.0; - double lon = (double)movement_location.bit.longitude / 100.0; + int16_t lat_centi = (int16_t)movement_location.bit.latitude; + int16_t lon_centi = (int16_t)movement_location.bit.longitude; + double lat = (double)lat_centi / 100.0; + double lon = (double)lon_centi / 100.0; double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 5c2162bb1..701150c9e 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -55,8 +55,10 @@ static void _get_chime_times(watch_date_time date_time, movement_settings_t *set } double rise, set; uint8_t rise_hour, set_hour; - double lat = (double)movement_location.bit.latitude / 100.0; - double lon = (double)movement_location.bit.longitude / 100.0; + int16_t lat_centi = (int16_t)movement_location.bit.latitude; + int16_t lon_centi = (int16_t)movement_location.bit.longitude; + double lat = (double)lat_centi / 100.0; + double lon = (double)lon_centi / 100.0; double hours_from_utc = ((double)tz) / 60.0; uint8_t result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &rise, &set); if (result != 0) { From 1cba812095a7c8cd8c718952ddf251c710ef0f02 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Fri, 18 Oct 2024 14:47:07 -0400 Subject: [PATCH 9/9] Bug fix with not showing "Always" on start and end screens --- .../watch_faces/settings/preferences_face.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/movement/watch_faces/settings/preferences_face.c b/movement/watch_faces/settings/preferences_face.c index c9d75c6df..e8104155a 100644 --- a/movement/watch_faces/settings/preferences_face.c +++ b/movement/watch_faces/settings/preferences_face.c @@ -55,12 +55,15 @@ void preferences_face_activate(movement_settings_t *settings, void *context) { movement_request_tick_frequency(4); // we need to manually blink some pixels } -static void _watch_display_hourly_chime_string(movement_settings_t *settings, uint8_t hour){ +static void _watch_display_hourly_chime_string(movement_settings_t *settings, uint8_t hour, uint8_t hour_bit, char *sun_string){ char buf[6]; - if (settings->bit.hourly_chime_always){ + if (settings->bit.hourly_chime_always) { watch_clear_indicator(WATCH_INDICATOR_PM); watch_display_string(" Always", 4); } + else if (hour_bit == 3 && watch_get_backup_data(1)) { + watch_display_string(sun_string, 4); + } else{ if (!settings->bit.clock_mode_24h) { // if we are in 12 hour mode, do some cleanup. @@ -217,16 +220,10 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings } break; case 4: - if (watch_get_backup_data(1) && settings->bit.hourly_chime_start == 3) - watch_display_string("SUNRIS", 4); - else - _watch_display_hourly_chime_string(settings, Hourly_Chime_Start[settings->bit.hourly_chime_start]); + _watch_display_hourly_chime_string(settings, Hourly_Chime_Start[settings->bit.hourly_chime_start], settings->bit.hourly_chime_start, "SUNRIS"); break; case 5: - if (watch_get_backup_data(1) && settings->bit.hourly_chime_end == 3) - watch_display_string("SUNSET", 4); - else - _watch_display_hourly_chime_string(settings, Hourly_Chime_End[settings->bit.hourly_chime_end]); + _watch_display_hourly_chime_string(settings, Hourly_Chime_End[settings->bit.hourly_chime_end], settings->bit.hourly_chime_end, "SUNSET"); break; case 6: if (settings->bit.led_duration) {