Improved Volume button handling, fix for music stopping
This commit is contained in:
parent
0a08709160
commit
22f8d3eec3
42
src/main.cpp
42
src/main.cpp
|
|
@ -78,6 +78,9 @@ DirectoryNode *currentNode = nullptr;
|
||||||
|
|
||||||
volatile bool newRfidInt = false;
|
volatile bool newRfidInt = false;
|
||||||
volatile bool playButtonDown = false;
|
volatile bool playButtonDown = false;
|
||||||
|
// Track if play button hold is active and if volume was adjusted during this hold
|
||||||
|
volatile bool playHoldActive = false;
|
||||||
|
volatile bool volumeAdjustedDuringHold = false;
|
||||||
volatile uint8_t sd_lock_flag = 0;
|
volatile uint8_t sd_lock_flag = 0;
|
||||||
|
|
||||||
/* Simple spinlock using older GCC sync builtins (no libatomic required).
|
/* Simple spinlock using older GCC sync builtins (no libatomic required).
|
||||||
|
|
@ -1509,7 +1512,7 @@ void loop()
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audio.isRunning() && webreq_cnt == 0)
|
if (audio.isRunning())
|
||||||
{
|
{
|
||||||
if (asyncStop)
|
if (asyncStop)
|
||||||
{
|
{
|
||||||
|
|
@ -1583,7 +1586,7 @@ void loop()
|
||||||
asyncTogglePlayPause = false;
|
asyncTogglePlayPause = false;
|
||||||
togglePlayPause();
|
togglePlayPause();
|
||||||
}
|
}
|
||||||
else if (asyncNext && webreq_cnt == 0)
|
else if (asyncNext)
|
||||||
{
|
{
|
||||||
asyncNext = false;
|
asyncNext = false;
|
||||||
// If the play/start button is held, treat NEXT as volume up
|
// If the play/start button is held, treat NEXT as volume up
|
||||||
|
|
@ -1595,6 +1598,7 @@ void loop()
|
||||||
vol++;
|
vol++;
|
||||||
audio.setVolume(vol);
|
audio.setVolume(vol);
|
||||||
volume = vol; // update stored volume for mute/unmute
|
volume = vol; // update stored volume for mute/unmute
|
||||||
|
volumeAdjustedDuringHold = true;
|
||||||
}
|
}
|
||||||
// do not play the startup sound when changing volume while holding play
|
// do not play the startup sound when changing volume while holding play
|
||||||
}
|
}
|
||||||
|
|
@ -1629,6 +1633,7 @@ void loop()
|
||||||
vol--;
|
vol--;
|
||||||
audio.setVolume(vol);
|
audio.setVolume(vol);
|
||||||
volume = vol; // update stored volume for mute/unmute
|
volume = vol; // update stored volume for mute/unmute
|
||||||
|
volumeAdjustedDuringHold = true;
|
||||||
}
|
}
|
||||||
// do not play the startup sound when changing volume while holding play
|
// do not play the startup sound when changing volume while holding play
|
||||||
}
|
}
|
||||||
|
|
@ -1704,9 +1709,32 @@ void loop2(void *parameter)
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
// Track whether the play/start button is currently held down so the main loop
|
// Track whether the play/start button is currently held down and detect press/release
|
||||||
// can interpret NEXT/PREV as volume changes while play is held.
|
bool currentDown = (digitalRead(BTN_START_STOP) == LOW);
|
||||||
playButtonDown = (digitalRead(BTN_START_STOP) == LOW);
|
static bool prevDown = false;
|
||||||
|
playButtonDown = currentDown;
|
||||||
|
|
||||||
|
// On press: start hold tracking and reset volume-change marker
|
||||||
|
if (currentDown && !prevDown)
|
||||||
|
{
|
||||||
|
playHoldActive = true;
|
||||||
|
volumeAdjustedDuringHold = false;
|
||||||
|
lastInteraction = millis();
|
||||||
|
}
|
||||||
|
// On release: toggle only if no volume change occurred during hold
|
||||||
|
if (!currentDown && prevDown)
|
||||||
|
{
|
||||||
|
if (playHoldActive)
|
||||||
|
{
|
||||||
|
if (!volumeAdjustedDuringHold)
|
||||||
|
{
|
||||||
|
asyncTogglePlayPause = true;
|
||||||
|
}
|
||||||
|
playHoldActive = false;
|
||||||
|
volumeAdjustedDuringHold = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prevDown = currentDown;
|
||||||
|
|
||||||
if (buttonPressed(BTN_NEXT))
|
if (buttonPressed(BTN_NEXT))
|
||||||
{
|
{
|
||||||
|
|
@ -1716,10 +1744,6 @@ void loop2(void *parameter)
|
||||||
{
|
{
|
||||||
asyncPrev = true;
|
asyncPrev = true;
|
||||||
}
|
}
|
||||||
if (buttonPressed(BTN_START_STOP))
|
|
||||||
{
|
|
||||||
asyncTogglePlayPause = true;
|
|
||||||
}
|
|
||||||
if (!loggingDone)
|
if (!loggingDone)
|
||||||
{
|
{
|
||||||
Serial.println("loop2 started");
|
Serial.println("loop2 started");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue