mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
fix: button navigator triggers
This commit is contained in:
parent
73c5f05843
commit
b7b36f02e2
@ -15,9 +15,9 @@ void ButtonNavigator::onNextPress(const Callback& callback) { onPress(getNextBut
|
||||
|
||||
void ButtonNavigator::onPreviousPress(const Callback& callback) { onPress(getPreviousButtons(), callback); }
|
||||
|
||||
void ButtonNavigator::onNextRelease(const Callback& callback) const { onRelease(getNextButtons(), callback); }
|
||||
void ButtonNavigator::onNextRelease(const Callback& callback) { onRelease(getNextButtons(), callback); }
|
||||
|
||||
void ButtonNavigator::onPreviousRelease(const Callback& callback) const { onRelease(getPreviousButtons(), callback); }
|
||||
void ButtonNavigator::onPreviousRelease(const Callback& callback) { onRelease(getPreviousButtons(), callback); }
|
||||
|
||||
void ButtonNavigator::onNextContinuous(const Callback& callback) { onContinuous(getNextButtons(), callback); }
|
||||
|
||||
@ -26,48 +26,38 @@ void ButtonNavigator::onPreviousContinuous(const Callback& callback) { onContinu
|
||||
void ButtonNavigator::onPress(const Buttons& buttons, const Callback& callback) {
|
||||
if (!mappedInput) return;
|
||||
|
||||
bool buttonPressed = false;
|
||||
for (const MappedInputManager::Button button : buttons) {
|
||||
if (mappedInput->wasPressed(button)) {
|
||||
buttonPressed = true;
|
||||
break;
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (buttonPressed && !recentlyNavigatedContinuously()) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
void ButtonNavigator::onRelease(const Buttons& buttons, const Callback& callback) const {
|
||||
void ButtonNavigator::onRelease(const Buttons& buttons, const Callback& callback) {
|
||||
if (!mappedInput) return;
|
||||
|
||||
bool buttonReleased = false;
|
||||
for (const MappedInputManager::Button button : buttons) {
|
||||
if (mappedInput->wasReleased(button)) {
|
||||
buttonReleased = true;
|
||||
break;
|
||||
}
|
||||
if (lastContinuousNavTime == 0) {
|
||||
callback();
|
||||
}
|
||||
|
||||
if (buttonReleased && !recentlyNavigatedContinuously()) {
|
||||
callback();
|
||||
lastContinuousNavTime = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonNavigator::onContinuous(const Buttons& buttons, const Callback& callback) {
|
||||
if (!mappedInput) return;
|
||||
|
||||
bool buttonPressed = false;
|
||||
for (const MappedInputManager::Button button : buttons) {
|
||||
if (mappedInput->isPressed(button)) {
|
||||
buttonPressed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buttonPressed && shouldNavigateContinuously()) {
|
||||
if (mappedInput->isPressed(button) && shouldNavigateContinuously()) {
|
||||
callback();
|
||||
lastContinuousNavTime = millis();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,15 +70,6 @@ bool ButtonNavigator::shouldNavigateContinuously() const {
|
||||
return buttonHeldLongEnough && navigationIntervalElapsed;
|
||||
}
|
||||
|
||||
bool ButtonNavigator::recentlyNavigatedContinuously() const {
|
||||
const int elapsedTime = millis() - lastContinuousNavTime;
|
||||
if (elapsedTime < 50) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int ButtonNavigator::nextIndex(const int currentIndex, const int totalItems) {
|
||||
if (totalItems <= 0) return 0;
|
||||
|
||||
|
||||
@ -12,11 +12,11 @@ class ButtonNavigator final {
|
||||
const uint16_t continuousStartMs;
|
||||
const uint16_t continuousIntervalMs;
|
||||
uint32_t lastContinuousNavTime = 0;
|
||||
bool continuousNavHold = false;
|
||||
|
||||
static const MappedInputManager* mappedInput;
|
||||
|
||||
[[nodiscard]] bool shouldNavigateContinuously() const;
|
||||
[[nodiscard]] bool recentlyNavigatedContinuously() const;
|
||||
|
||||
[[nodiscard]] static Buttons getNextButtons() {
|
||||
return {MappedInputManager::Button::Down, MappedInputManager::Button::Right};
|
||||
@ -38,9 +38,9 @@ class ButtonNavigator final {
|
||||
void onPreviousPress(const Callback& callback);
|
||||
void onPress(const Buttons& buttons, const Callback& callback);
|
||||
|
||||
void onNextRelease(const Callback& callback) const;
|
||||
void onPreviousRelease(const Callback& callback) const;
|
||||
void onRelease(const Buttons& buttons, const Callback& callback) const;
|
||||
void onNextRelease(const Callback& callback);
|
||||
void onPreviousRelease(const Callback& callback);
|
||||
void onRelease(const Buttons& buttons, const Callback& callback);
|
||||
|
||||
void onNextContinuous(const Callback& callback);
|
||||
void onPreviousContinuous(const Callback& callback);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user