From fe0a64da8089076df5357442fddb771af17209a0 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 4 Jun 2025 19:04:48 -0500 Subject: [PATCH] Boop boop boop boop --- src/ButtonThread.cpp | 23 +++++++++++++++++++---- src/ButtonThread.h | 4 +++- src/buzz/buzz.cpp | 29 +++++++++++++++++++++++++++++ src/buzz/buzz.h | 4 +++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index a423b4f36..4c6a7d4c4 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -229,18 +229,33 @@ int32_t ButtonThread::runOnce() if (buttonCurrentlyPressed && !buttonWasPressed) { buttonPressStartTime = millis(); leadUpPlayed = false; + leadUpSequenceActive = false; + resetLeadUpSequence(); } - // Check if we should play lead-up sound - if (buttonCurrentlyPressed && !leadUpPlayed && (millis() - buttonPressStartTime) >= BUTTON_LEADUP_MS && + // Progressive lead-up sound system + if (buttonCurrentlyPressed && (millis() - buttonPressStartTime) >= BUTTON_LEADUP_MS && (millis() - buttonPressStartTime) < BUTTON_LONGPRESS_MS) { - playLongPressLeadUp(); - leadUpPlayed = true; + + // Start the progressive sequence if not already active + if (!leadUpSequenceActive) { + leadUpSequenceActive = true; + lastLeadUpNoteTime = millis(); + playNextLeadUpNote(); // Play the first note immediately + } + // Continue playing notes at intervals + else if ((millis() - lastLeadUpNoteTime) >= 400) { // 400ms interval between notes + if (playNextLeadUpNote()) { + lastLeadUpNoteTime = millis(); + } + } } // Reset when button is released if (!buttonCurrentlyPressed && buttonWasPressed) { leadUpPlayed = false; + leadUpSequenceActive = false; + resetLeadUpSequence(); } buttonWasPressed = buttonCurrentlyPressed; diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 05fa46892..1fbc38672 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -21,7 +21,7 @@ #endif #ifndef BUTTON_LEADUP_MS -#define BUTTON_LEADUP_MS 2500 // Play lead-up sound after 2.5 seconds of holding +#define BUTTON_LEADUP_MS 2200 // Play lead-up sound after 2.5 seconds of holding #endif class ButtonThread : public concurrency::OSThread @@ -97,6 +97,8 @@ class ButtonThread : public concurrency::OSThread // Long press lead-up tracking bool leadUpPlayed = false; + uint32_t lastLeadUpNoteTime = 0; + bool leadUpSequenceActive = false; static void wakeOnIrq(int irq, int mode); diff --git a/src/buzz/buzz.cpp b/src/buzz/buzz.cpp index 8c7d4ec2b..fc113dcae 100644 --- a/src/buzz/buzz.cpp +++ b/src/buzz/buzz.cpp @@ -107,6 +107,35 @@ void playLongPressLeadUp() playTones(melody, sizeof(melody) / sizeof(ToneDuration)); } +// Static state for progressive lead-up notes +static int leadUpNoteIndex = 0; +static const ToneDuration leadUpNotes[] = { + {NOTE_C3, 100}, // Start low + {NOTE_E3, 100}, // Step up + {NOTE_G3, 100}, // Keep climbing + {NOTE_B3, 150} // Peak with longer note for emphasis +}; +static const int leadUpNotesCount = sizeof(leadUpNotes) / sizeof(ToneDuration); + +bool playNextLeadUpNote() +{ + if (leadUpNoteIndex >= leadUpNotesCount) { + return false; // All notes have been played + } + + // Use playTones to handle buzzer logic consistently + const auto ¬e = leadUpNotes[leadUpNoteIndex]; + playTones(¬e, 1); // Play single note using existing playTones function + + leadUpNoteIndex++; + return true; // Note was played (playTones handles buzzer availability internally) +} + +void resetLeadUpSequence() +{ + leadUpNoteIndex = 0; +} + void playComboTune() { // Quick high-pitched notes with trills diff --git a/src/buzz/buzz.h b/src/buzz/buzz.h index 75afe6d90..4b7302383 100644 --- a/src/buzz/buzz.h +++ b/src/buzz/buzz.h @@ -8,4 +8,6 @@ void playGPSEnableBeep(); void playGPSDisableBeep(); void playComboTune(); void playBoop(); -void playLongPressLeadUp(); \ No newline at end of file +void playLongPressLeadUp(); +bool playNextLeadUpNote(); // Play the next note in the lead-up sequence +void resetLeadUpSequence(); // Reset the lead-up sequence to start from beginning \ No newline at end of file