]> git.earman.xyz Git - sensor-watch.git/commitdiff
Fix faces that relied on watch_buzzer_play_note being blocking
authorAlessandro Genova <ales.genova@gmail.com>
Mon, 18 Aug 2025 03:35:15 +0000 (23:35 -0400)
committerAlessandro Genova <ales.genova@gmail.com>
Sat, 3 Jan 2026 01:07:56 +0000 (20:07 -0500)
watch-faces/complication/advanced_alarm_face.c
watch-faces/complication/deadline_face.c
watch-faces/complication/simon_face.c
watch-faces/complication/tally_face.c

index 16bfdbce34a3308225beec31672d5e3b72183383..4e5d9eb90435f21686cb8fff65231fdb411ec4bd 100644 (file)
@@ -202,9 +202,16 @@ static void _alarm_update_alarm_enabled(alarm_state_t *state) {
 
 static void _alarm_play_short_beep(uint8_t pitch_idx) {
     // play a short double beep
-    watch_buzzer_play_note(_buzzer_notes[pitch_idx], 50);
-    watch_buzzer_play_note(BUZZER_NOTE_REST, 50);
-    watch_buzzer_play_note(_buzzer_notes[pitch_idx], 70);
+    static int8_t beep_sequence[] = {
+        0, 4,
+        BUZZER_NOTE_REST, 4,
+        0, 6,
+        0
+    };
+    beep_sequence[0] = _buzzer_notes[pitch_idx];
+    beep_sequence[4] = _buzzer_notes[pitch_idx];
+
+    movement_play_sequence(beep_sequence, 0);
 }
 
 static void _alarm_indicate_beep(alarm_state_t *state) {
@@ -437,14 +444,7 @@ bool advanced_alarm_face_loop(movement_event_t event, void *context) {
         // play alarm
         if (state->alarm[state->alarm_playing_idx].beeps == 0) {
             // short beep
-            if (watch_is_buzzer_or_led_enabled()) {
-                _alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch);
-            } else {
-                // enable, play beep and disable buzzer again
-                watch_enable_buzzer();
-                _alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch);
-                watch_disable_buzzer();
-            }
+            _alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch);
         } else {
             // regular alarm beeps
             movement_play_alarm_beeps((state->alarm[state->alarm_playing_idx].beeps == (ALARM_MAX_BEEP_ROUNDS - 1) ? 20 : state->alarm[state->alarm_playing_idx].beeps), 
index b145a6186f1dbb346c58f2876323f2cf3a3cff76..ebad0e8bfadc2c0b4dde0c0b984ec06be73f3792 100644 (file)
@@ -82,26 +82,36 @@ static inline int _days_in_month(int16_t month, int16_t year)
 /* Play beep sound based on type */
 static inline void _beep(beep_type_t beep_type)
 {
+    static int8_t beep_sequence[] = {
+        0, 4,
+        0, 6,
+        0, 6,
+        0
+    };
+
     if (!movement_button_should_sound())
         return;
 
     switch (beep_type) {
         case BEEP_BUTTON:
-            watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, movement_button_volume());
+            beep_sequence[0] = BUZZER_NOTE_C7;
+            beep_sequence[2] = 0;
             break;
 
         case BEEP_ENABLE:
-            watch_buzzer_play_note_with_volume(BUZZER_NOTE_G7, 50, movement_button_volume());
-            watch_buzzer_play_note(BUZZER_NOTE_REST, 75);
-            watch_buzzer_play_note_with_volume(BUZZER_NOTE_C8, 50, movement_button_volume());
+            beep_sequence[0] = BUZZER_NOTE_G7;
+            beep_sequence[2] = BUZZER_NOTE_REST;
+            beep_sequence[4] = BUZZER_NOTE_C8;
             break;
 
         case BEEP_DISABLE:
-            watch_buzzer_play_note_with_volume(BUZZER_NOTE_C8, 50, movement_button_volume());
-            watch_buzzer_play_note(BUZZER_NOTE_REST, 75);
-            watch_buzzer_play_note_with_volume(BUZZER_NOTE_G7, 50, movement_button_volume());
+            beep_sequence[0] = BUZZER_NOTE_C8;
+            beep_sequence[2] = BUZZER_NOTE_REST;
+            beep_sequence[4] = BUZZER_NOTE_G7;
             break;
     }
+
+    movement_play_sequence(beep_sequence, 0);
 }
 
 /* Change tick frequency */
index 642b32a2e6faf08351938cfe1a5ca678e6625bf0..7b54f12f319ef6f438e5d05fb6e7bf76b771678e 100644 (file)
@@ -119,30 +119,22 @@ static void _simon_play_note(SimonNote note, simon_state_t *state, bool skip_res
     switch (note) {
         case SIMON_LED_NOTE:
             if (!state->lightOff) watch_set_led_yellow();
-            if (state->soundOff)
-                delay_ms(_delay_beep);
-            else
-                watch_buzzer_play_note(BUZZER_NOTE_D3, _delay_beep);
+            if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_D3, _delay_beep);
+            delay_ms(_delay_beep);
             break;
         case SIMON_MODE_NOTE:
             if (!state->lightOff) watch_set_led_red();
-            if (state->soundOff)
-                delay_ms(_delay_beep);
-            else
-               watch_buzzer_play_note(BUZZER_NOTE_E4, _delay_beep);
+            if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_E4, _delay_beep);
+            delay_ms(_delay_beep);
             break;
         case SIMON_ALARM_NOTE:
             if (!state->lightOff) watch_set_led_green();
-            if (state->soundOff)
-                delay_ms(_delay_beep);
-            else
-               watch_buzzer_play_note(BUZZER_NOTE_C3, _delay_beep);
+            if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_C3, _delay_beep);
+            delay_ms(_delay_beep);
             break;
         case SIMON_WRONG_NOTE:
-            if (state->soundOff)
-                delay_ms(800);
-            else
-               watch_buzzer_play_note(BUZZER_NOTE_A1, 800);
+            if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_A1, 800);
+            delay_ms(800);
             break;
     }
     watch_set_led_off();
@@ -150,7 +142,7 @@ static void _simon_play_note(SimonNote note, simon_state_t *state, bool skip_res
     if (note != SIMON_WRONG_NOTE) {
         _simon_clear_display(state);
         if (!skip_rest) {
-            watch_buzzer_play_note(BUZZER_NOTE_REST, (_delay_beep * 2)/3);
+            delay_ms((_delay_beep * 2)/3);
         }
     }
 }
index deb5b878a737f8dc222881c1124c25ebc0734c12..ec217954578b682e3971078f05625a46be48202f 100644 (file)
@@ -110,6 +110,12 @@ static bool tally_face_should_move_back(tally_state_t *state) {
 bool tally_face_loop(movement_event_t event, void *context) {
     tally_state_t *state = (tally_state_t *)context;
     static bool using_led = false;
+    static int8_t beep_sequence[] = {
+        0, 2,
+        BUZZER_NOTE_REST, 3,
+        0, 2,
+        0
+    };
 
     if (using_led) {
         if(!HAL_GPIO_BTN_MODE_read() && !HAL_GPIO_BTN_LIGHT_read() && !HAL_GPIO_BTN_ALARM_read())
@@ -148,9 +154,11 @@ bool tally_face_loop(movement_event_t event, void *context) {
                 state->tally_idx = _tally_default[state->tally_default_idx]; // reset tally index
                 _init_val = true;
                 //play a reset tune
-                if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
-                if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
-                if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
+                if (movement_button_should_sound()) {
+                    beep_sequence[0] = BUZZER_NOTE_G6;
+                    beep_sequence[4] = BUZZER_NOTE_E6;
+                    movement_play_sequence(beep_sequence, 0);
+                }
                 print_tally(state, movement_button_should_sound());
             }
             break;
@@ -168,9 +176,11 @@ bool tally_face_loop(movement_event_t event, void *context) {
             if (TALLY_FACE_PRESETS_SIZE() > 1 && _init_val){
                 state->tally_default_idx = (state->tally_default_idx + 1) % TALLY_FACE_PRESETS_SIZE();
                 state->tally_idx = _tally_default[state->tally_default_idx];
-                if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
-                if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
-                if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
+                if (movement_button_should_sound()) {
+                    beep_sequence[0] = BUZZER_NOTE_E6;
+                    beep_sequence[4] = BUZZER_NOTE_G6;
+                    movement_play_sequence(beep_sequence, 0);
+                }
                 print_tally(state, movement_button_should_sound());
             }
             else{