From 1caad578fc9d43d3d5d545295732b6d8d886a9d5 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 8 Feb 2026 21:01:30 +0300 Subject: [PATCH] feat: wakeup target detection (#731) ## Summary * If going to sleep was from the Reader view, wake up to the same book. Otherwise, wakeup to the Home view --- src/CrossPointState.cpp | 9 ++++++++- src/CrossPointState.h | 1 + src/activities/Activity.h | 1 + src/activities/reader/ReaderActivity.h | 1 + src/main.cpp | 9 ++++++--- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/CrossPointState.cpp b/src/CrossPointState.cpp index d578945c..d97344f2 100644 --- a/src/CrossPointState.cpp +++ b/src/CrossPointState.cpp @@ -5,7 +5,7 @@ #include namespace { -constexpr uint8_t STATE_FILE_VERSION = 3; +constexpr uint8_t STATE_FILE_VERSION = 4; constexpr char STATE_FILE[] = "/.crosspoint/state.bin"; } // namespace @@ -21,6 +21,7 @@ bool CrossPointState::saveToFile() const { serialization::writeString(outputFile, openEpubPath); serialization::writePod(outputFile, lastSleepImage); serialization::writePod(outputFile, readerActivityLoadCount); + serialization::writePod(outputFile, lastSleepFromReader); outputFile.close(); return true; } @@ -50,6 +51,12 @@ bool CrossPointState::loadFromFile() { serialization::readPod(inputFile, readerActivityLoadCount); } + if (version >= 4) { + serialization::readPod(inputFile, lastSleepFromReader); + } else { + lastSleepFromReader = false; + } + inputFile.close(); return true; } diff --git a/src/CrossPointState.h b/src/CrossPointState.h index e8c65c10..68fa1d68 100644 --- a/src/CrossPointState.h +++ b/src/CrossPointState.h @@ -10,6 +10,7 @@ class CrossPointState { std::string openEpubPath; uint8_t lastSleepImage; uint8_t readerActivityLoadCount = 0; + bool lastSleepFromReader = false; ~CrossPointState() = default; // Get singleton instance diff --git a/src/activities/Activity.h b/src/activities/Activity.h index 4a60607b..632d396d 100644 --- a/src/activities/Activity.h +++ b/src/activities/Activity.h @@ -23,4 +23,5 @@ class Activity { virtual void loop() {} virtual bool skipLoopDelay() { return false; } virtual bool preventAutoSleep() { return false; } + virtual bool isReaderActivity() const { return false; } }; diff --git a/src/activities/reader/ReaderActivity.h b/src/activities/reader/ReaderActivity.h index 6ecd6f34..5a2c1012 100644 --- a/src/activities/reader/ReaderActivity.h +++ b/src/activities/reader/ReaderActivity.h @@ -34,4 +34,5 @@ class ReaderActivity final : public ActivityWithSubactivity { onGoBack(onGoBack), onGoToLibrary(onGoToLibrary) {} void onEnter() override; + bool isReaderActivity() const override { return true; } }; diff --git a/src/main.cpp b/src/main.cpp index e1c74038..f18c47e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -194,6 +194,8 @@ void waitForPowerRelease() { // Enter deep sleep mode void enterDeepSleep() { + APP_STATE.lastSleepFromReader = currentActivity && currentActivity->isReaderActivity(); + APP_STATE.saveToFile(); exitActivity(); enterNewActivity(new SleepActivity(renderer, mappedInputManager)); @@ -331,9 +333,10 @@ void setup() { APP_STATE.loadFromFile(); RECENT_BOOKS.loadFromFile(); - // Boot to home screen directly when back button is held or when reader activity crashes 3 times - if (APP_STATE.openEpubPath.empty() || mappedInputManager.isPressed(MappedInputManager::Button::Back) || - APP_STATE.readerActivityLoadCount > 0) { + // Boot to home screen if no book is open, last sleep was not from reader, back button is held, or reader activity + // crashed (indicated by readerActivityLoadCount > 0) + if (APP_STATE.openEpubPath.empty() || !APP_STATE.lastSleepFromReader || + mappedInputManager.isPressed(MappedInputManager::Button::Back) || APP_STATE.readerActivityLoadCount > 0) { onGoHome(); } else { // Clear app state to avoid getting into a boot loop if the epub doesn't load