Compare commits

...

3 Commits

Author SHA1 Message Date
Will Morrow
4b23681ca5
Merge fedfb80258 into 97c4871316 2026-01-12 19:09:26 +10:00
Will Morrow
fedfb80258
Fix style problem 2026-01-09 19:55:30 -05:00
Will Morrow
3819448945
Ensure new custom sleep image every time
When picking a random sleep image from a set of custom images, compare
the randomly chosen index against a cached value in settings. If the
value matches, use the next image (rolling over if it's the last image).
Cache the chosen image index to settings in either case.
2026-01-09 08:35:27 -05:00
3 changed files with 13 additions and 2 deletions

View File

@ -14,7 +14,7 @@ CrossPointSettings CrossPointSettings::instance;
namespace {
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
// Increment this when adding new persisted settings fields
constexpr uint8_t SETTINGS_COUNT = 17;
constexpr uint8_t SETTINGS_COUNT = 18;
constexpr char SETTINGS_FILE[] = "/.crosspoint/settings.bin";
} // namespace
@ -46,6 +46,7 @@ bool CrossPointSettings::saveToFile() const {
serialization::writePod(outputFile, sleepScreenCoverMode);
serialization::writeString(outputFile, std::string(opdsServerUrl));
serialization::writePod(outputFile, textAntiAliasing);
serialization::writePod(outputFile, lastUsedSleep);
outputFile.close();
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
@ -110,6 +111,8 @@ bool CrossPointSettings::loadFromFile() {
}
serialization::readPod(inputFile, textAntiAliasing);
if (++settingsRead >= fileSettingsCount) break;
serialization::readPod(inputFile, lastUsedSleep);
if (++settingsRead >= fileSettingsCount) break;
} while (false);
inputFile.close();

View File

@ -85,6 +85,8 @@ class CrossPointSettings {
uint8_t screenMargin = 5;
// OPDS browser settings
char opdsServerUrl[128] = "";
// Last used sleep screen index (for custom screens)
uint8_t lastUsedSleep = 0;
~CrossPointSettings() = default;

View File

@ -81,7 +81,13 @@ void SleepActivity::renderCustomSleepScreen() const {
if (numFiles > 0) {
// Generate a random number between 1 and numFiles
const auto randomFileIndex = random(numFiles);
const auto filename = "/sleep/" + files[randomFileIndex];
// If we re-generated the same index as the last sleep screen,
// use the next one (modulo the number of files we have)
const auto realFileIndex =
randomFileIndex == SETTINGS.lastUsedSleep ? randomFileIndex + 1 % numFiles : randomFileIndex;
SETTINGS.lastUsedSleep = realFileIndex;
SETTINGS.saveToFile();
const auto filename = "/sleep/" + files[realFileIndex];
FsFile file;
if (SdMan.openFileForRead("SLP", filename, file)) {
Serial.printf("[%lu] [SLP] Randomly loading: /sleep/%s\n", millis(), files[randomFileIndex].c_str());