A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Init lastSleepImage (edge case) (#1360)

## Summary

* **What is the goal of this PR?** fix edge case for definition

## Additional Context

If loadFromFile() returns false (no state file exists — first boot, or
SD missing), lastSleepImage is never set and contains garbage.
[SleepActivity.cpp:83] then uses it in a while comparison to avoid
repeating the same image. The JSON path (doc["lastSleepImage"] |
(uint8_t)0) handles it, but only if the file exists.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _** NO **_

authored by

jpirnay and committed by
GitHub
79b54b3a 11ca208e

+5 -4
+1 -1
src/CrossPointState.cpp
··· 63 63 if (version >= 2) { 64 64 serialization::readPod(inputFile, lastSleepImage); 65 65 } else { 66 - lastSleepImage = 0; 66 + lastSleepImage = UINT8_MAX; 67 67 } 68 68 69 69 if (version >= 3) {
+2 -1
src/CrossPointState.h
··· 1 1 #pragma once 2 + #include <cstdint> 2 3 #include <iosfwd> 3 4 #include <string> 4 5 ··· 8 9 9 10 public: 10 11 std::string openEpubPath; 11 - uint8_t lastSleepImage; 12 + uint8_t lastSleepImage = UINT8_MAX; // UINT8_MAX = unset sentinel 12 13 uint8_t readerActivityLoadCount = 0; 13 14 bool lastSleepFromReader = false; 14 15 ~CrossPointState() = default;
+1 -1
src/JsonSettingsIO.cpp
··· 87 87 } 88 88 89 89 s.openEpubPath = doc["openEpubPath"] | std::string(""); 90 - s.lastSleepImage = doc["lastSleepImage"] | (uint8_t)0; 90 + s.lastSleepImage = doc["lastSleepImage"] | (uint8_t)UINT8_MAX; 91 91 s.readerActivityLoadCount = doc["readerActivityLoadCount"] | (uint8_t)0; 92 92 s.lastSleepFromReader = doc["lastSleepFromReader"] | false; 93 93 return true;
+1 -1
src/activities/boot_sleep/SleepActivity.cpp
··· 80 80 // Generate a random number between 1 and numFiles 81 81 auto randomFileIndex = random(numFiles); 82 82 // If we picked the same image as last time, reroll 83 - while (numFiles > 1 && randomFileIndex == APP_STATE.lastSleepImage) { 83 + while (numFiles > 1 && APP_STATE.lastSleepImage != UINT8_MAX && randomFileIndex == APP_STATE.lastSleepImage) { 84 84 randomFileIndex = random(numFiles); 85 85 } 86 86 APP_STATE.lastSleepImage = randomFileIndex;