From 399679ac597969d4e2a5487cd8bab7a687575928 Mon Sep 17 00:00:00 2001 From: Alex Maestas Date: Fri, 22 Dec 2023 22:35:46 +0000 Subject: [PATCH 1/9] delete stray line of code that messed with correction profile while adjusting cadence --- movement/watch_faces/settings/nanosec_face.c | 1 - 1 file changed, 1 deletion(-) diff --git a/movement/watch_faces/settings/nanosec_face.c b/movement/watch_faces/settings/nanosec_face.c index 72fdb729..37dd08ef 100644 --- a/movement/watch_faces/settings/nanosec_face.c +++ b/movement/watch_faces/settings/nanosec_face.c @@ -245,7 +245,6 @@ static void value_increase(int16_t delta) { nanosec_state.correction_cadence = (delta > 0) ? 1 : 20; break; } - nanosec_state.correction_profile = (nanosec_state.correction_profile + delta) % nanosec_profile_count; break; case 6: // Aging nanosec_state.aging_ppm_pa += delta; From 8e0e942573407ffe9901cb1a2ee5ac4cf911f37c Mon Sep 17 00:00:00 2001 From: "Pietro F. Maggi" Date: Sun, 7 Jan 2024 12:40:42 +0100 Subject: [PATCH 2/9] Handle visibility for tomato watchface (cherry picked from commit 547e8248ba3538693ee8c587a92ffece7b40d1a2) --- movement/watch_faces/complication/tomato_face.c | 10 ++++++++-- movement/watch_faces/complication/tomato_face.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/complication/tomato_face.c b/movement/watch_faces/complication/tomato_face.c index 698301e1..3d46ba94 100644 --- a/movement/watch_faces/complication/tomato_face.c +++ b/movement/watch_faces/complication/tomato_face.c @@ -84,8 +84,10 @@ static void tomato_draw(tomato_state_t *state) { sec = 0; break; } - sprintf(buf, "TO %c%2d%02d%2d", kind, min, sec, state->done_count); - watch_display_string(buf, 0); + if (state->visible) { + sprintf(buf, "TO %c%2d%02d%2d", kind, min, sec, state->done_count); + watch_display_string(buf, 0); + } } static void tomato_reset(tomato_state_t *state) { @@ -116,6 +118,7 @@ void tomato_face_setup(movement_settings_t *settings, uint8_t watch_face_index, state->mode=tomato_ready; state->kind= tomato_focus; state->done_count = 0; + state->visible = true; } } @@ -127,6 +130,7 @@ void tomato_face_activate(movement_settings_t *settings, void *context) { watch_set_indicator(WATCH_INDICATOR_BELL); } watch_set_colon(); + state->visible = true; } bool tomato_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { @@ -184,6 +188,8 @@ bool tomato_face_loop(movement_event_t event, movement_settings_t *settings, voi } void tomato_face_resign(movement_settings_t *settings, void *context) { + tomato_state_t *state = (tomato_state_t *)context; + state->visible = false; (void) settings; (void) context; } diff --git a/movement/watch_faces/complication/tomato_face.h b/movement/watch_faces/complication/tomato_face.h index 33a086c6..25f7db0e 100644 --- a/movement/watch_faces/complication/tomato_face.h +++ b/movement/watch_faces/complication/tomato_face.h @@ -64,6 +64,7 @@ typedef struct { tomato_mode mode; tomato_kind kind; uint8_t done_count; + bool visible; } tomato_state_t; void tomato_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); From 6f4917a0d5828dac8751c02e700f30e355f22c87 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Mon, 13 Nov 2023 00:14:41 -0500 Subject: [PATCH 3/9] Revert "Merge pull request #283 from neutralinsomniac/fix_hourly_chime_background" This reverts commit 5c94111ea20e50cb9dab8f416603403185e933b3, reversing changes made to bc9b4ce700d3f12adc0daceaa880e3d638df0c2b. --- movement/movement.c | 20 +------------------ movement/movement.h | 1 - .../clock/repetition_minute_face.c | 14 ++++++++++++- .../clock/simple_clock_bin_led_face.c | 12 ++++++++++- .../watch_faces/clock/simple_clock_face.c | 16 ++++++++++----- .../watch_faces/clock/weeknumber_clock_face.c | 12 ++++++++++- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index f0868416..0c6ed319 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -294,25 +294,7 @@ void movement_request_wake() { } void movement_play_signal(void) { - bool buzzer_enabled = watch_is_buzzer_or_led_enabled(); - if (!buzzer_enabled) { - watch_enable_buzzer(); - } - watch_buzzer_play_note(BUZZER_NOTE_C8, 75); - watch_buzzer_play_note(BUZZER_NOTE_REST, 100); - watch_buzzer_play_note(BUZZER_NOTE_C8, 100); - if (!buzzer_enabled) { - watch_disable_buzzer(); - } -} - -void movement_play_tune(void) { - if (!watch_is_buzzer_or_led_enabled()) { - watch_enable_buzzer(); - watch_buzzer_play_sequence(signal_tune, watch_disable_buzzer); - } else { - watch_buzzer_play_sequence(signal_tune, NULL); - } + watch_buzzer_play_sequence(signal_tune, NULL); } void movement_play_alarm(void) { diff --git a/movement/movement.h b/movement/movement.h index 5f30dfb8..66bf6af4 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -307,7 +307,6 @@ void movement_cancel_background_task_for_face(uint8_t watch_face_index); void movement_request_wake(void); void movement_play_signal(void); -void movement_play_tune(void); void movement_play_alarm(void); void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note); diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index fc78b2d8..a0fbe077 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -151,7 +151,19 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se else watch_clear_indicator(WATCH_INDICATOR_BELL); break; case EVENT_BACKGROUND_TASK: - movement_play_signal(); + // uncomment this line to snap back to the clock face when the hour signal sounds: + // movement_move_to_face(state->watch_face_index); + if (watch_is_buzzer_or_led_enabled()) { + // if we are in the foreground, we can just beep. + movement_play_signal(); + } else { + // if we were in the background, we need to enable the buzzer peripheral first, + watch_enable_buzzer(); + // beep quickly (this call blocks for 275 ms), + movement_play_signal(); + // and then turn the buzzer peripheral off again. + watch_disable_buzzer(); + } break; case EVENT_LIGHT_LONG_UP: /* 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 cf39c188..640f0d77 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -180,7 +180,17 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - movement_play_signal(); + if (watch_is_buzzer_or_led_enabled()) { + // if we are in the foreground, we can just beep. + movement_play_signal(); + } else { + // if we were in the background, we need to enable the buzzer peripheral first, + watch_enable_buzzer(); + // beep quickly (this call blocks for 275 ms), + movement_play_signal(); + // and then turn the buzzer peripheral off again. + watch_disable_buzzer(); + } break; case EVENT_LIGHT_LONG_PRESS: if (state->flashing_state == 0) { diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index ac9a97b2..91400b6c 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -136,11 +136,17 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - #ifdef SIGNAL_TUNE_DEFAULT - movement_play_signal(); - #else - movement_play_tune(); - #endif + if (watch_is_buzzer_or_led_enabled()) { + // if we are in the foreground, we can just beep. + movement_play_signal(); + } else { + // if we were in the background, we need to enable the buzzer peripheral first, + watch_enable_buzzer(); + // beep quickly (this call blocks for 275 ms), + movement_play_signal(); + // and then turn the buzzer peripheral off again. + watch_disable_buzzer(); + } break; default: return movement_default_loop_handler(event, settings); diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 81df5847..4e40ebdc 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -130,7 +130,17 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - movement_play_signal(); + if (watch_is_buzzer_or_led_enabled()) { + // if we are in the foreground, we can just beep. + movement_play_signal(); + } else { + // if we were in the background, we need to enable the buzzer peripheral first, + watch_enable_buzzer(); + // beep quickly (this call blocks for 275 ms), + movement_play_signal(); + // and then turn the buzzer peripheral off again. + watch_disable_buzzer(); + } break; default: movement_default_loop_handler(event, settings); From 3ee32c6e57e9a741355251f33fbcc323ded249d8 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Mon, 13 Nov 2023 00:16:13 -0500 Subject: [PATCH 4/9] Use legacy buzzer functions when playing default tune. This allows the default tune to be played in LE mode. Fixes: #275 --- movement/movement.c | 7 +++++++ movement/movement_config.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/movement/movement.c b/movement/movement.c index 0c6ed319..235716c8 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -294,7 +294,14 @@ void movement_request_wake() { } void movement_play_signal(void) { +#ifdef SIGNAL_TUNE_DEFAULT + watch_buzzer_play_note(BUZZER_NOTE_C8, 75); + watch_buzzer_play_note(BUZZER_NOTE_REST, 100); + watch_buzzer_play_note(BUZZER_NOTE_C8, 100); +#else + // Does not work in LE mode. watch_buzzer_play_sequence(signal_tune, NULL); +#endif // SIGNAL_TUNE_DEFAULT } void movement_play_alarm(void) { diff --git a/movement/movement_config.h b/movement/movement_config.h index 6a7f87e0..bafbc5e5 100644 --- a/movement/movement_config.h +++ b/movement/movement_config.h @@ -49,7 +49,8 @@ const watch_face_t watch_faces[] = { */ #define MOVEMENT_SECONDARY_FACE_INDEX (MOVEMENT_NUM_FACES - 2) // or (0) -/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options */ +/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. + * Custom tunes do not currently work in LE mode. */ #define SIGNAL_TUNE_DEFAULT #endif // MOVEMENT_CONFIG_H_ From e9fe4aeefe7e56d637f7fbf35772f5bb37aff911 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Mon, 13 Nov 2023 00:48:57 -0500 Subject: [PATCH 5/9] Enable custom signal tones in LE mode. This makes movement_play_signal synchronous when in LE mode, despite using the underlying asynchronous API. It's a bit of a hack, but it should work well enough for now. This also moves the enabling/disabling of the buzzer into the movement_play_signal function, so that watch faces no longer have to do it. --- movement/movement.c | 33 ++++++++++++++----- movement/movement_config.h | 3 +- .../clock/repetition_minute_face.c | 12 +------ .../clock/simple_clock_bin_led_face.c | 12 +------ .../watch_faces/clock/simple_clock_face.c | 12 +------ .../watch_faces/clock/weeknumber_clock_face.c | 12 +------ watch-library/hardware/watch/watch_buzzer.c | 9 +++++ watch-library/shared/watch/watch_buzzer.h | 2 ++ 8 files changed, 41 insertions(+), 54 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index 235716c8..0e40d462 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -294,14 +294,31 @@ void movement_request_wake() { } void movement_play_signal(void) { -#ifdef SIGNAL_TUNE_DEFAULT - watch_buzzer_play_note(BUZZER_NOTE_C8, 75); - watch_buzzer_play_note(BUZZER_NOTE_REST, 100); - watch_buzzer_play_note(BUZZER_NOTE_C8, 100); -#else - // Does not work in LE mode. - watch_buzzer_play_sequence(signal_tune, NULL); -#endif // SIGNAL_TUNE_DEFAULT + watch_enable_buzzer(); + watch_buzzer_play_sequence(signal_tune, watch_disable_buzzer); + if (movement_state.le_mode_ticks == -1) { + // This is somewhat of a hack. In order to play a sequence, we need to + // be awake. We should ideally be able to tell movement that we need to + // be awake for a given amount of time, but there's no good way to do + // this, so we block instead. This might be bad in the case that a + // watch face has housekeeping to do after calling this, since it could + // in theory do that housekeeping concurrently, but alas. + // + // You might wonder, why not just put the instruction to go back to + // sleep in the callback? It's a good idea, but I can't figure out how + // to get it to work - you're basically kicking the can down the road, + // since at some point movement will be done doing what it's doing and + // have to wait. At that point, you're delaying anyways, but it's + // harder to figure out how much time to delay for, since you don't + // know how much time has elapsed since starting the sequence. I'd + // rather this block than have to read from the RTC to figure that + // out. + // + // Don't ask me what the +50ms is doing. The sequence gets cut short + // with the exact time, I have no idea why. 50 extra millisecons seems + // like a safe value. + delay_ms(sequence_length(signal_tune) * 1000 / 64 + 50); + } } void movement_play_alarm(void) { diff --git a/movement/movement_config.h b/movement/movement_config.h index bafbc5e5..067ca44b 100644 --- a/movement/movement_config.h +++ b/movement/movement_config.h @@ -49,8 +49,7 @@ const watch_face_t watch_faces[] = { */ #define MOVEMENT_SECONDARY_FACE_INDEX (MOVEMENT_NUM_FACES - 2) // or (0) -/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. - * Custom tunes do not currently work in LE mode. */ +/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. */ #define SIGNAL_TUNE_DEFAULT #endif // MOVEMENT_CONFIG_H_ diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index a0fbe077..e9e5e319 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -153,17 +153,7 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - if (watch_is_buzzer_or_led_enabled()) { - // if we are in the foreground, we can just beep. - movement_play_signal(); - } else { - // if we were in the background, we need to enable the buzzer peripheral first, - watch_enable_buzzer(); - // beep quickly (this call blocks for 275 ms), - movement_play_signal(); - // and then turn the buzzer peripheral off again. - watch_disable_buzzer(); - } + movement_play_signal(); break; case EVENT_LIGHT_LONG_UP: /* 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 640f0d77..cf39c188 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -180,17 +180,7 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - if (watch_is_buzzer_or_led_enabled()) { - // if we are in the foreground, we can just beep. - movement_play_signal(); - } else { - // if we were in the background, we need to enable the buzzer peripheral first, - watch_enable_buzzer(); - // beep quickly (this call blocks for 275 ms), - movement_play_signal(); - // and then turn the buzzer peripheral off again. - watch_disable_buzzer(); - } + movement_play_signal(); break; case EVENT_LIGHT_LONG_PRESS: if (state->flashing_state == 0) { diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index 91400b6c..fbc2c4b3 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -136,17 +136,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - if (watch_is_buzzer_or_led_enabled()) { - // if we are in the foreground, we can just beep. - movement_play_signal(); - } else { - // if we were in the background, we need to enable the buzzer peripheral first, - watch_enable_buzzer(); - // beep quickly (this call blocks for 275 ms), - movement_play_signal(); - // and then turn the buzzer peripheral off again. - watch_disable_buzzer(); - } + movement_play_signal(); break; default: return movement_default_loop_handler(event, settings); diff --git a/movement/watch_faces/clock/weeknumber_clock_face.c b/movement/watch_faces/clock/weeknumber_clock_face.c index 4e40ebdc..81df5847 100644 --- a/movement/watch_faces/clock/weeknumber_clock_face.c +++ b/movement/watch_faces/clock/weeknumber_clock_face.c @@ -130,17 +130,7 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: // movement_move_to_face(state->watch_face_index); - if (watch_is_buzzer_or_led_enabled()) { - // if we are in the foreground, we can just beep. - movement_play_signal(); - } else { - // if we were in the background, we need to enable the buzzer peripheral first, - watch_enable_buzzer(); - // beep quickly (this call blocks for 275 ms), - movement_play_signal(); - // and then turn the buzzer peripheral off again. - watch_disable_buzzer(); - } + movement_play_signal(); break; default: movement_default_loop_handler(event, settings); diff --git a/watch-library/hardware/watch/watch_buzzer.c b/watch-library/hardware/watch/watch_buzzer.c index 18fb4db0..63506a51 100644 --- a/watch-library/hardware/watch/watch_buzzer.c +++ b/watch-library/hardware/watch/watch_buzzer.c @@ -90,6 +90,15 @@ void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(v _tc3_start(); } +uint16_t sequence_length(int8_t *sequence) { + uint16_t result = 0; + int i = 0; + while (sequence[i++]) { + result += sequence[i++]; + } + return result; +} + void cb_watch_buzzer_seq(void) { // callback for reading the note sequence if (_tone_ticks == 0) { diff --git a/watch-library/shared/watch/watch_buzzer.h b/watch-library/shared/watch/watch_buzzer.h index 7ba9a52e..4c39475c 100644 --- a/watch-library/shared/watch/watch_buzzer.h +++ b/watch-library/shared/watch/watch_buzzer.h @@ -175,6 +175,8 @@ extern const uint16_t NotePeriods[108]; */ void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(void)); +uint16_t sequence_length(int8_t *sequence); + /** @brief Aborts a playing sequence. */ void watch_buzzer_abort_sequence(void); From 50dccd07d3fe39f1a0f4648dd3812561d4a52974 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Wed, 15 Nov 2023 19:21:43 -0500 Subject: [PATCH 6/9] buzzer: fix simulator build, refactor sequence_length. --- watch-library/hardware/watch/watch_buzzer.c | 10 +----- .../shared/watch/watch_private_buzzer.c | 13 ++++++-- .../shared/watch/watch_private_buzzer.h | 33 +++++++++++++++++++ watch-library/simulator/watch/watch_buzzer.c | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 watch-library/shared/watch/watch_private_buzzer.h diff --git a/watch-library/hardware/watch/watch_buzzer.c b/watch-library/hardware/watch/watch_buzzer.c index 63506a51..2dce8d23 100644 --- a/watch-library/hardware/watch/watch_buzzer.c +++ b/watch-library/hardware/watch/watch_buzzer.c @@ -23,6 +23,7 @@ */ #include "watch_buzzer.h" +#include "watch_private_buzzer.h" #include "../../../watch-library/hardware/include/saml22j18a.h" #include "../../../watch-library/hardware/include/component/tc.h" #include "../../../watch-library/hardware/hri/hri_tc_l22.h" @@ -90,15 +91,6 @@ void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(v _tc3_start(); } -uint16_t sequence_length(int8_t *sequence) { - uint16_t result = 0; - int i = 0; - while (sequence[i++]) { - result += sequence[i++]; - } - return result; -} - void cb_watch_buzzer_seq(void) { // callback for reading the note sequence if (_tone_ticks == 0) { diff --git a/watch-library/shared/watch/watch_private_buzzer.c b/watch-library/shared/watch/watch_private_buzzer.c index 0618f425..def54a46 100644 --- a/watch-library/shared/watch/watch_private_buzzer.c +++ b/watch-library/shared/watch/watch_private_buzzer.c @@ -23,6 +23,13 @@ */ #include "driver_init.h" -// note: the buzzer uses a 1 MHz clock. these values were determined by dividing 1,000,000 by the target frequency. -// i.e. for a 440 Hz tone (A4 on the piano), 1MHz/440Hz = 2273 -const uint16_t NotePeriods[108] = {18182,17161,16197,15288,14430,13620,12857,12134,11453,10811,10204,9631,9091,8581,8099,7645,7216,6811,6428,6068,5727,5405,5102,4816,4545,4290,4050,3822,3608,3405,3214,3034,2863,2703,2551,2408,2273,2145,2025,1911,1804,1703,1607,1517,1432,1351,1276,1204,1136,1073,1012,956,902,851,804,758,716,676,638,602,568,536,506,478,451,426,402,379,358,338,319,301,284,268,253,239,225,213,201,190,179,169,159,150,142,134,127}; +uint16_t sequence_length(int8_t *sequence) { + uint16_t result = 0; + + while (*sequence != 0){ + result += *(sequence + 1); + sequence += 2; + } + + return result; +} diff --git a/watch-library/shared/watch/watch_private_buzzer.h b/watch-library/shared/watch/watch_private_buzzer.h new file mode 100644 index 00000000..3017bbb5 --- /dev/null +++ b/watch-library/shared/watch/watch_private_buzzer.h @@ -0,0 +1,33 @@ +/* + * MIT License + * + * Copyright (c) 2023 Wesley Aptekar-Cassels + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef _WATCH_PRIVATE_BUZZER_H_INCLUDED +#define _WATCH_PRIVATE_BUZZER_H_INCLUDED + +// note: the buzzer uses a 1 MHz clock. these values were determined by dividing 1,000,000 by the target frequency. +// i.e. for a 440 Hz tone (A4 on the piano), 1MHz/440Hz = 2273 +const uint16_t NotePeriods[108] = {18182,17161,16197,15288,14430,13620,12857,12134,11453,10811,10204,9631,9091,8581,8099,7645,7216,6811,6428,6068,5727,5405,5102,4816,4545,4290,4050,3822,3608,3405,3214,3034,2863,2703,2551,2408,2273,2145,2025,1911,1804,1703,1607,1517,1432,1351,1276,1204,1136,1073,1012,956,902,851,804,758,716,676,638,602,568,536,506,478,451,426,402,379,358,338,319,301,284,268,253,239,225,213,201,190,179,169,159,150,142,134,127}; + +uint16_t sequence_length(int8_t *sequence); + +#endif diff --git a/watch-library/simulator/watch/watch_buzzer.c b/watch-library/simulator/watch/watch_buzzer.c index 211235df..7ccb8545 100644 --- a/watch-library/simulator/watch/watch_buzzer.c +++ b/watch-library/simulator/watch/watch_buzzer.c @@ -23,6 +23,7 @@ */ #include "watch_buzzer.h" +#include "watch_private_buzzer.h" #include "watch_main_loop.h" #include From aa3a1eeeef983b79ba8ebfe0e538d0addf983347 Mon Sep 17 00:00:00 2001 From: Alex Maestas Date: Tue, 9 Jan 2024 16:24:11 -0500 Subject: [PATCH 7/9] movement: Use LE mode code to keep buzzer awake, instead of sleeping. --- movement/movement.c | 62 ++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index 0e40d462..2f4bec7f 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -293,31 +293,31 @@ void movement_request_wake() { _movement_reset_inactivity_countdown(); } +void end_buzzing() { + movement_state.is_buzzing = false; +} + +void end_buzzing_and_disable_buzzer(void) { + end_buzzing(); + watch_disable_buzzer(); +} + void movement_play_signal(void) { - watch_enable_buzzer(); - watch_buzzer_play_sequence(signal_tune, watch_disable_buzzer); + void *maybe_disable_buzzer = end_buzzing_and_disable_buzzer; + if (watch_is_buzzer_or_led_enabled()) { + maybe_disable_buzzer = end_buzzing; + } else { + watch_enable_buzzer(); + } + movement_state.is_buzzing = true; + watch_buzzer_play_sequence(signal_tune, maybe_disable_buzzer); if (movement_state.le_mode_ticks == -1) { - // This is somewhat of a hack. In order to play a sequence, we need to - // be awake. We should ideally be able to tell movement that we need to - // be awake for a given amount of time, but there's no good way to do - // this, so we block instead. This might be bad in the case that a - // watch face has housekeeping to do after calling this, since it could - // in theory do that housekeeping concurrently, but alas. - // - // You might wonder, why not just put the instruction to go back to - // sleep in the callback? It's a good idea, but I can't figure out how - // to get it to work - you're basically kicking the can down the road, - // since at some point movement will be done doing what it's doing and - // have to wait. At that point, you're delaying anyways, but it's - // harder to figure out how much time to delay for, since you don't - // know how much time has elapsed since starting the sequence. I'd - // rather this block than have to read from the RTC to figure that - // out. - // - // Don't ask me what the +50ms is doing. The sequence gets cut short - // with the exact time, I have no idea why. 50 extra millisecons seems - // like a safe value. - delay_ms(sequence_length(signal_tune) * 1000 / 64 + 50); + // the watch is asleep. wake it up for "1" round through the main loop. + // the sleep_mode_app_loop will notice the is_buzzing and note that it + // only woke up to beep and then it will spinlock until the callback + // turns off the is_buzzing flag. + movement_state.needs_wake = true; + movement_state.le_mode_ticks = 1; } } @@ -450,6 +450,7 @@ static void _sleep_mode_app_loop(void) { } bool app_loop(void) { + bool woke_up_for_buzzer = false; if (movement_state.watch_face_changed) { if (movement_state.settings.bit.button_should_sound) { // low note for nonzero case, high note for return to watch_face 0 @@ -493,7 +494,11 @@ bool app_loop(void) { // _sleep_mode_app_loop takes over at this point and loops until le_mode_ticks is reset by the extwake handler, // or wake is requested using the movement_request_wake function. _sleep_mode_app_loop(); - // as soon as _sleep_mode_app_loop returns, we reactivate ourselves. + // as soon as _sleep_mode_app_loop returns, we prepare to reactivate + // ourselves, but first, we check to see if we woke up for the buzzer: + if (movement_state.is_buzzing) { + woke_up_for_buzzer = true; + } event.event_type = EVENT_ACTIVATE; // this is a hack tho: waking from sleep mode, app_setup does get called, but it happens before we have reset our ticks. // need to figure out if there's a better heuristic for determining how we woke up. @@ -575,8 +580,13 @@ bool app_loop(void) { // if the watch face changed, we can't sleep because we need to update the display. if (movement_state.watch_face_changed) can_sleep = false; - // if the buzzer or the LED is on, we need to stay awake to keep the TCC running. - if (movement_state.is_buzzing || movement_state.light_ticks != -1) can_sleep = false; + // if we woke up for the buzzer, stay awake until it's finished. + if (woke_up_for_buzzer) { + while(watch_is_buzzer_or_led_enabled()); + } + + // if the LED is on, we need to stay awake to keep the TCC running. + if (movement_state.light_ticks != -1) can_sleep = false; return can_sleep; } From cd44cb74a2a3a058a2ff250797fd103f8a8d8423 Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Wed, 10 Jan 2024 09:38:33 -0500 Subject: [PATCH 8/9] fix alternate firmware script --- movement/make/make_alternate_fw.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/movement/make/make_alternate_fw.sh b/movement/make/make_alternate_fw.sh index c65e72d3..df27403f 100755 --- a/movement/make/make_alternate_fw.sh +++ b/movement/make/make_alternate_fw.sh @@ -21,12 +21,12 @@ do for color in "${colors[@]}" do COLOR=$(echo "$color" | tr '[:lower:]' '[:upper:]') - make clean + make COLOR=$COLOR clean make COLOR=$COLOR FIRMWARE=$VARIANT mv "build/watch.uf2" "$fw_dir/$variant-$color.uf2" done rm -rf ./build-sim - emmake make FIRMWARE=$VARIANT + emmake make COLOR=GREEN FIRMWARE=$VARIANT mkdir "$sim_dir/$variant/" mv "build-sim/watch.wasm" "$sim_dir/$variant/" mv "build-sim/watch.js" "$sim_dir/$variant/" From 6985ca54f31f5a825661c4e0fdf07622bbf1d07c Mon Sep 17 00:00:00 2001 From: CarpeNoctem Date: Wed, 17 Jan 2024 23:08:54 +1100 Subject: [PATCH 9/9] template: fix compiler warning on watch_face_index as mentioned in PR 269 --- movement/template/template.c | 1 + 1 file changed, 1 insertion(+) diff --git a/movement/template/template.c b/movement/template/template.c index e03db561..fe2723b8 100644 --- a/movement/template/template.c +++ b/movement/template/template.c @@ -28,6 +28,7 @@ void <#watch_face_name#>_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; + (void) watch_face_index; if (*context_ptr == NULL) { *context_ptr = malloc(sizeof(<#watch_face_name#>_state_t)); memset(*context_ptr, 0, sizeof(<#watch_face_name#>_state_t));