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.
This commit is contained in:
Wesley Aptekar-Cassels 2023-11-13 00:48:57 -05:00
parent 3ee32c6e57
commit e9fe4aeefe
8 changed files with 41 additions and 54 deletions

View file

@ -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) {

View file

@ -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_

View file

@ -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:
/*

View file

@ -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) {

View file

@ -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);

View file

@ -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);

View file

@ -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) {

View file

@ -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);