Fix power button leak on startup
This commit is contained in:
@@ -48,6 +48,10 @@ int clampPercent(int percent) {
|
|||||||
void EpubReaderActivity::onEnter() {
|
void EpubReaderActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
|
// Drop any input events that arrived from the activity that launched us (e.g. a wake-up power
|
||||||
|
// button hold) before they reach detectPageTurn() — see ReaderUtils::InputDrainGuard.
|
||||||
|
inputDrainGuard.arm();
|
||||||
|
|
||||||
if (!epub) {
|
if (!epub) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -118,6 +122,10 @@ void EpubReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inputDrainGuard.shouldDrain(mappedInput)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (automaticPageTurnActive) {
|
if (automaticPageTurnActive) {
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm) ||
|
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm) ||
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "EpubReaderMenuActivity.h"
|
#include "EpubReaderMenuActivity.h"
|
||||||
|
#include "ReaderUtils.h"
|
||||||
#include "activities/Activity.h"
|
#include "activities/Activity.h"
|
||||||
|
|
||||||
class EpubReaderActivity final : public Activity {
|
class EpubReaderActivity final : public Activity {
|
||||||
@@ -45,6 +46,7 @@ class EpubReaderActivity final : public Activity {
|
|||||||
uint16_t pendingParagraphIndex = 0;
|
uint16_t pendingParagraphIndex = 0;
|
||||||
bool pendingScreenshot = false;
|
bool pendingScreenshot = false;
|
||||||
bool skipNextButtonCheck = false; // Skip button processing for one frame after subactivity exit
|
bool skipNextButtonCheck = false; // Skip button processing for one frame after subactivity exit
|
||||||
|
ReaderUtils::InputDrainGuard inputDrainGuard;
|
||||||
bool automaticPageTurnActive = false;
|
bool automaticPageTurnActive = false;
|
||||||
std::string deferredSyncEpubPath;
|
std::string deferredSyncEpubPath;
|
||||||
// -1 means use global SETTINGS value.
|
// -1 means use global SETTINGS value.
|
||||||
|
|||||||
@@ -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 {
|
struct PageTurnResult {
|
||||||
bool prev;
|
bool prev;
|
||||||
bool next;
|
bool next;
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ size_t parseAndWrapLines(const uint8_t* buffer, size_t chunkSize, size_t fileOff
|
|||||||
void TxtReaderActivity::onEnter() {
|
void TxtReaderActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
|
// See ReaderUtils::InputDrainGuard — prevents wake-up power-button hold from leaking into
|
||||||
|
// the first detectPageTurn() call as a page turn or chapter skip.
|
||||||
|
inputDrainGuard.arm();
|
||||||
|
|
||||||
if (!txt) {
|
if (!txt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -117,6 +121,10 @@ void TxtReaderActivity::onExit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxtReaderActivity::loop() {
|
void TxtReaderActivity::loop() {
|
||||||
|
if (inputDrainGuard.shouldDrain(mappedInput)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Long press BACK (1s+) goes to home screen
|
// Long press BACK (1s+) goes to home screen
|
||||||
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) {
|
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) {
|
||||||
ReaderUtils::enforceExitFullRefresh(renderer);
|
ReaderUtils::enforceExitFullRefresh(renderer);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "CrossPointSettings.h"
|
#include "CrossPointSettings.h"
|
||||||
|
#include "ReaderUtils.h"
|
||||||
#include "activities/Activity.h"
|
#include "activities/Activity.h"
|
||||||
|
|
||||||
class TxtReaderActivity final : public Activity {
|
class TxtReaderActivity final : public Activity {
|
||||||
@@ -13,6 +14,7 @@ class TxtReaderActivity final : public Activity {
|
|||||||
int currentPage = 0;
|
int currentPage = 0;
|
||||||
int totalPages = 1;
|
int totalPages = 1;
|
||||||
int pagesUntilFullRefresh = 0;
|
int pagesUntilFullRefresh = 0;
|
||||||
|
ReaderUtils::InputDrainGuard inputDrainGuard;
|
||||||
|
|
||||||
// Streaming text reader - stores file offsets for each page
|
// Streaming text reader - stores file offsets for each page
|
||||||
std::vector<size_t> pageOffsets; // File offset for start of each page
|
std::vector<size_t> pageOffsets; // File offset for start of each page
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ constexpr unsigned long goHomeMs = 1000;
|
|||||||
void XtcReaderActivity::onEnter() {
|
void XtcReaderActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
|
// See ReaderUtils::InputDrainGuard — prevents wake-up power-button hold from leaking into
|
||||||
|
// the first detectPageTurn() call as a page turn or chapter skip.
|
||||||
|
inputDrainGuard.arm();
|
||||||
|
|
||||||
if (!xtc) {
|
if (!xtc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -58,6 +62,10 @@ void XtcReaderActivity::onExit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void XtcReaderActivity::loop() {
|
void XtcReaderActivity::loop() {
|
||||||
|
if (inputDrainGuard.shouldDrain(mappedInput)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Enter chapter selection activity
|
// Enter chapter selection activity
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||||
if (xtc && xtc->hasChapters() && !xtc->getChapters().empty()) {
|
if (xtc && xtc->hasChapters() && !xtc->getChapters().empty()) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <Xtc.h>
|
#include <Xtc.h>
|
||||||
|
|
||||||
|
#include "ReaderUtils.h"
|
||||||
#include "activities/Activity.h"
|
#include "activities/Activity.h"
|
||||||
|
|
||||||
class XtcReaderActivity final : public Activity {
|
class XtcReaderActivity final : public Activity {
|
||||||
@@ -16,6 +17,7 @@ class XtcReaderActivity final : public Activity {
|
|||||||
|
|
||||||
uint32_t currentPage = 0;
|
uint32_t currentPage = 0;
|
||||||
int pagesUntilFullRefresh = 0;
|
int pagesUntilFullRefresh = 0;
|
||||||
|
ReaderUtils::InputDrainGuard inputDrainGuard;
|
||||||
|
|
||||||
void renderPage();
|
void renderPage();
|
||||||
void saveProgress() const;
|
void saveProgress() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user