From f534e7c202f08c0b666c78dd2fd5295cbec81bcd Mon Sep 17 00:00:00 2001 From: Alessandro Genova Date: Tue, 19 Aug 2025 00:00:51 -0400 Subject: [PATCH] Fix bug that was causing notes in a sequence to play too long --- movement.c | 16 ++++++++-------- watch-library/hardware/watch/watch_tcc.c | 12 ++++++------ watch-library/simulator/watch/watch_tcc.c | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/movement.c b/movement.c index f52050e0..d13146e9 100644 --- a/movement.c +++ b/movement.c @@ -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; diff --git a/watch-library/hardware/watch/watch_tcc.c b/watch-library/hardware/watch/watch_tcc.c index cde3c0dd..07f3126c 100644 --- a/watch-library/hardware/watch/watch_tcc.c +++ b/watch-library/hardware/watch/watch_tcc.c @@ -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; diff --git a/watch-library/simulator/watch/watch_tcc.c b/watch-library/simulator/watch/watch_tcc.c index 6cbf9822..e90b7613 100644 --- a/watch-library/simulator/watch/watch_tcc.c +++ b/watch-library/simulator/watch/watch_tcc.c @@ -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;