Skip to content

Commit 76e1535

Browse files
committed
feat: improve button responsiveness and track navigation seek options
- Reduce button debounce interval for faster responsiveness - Support 5-minute seeking using track navigation buttons on single long tracks
1 parent d83e15f commit 76e1535

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/AudioPlayer.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,16 @@ void AudioPlayer_Loop() {
758758
audio->stopSong();
759759
}
760760
} else {
761-
Log_Println(lastTrackAlreadyActive, LOGLEVEL_NOTICE);
762-
System_IndicateError();
763-
return;
761+
if (gPlayProperties.playlist->size() == 1 && audio->getAudioFileDuration() > 300) {
762+
audio->setTimeOffset(300);
763+
Log_Printf(LOGLEVEL_NOTICE, secondsJumpForward, 300);
764+
trackCommand = NO_ACTION;
765+
return;
766+
} else {
767+
Log_Println(lastTrackAlreadyActive, LOGLEVEL_NOTICE);
768+
System_IndicateError();
769+
return;
770+
}
764771
}
765772
break;
766773

@@ -793,12 +800,10 @@ void AudioPlayer_Loop() {
793800
}
794801
} else {
795802
if (gPlayProperties.currentTrackNumber > 0 || gPlayProperties.repeatPlaylist) {
796-
if (audio->getAudioCurrentTime() < 5) { // play previous track when current track time is small, else play current track again
797-
if (gPlayProperties.currentTrackNumber == 0 && gPlayProperties.repeatPlaylist) {
798-
gPlayProperties.currentTrackNumber = gPlayProperties.playlist->size() - 1; // Go back to last track in loop-mode when first track is played
799-
} else {
800-
gPlayProperties.currentTrackNumber--;
801-
}
803+
if (gPlayProperties.currentTrackNumber == 0 && gPlayProperties.repeatPlaylist) {
804+
gPlayProperties.currentTrackNumber = gPlayProperties.playlist->size() - 1; // Go back to last track in loop-mode when first track is played
805+
} else {
806+
gPlayProperties.currentTrackNumber--;
802807
}
803808

804809
if (gPlayProperties.saveLastPlayPosition) {
@@ -811,6 +816,12 @@ void AudioPlayer_Loop() {
811816
audio->stopSong();
812817
}
813818
} else {
819+
if (gPlayProperties.playlist->size() == 1 && audio->getAudioFileDuration() > 300) {
820+
audio->setTimeOffset(-300);
821+
Log_Printf(LOGLEVEL_NOTICE, secondsJumpBackward, 300);
822+
trackCommand = NO_ACTION;
823+
return;
824+
}
814825
if (gPlayProperties.saveLastPlayPosition) {
815826
AudioPlayer_NvsRfidWriteWrapper(gPlayProperties.playRfidTag, 0, gPlayProperties.playMode, gPlayProperties.currentTrackNumber);
816827
}

src/Button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ static void Button_UpdateState(uint8_t i, t_button &btn, unsigned long currentTi
215215
btn.lastReleasedTimestamp = currentTimestamp;
216216
btn.firstPressedTimestamp = 0;
217217
}
218+
btn.lastState = btn.currentState;
218219
}
219-
btn.lastState = btn.currentState;
220220
}
221221

222222
// If timer-semaphore is set, read buttons (unless controls are locked)

src/settings-override.h.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
#endif
160160

161161
// Buttons (better leave unchanged if in doubts :-))
162-
constexpr uint8_t buttonDebounceInterval = 50; // Interval in ms to software-debounce buttons
162+
constexpr uint8_t buttonDebounceInterval = 30; // Interval in ms to software-debounce buttons
163163
constexpr uint16_t intervalToLongPress = 700; // Interval in ms to distinguish between short and long press of buttons
164164

165165
// Buttons active state: Default 0 for active LOW, 1 for active HIGH e.g. for TTP223 Capacitive Touch Switch Button (FinnBox)

src/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
#endif
168168

169169
// Buttons (better leave unchanged if in doubts :-))
170-
constexpr uint8_t buttonDebounceInterval = 50; // Interval in ms to software-debounce buttons
170+
constexpr uint8_t buttonDebounceInterval = 30; // Interval in ms to software-debounce buttons
171171
constexpr uint16_t intervalToLongPress = 700; // Interval in ms to distinguish between short and long press of buttons
172172

173173
// Buttons active state: Default 0 for active LOW, 1 for active HIGH e.g. for TTP223 Capacitive Touch Switch Button (FinnBox)

0 commit comments

Comments
 (0)