From 6f4917a0d5828dac8751c02e700f30e355f22c87 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Mon, 13 Nov 2023 00:14:41 -0500 Subject: Revert "Merge pull request #283 from neutralinsomniac/fix_hourly_chime_background" This reverts commit 5c94111ea20e50cb9dab8f416603403185e933b3, reversing changes made to bc9b4ce700d3f12adc0daceaa880e3d638df0c2b. --- movement/movement.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'movement/movement.c') 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) { -- cgit v1.2.3 From 3ee32c6e57e9a741355251f33fbcc323ded249d8 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Mon, 13 Nov 2023 00:16:13 -0500 Subject: 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 +++++++ 1 file changed, 7 insertions(+) (limited to 'movement/movement.c') 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) { -- cgit v1.2.3 From e9fe4aeefe7e56d637f7fbf35772f5bb37aff911 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Mon, 13 Nov 2023 00:48:57 -0500 Subject: 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 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'movement/movement.c') 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) { -- cgit v1.2.3 From aa3a1eeeef983b79ba8ebfe0e538d0addf983347 Mon Sep 17 00:00:00 2001 From: Alex Maestas Date: Tue, 9 Jan 2024 16:24:11 -0500 Subject: movement: Use LE mode code to keep buzzer awake, instead of sleeping. --- movement/movement.c | 62 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 26 deletions(-) (limited to 'movement/movement.c') 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; } -- cgit v1.2.3