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
This commit is contained in:
Arthur Tazhitdinov
2026-02-08 21:01:30 +03:00
committed by Dave Allie
parent bb983d0ef4
commit 4f0a3aa4dd
5 changed files with 17 additions and 4 deletions

View File

@@ -5,7 +5,7 @@
#include <Serialization.h> #include <Serialization.h>
namespace { namespace {
constexpr uint8_t STATE_FILE_VERSION = 3; constexpr uint8_t STATE_FILE_VERSION = 4;
constexpr char STATE_FILE[] = "/.crosspoint/state.bin"; constexpr char STATE_FILE[] = "/.crosspoint/state.bin";
} // namespace } // namespace
@@ -21,6 +21,7 @@ bool CrossPointState::saveToFile() const {
serialization::writeString(outputFile, openEpubPath); serialization::writeString(outputFile, openEpubPath);
serialization::writePod(outputFile, lastSleepImage); serialization::writePod(outputFile, lastSleepImage);
serialization::writePod(outputFile, readerActivityLoadCount); serialization::writePod(outputFile, readerActivityLoadCount);
serialization::writePod(outputFile, lastSleepFromReader);
outputFile.close(); outputFile.close();
return true; return true;
} }
@@ -50,6 +51,12 @@ bool CrossPointState::loadFromFile() {
serialization::readPod(inputFile, readerActivityLoadCount); serialization::readPod(inputFile, readerActivityLoadCount);
} }
if (version >= 4) {
serialization::readPod(inputFile, lastSleepFromReader);
} else {
lastSleepFromReader = false;
}
inputFile.close(); inputFile.close();
return true; return true;
} }

View File

@@ -10,6 +10,7 @@ class CrossPointState {
std::string openEpubPath; std::string openEpubPath;
uint8_t lastSleepImage; uint8_t lastSleepImage;
uint8_t readerActivityLoadCount = 0; uint8_t readerActivityLoadCount = 0;
bool lastSleepFromReader = false;
~CrossPointState() = default; ~CrossPointState() = default;
// Get singleton instance // Get singleton instance

View File

@@ -23,4 +23,5 @@ class Activity {
virtual void loop() {} virtual void loop() {}
virtual bool skipLoopDelay() { return false; } virtual bool skipLoopDelay() { return false; }
virtual bool preventAutoSleep() { return false; } virtual bool preventAutoSleep() { return false; }
virtual bool isReaderActivity() const { return false; }
}; };

View File

@@ -34,4 +34,5 @@ class ReaderActivity final : public ActivityWithSubactivity {
onGoBack(onGoBack), onGoBack(onGoBack),
onGoToLibrary(onGoToLibrary) {} onGoToLibrary(onGoToLibrary) {}
void onEnter() override; void onEnter() override;
bool isReaderActivity() const override { return true; }
}; };

View File

@@ -194,6 +194,8 @@ void waitForPowerRelease() {
// Enter deep sleep mode // Enter deep sleep mode
void enterDeepSleep() { void enterDeepSleep() {
APP_STATE.lastSleepFromReader = currentActivity && currentActivity->isReaderActivity();
APP_STATE.saveToFile();
exitActivity(); exitActivity();
enterNewActivity(new SleepActivity(renderer, mappedInputManager)); enterNewActivity(new SleepActivity(renderer, mappedInputManager));
@@ -331,9 +333,10 @@ void setup() {
APP_STATE.loadFromFile(); APP_STATE.loadFromFile();
RECENT_BOOKS.loadFromFile(); RECENT_BOOKS.loadFromFile();
// Boot to home screen directly when back button is held or when reader activity crashes 3 times // Boot to home screen if no book is open, last sleep was not from reader, back button is held, or reader activity
if (APP_STATE.openEpubPath.empty() || mappedInputManager.isPressed(MappedInputManager::Button::Back) || // crashed (indicated by readerActivityLoadCount > 0)
APP_STATE.readerActivityLoadCount > 0) { if (APP_STATE.openEpubPath.empty() || !APP_STATE.lastSleepFromReader ||
mappedInputManager.isPressed(MappedInputManager::Button::Back) || APP_STATE.readerActivityLoadCount > 0) {
onGoHome(); onGoHome();
} else { } else {
// Clear app state to avoid getting into a boot loop if the epub doesn't load // Clear app state to avoid getting into a boot loop if the epub doesn't load