Fix power button leak on startup

This commit is contained in:
jpirnay
2026-04-08 10:14:35 +02:00
parent 84d6054898
commit b3d6562cb6
7 changed files with 57 additions and 0 deletions
+27
View File
@@ -29,6 +29,33 @@ inline void applyOrientation(GfxRenderer& renderer, const uint8_t orientation) {
}
}
// Suppresses input processing on activity entry until the user has released all buttons and a
// clean frame (no pending press/release events) has been observed. Without this, the power-button
// hold used to wake the device leaks into detectPageTurn() and triggers a page turn or, with
// longPressChapterSkip enabled, a chapter skip (the wake-hold easily exceeds skipChapterMs).
// Each reader holds an instance, calls arm() in onEnter(), and calls shouldDrain() at the top
// of loop() — returning early when it returns true.
struct InputDrainGuard {
bool active = false;
void arm() { active = true; }
bool shouldDrain(const MappedInputManager& input) {
if (!active) {
return false;
}
using B = MappedInputManager::Button;
const bool anyHeld = input.isPressed(B::Back) || input.isPressed(B::Confirm) || input.isPressed(B::Left) ||
input.isPressed(B::Right) || input.isPressed(B::Up) || input.isPressed(B::Down) ||
input.isPressed(B::Power) || input.isPressed(B::PageBack) || input.isPressed(B::PageForward);
if (anyHeld || input.wasAnyPressed() || input.wasAnyReleased()) {
return true;
}
active = false;
return false;
}
};
struct PageTurnResult {
bool prev;
bool next;