]> git.earman.xyz Git - sensor-watch.git/commitdiff
Fix bug that was causing notes in a sequence to play too long
authorAlessandro Genova <ales.genova@gmail.com>
Tue, 19 Aug 2025 04:00:51 +0000 (00:00 -0400)
committerAlessandro Genova <ales.genova@gmail.com>
Sat, 3 Jan 2026 01:07:56 +0000 (20:07 -0500)
movement.c
watch-library/hardware/watch/watch_tcc.c
watch-library/simulator/watch/watch_tcc.c

index f52050e054d4b14285c6c3452b1dbdb246577602..d13146e97301e3ea5f50bf7b88dd2aae158bd469 100644 (file)
@@ -103,13 +103,13 @@ static int8_t *_pending_sequence;
 // The note sequence of the default alarm
 int8_t alarm_tune[] = {
     BUZZER_NOTE_C8, 4,
-    BUZZER_NOTE_REST, 4,
+    BUZZER_NOTE_REST, 7,
     BUZZER_NOTE_C8, 4,
-    BUZZER_NOTE_REST, 4,
+    BUZZER_NOTE_REST, 7,
     BUZZER_NOTE_C8, 4,
-    BUZZER_NOTE_REST, 4,
-    BUZZER_NOTE_C8, 6,
-    BUZZER_NOTE_REST, 18,
+    BUZZER_NOTE_REST, 7,
+    BUZZER_NOTE_C8, 4,
+    BUZZER_NOTE_REST, 27,
     -8, 9,
     0
 };
@@ -505,9 +505,9 @@ void movement_play_note(watch_buzzer_note_t note, uint16_t duration_ms) {
     static int8_t single_note_sequence[3];
 
     single_note_sequence[0] = note;
-    // 48 ticks per second for the tc0?
-    // Each tick is approximately 20ms
-    uint16_t duration = duration_ms / 20;
+    // 64 ticks per second for the tc0
+    // Each tick is approximately 15ms
+    uint16_t duration = duration_ms / 15;
     if (duration > 127) duration = 127;
     single_note_sequence[1] = (int8_t)duration;
     single_note_sequence[2] = 0;
index cde3c0dd6f2cc374e43a8dd24f5a815da60adc51..07f3126c43907c91295d2f7e86d8e1ba6ea0ba0f 100644 (file)
@@ -139,7 +139,7 @@ void cb_watch_buzzer_seq(void) {
                 watch_set_buzzer_on();
             } else watch_set_buzzer_off();
             // set duration ticks and move to next tone
-            _tone_ticks = _sequence[_seq_position + 1];
+            _tone_ticks = _sequence[_seq_position + 1] - 1;
             _seq_position += 2;
         } else {
             // end the sequence
@@ -187,7 +187,7 @@ void cb_watch_buzzer_raw_source(void) {
     if (_tone_ticks == 0) {
         done = _raw_source(_seq_position, _userdata, &period, &duration);
 
-        if (done) {
+        if (done || duration == 0) {
             // end the sequence
             watch_buzzer_abort_sequence();
         } else {
@@ -199,7 +199,7 @@ void cb_watch_buzzer_raw_source(void) {
             }
 
             // set duration ticks and move to next tone
-            _tone_ticks = duration;
+            _tone_ticks = duration - 1;
             _seq_position += 1;
         }
     } else {
@@ -305,9 +305,9 @@ void watch_buzzer_play_note_with_volume(watch_buzzer_note_t note, uint16_t durat
     static int8_t single_note_sequence[3];
 
     single_note_sequence[0] = note;
-    // 48 ticks per second for the tc0?
-    // Each tick is approximately 20ms
-    uint16_t duration = duration_ms / 20;
+    // 64 ticks per second for the tc0
+    // Each tick is approximately 15ms
+    uint16_t duration = duration_ms / 15;
     if (duration > 127) duration = 127;
     single_note_sequence[1] = (int8_t)duration;
     single_note_sequence[2] = 0;
index 6cbf98226564d666dfc1369d4a5cbde2824f43bf..e90b76133c9937ffb8c80e118e588f4313ab7f43 100644 (file)
@@ -110,7 +110,7 @@ void cb_watch_buzzer_seq(void *userData) {
                 watch_set_buzzer_on();
             }
             // set duration ticks and move to next tone
-            _tone_ticks = _sequence[_seq_position + 1];
+            _tone_ticks = _sequence[_seq_position + 1] - 1;
             _seq_position += 2;
         } else {
             // end the sequence
@@ -157,7 +157,7 @@ void cb_watch_buzzer_raw_source(void *userData) {
     if (_tone_ticks == 0) {
         done = _raw_source(_seq_position, _userdata, &period, &duration);
 
-        if (done) {
+        if (done || duration == 0) {
             // end the sequence
             watch_buzzer_abort_sequence();
         } else {
@@ -169,7 +169,7 @@ void cb_watch_buzzer_raw_source(void *userData) {
             }
 
             // set duration ticks and move to next tone
-            _tone_ticks = duration;
+            _tone_ticks = duration - 1;
             _seq_position += 1;
         }
     } else {
@@ -272,7 +272,7 @@ void watch_buzzer_play_note_with_volume(watch_buzzer_note_t note, uint16_t durat
     static int8_t single_note_sequence[3];
 
     single_note_sequence[0] = note;
-    // 64 ticks per second for the tc0?
+    // 64 ticks per second for the tc0
     // Each tick is approximately 15ms
     uint16_t duration = duration_ms / 15;
     if (duration > 127) duration = 127;