mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-08 08:37:38 +03:00
Refactor auto-sleep settings to use minutes instead of predefined timeouts
This commit is contained in:
parent
14972b34cb
commit
f43eb5411c
@ -40,6 +40,7 @@ This project is **not affiliated with Xteink**; it's built as a community projec
|
|||||||
- [ ] User provided fonts
|
- [ ] User provided fonts
|
||||||
- [ ] Full UTF support
|
- [ ] Full UTF support
|
||||||
- [x] Screen rotation
|
- [x] Screen rotation
|
||||||
|
- [x] Adjustable auto-sleep timeout (2, 5, 10, 15, 20, 30, 60 minutes, or Never)
|
||||||
|
|
||||||
See [the user guide](./USER_GUIDE.md) for instructions on operating CrossPoint.
|
See [the user guide](./USER_GUIDE.md) for instructions on operating CrossPoint.
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ bool CrossPointSettings::saveToFile() const {
|
|||||||
serialization::writePod(outputFile, fontSize);
|
serialization::writePod(outputFile, fontSize);
|
||||||
serialization::writePod(outputFile, lineSpacing);
|
serialization::writePod(outputFile, lineSpacing);
|
||||||
serialization::writePod(outputFile, paragraphAlignment);
|
serialization::writePod(outputFile, paragraphAlignment);
|
||||||
serialization::writePod(outputFile, sleepTimeout);
|
serialization::writePod(outputFile, autoSleepMinutes);
|
||||||
serialization::writePod(outputFile, refreshFrequency);
|
serialization::writePod(outputFile, refreshFrequency);
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ bool CrossPointSettings::loadFromFile() {
|
|||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
serialization::readPod(inputFile, paragraphAlignment);
|
serialization::readPod(inputFile, paragraphAlignment);
|
||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
serialization::readPod(inputFile, sleepTimeout);
|
serialization::readPod(inputFile, autoSleepMinutes);
|
||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
serialization::readPod(inputFile, refreshFrequency);
|
serialization::readPod(inputFile, refreshFrequency);
|
||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
@ -135,22 +135,6 @@ float CrossPointSettings::getReaderLineCompression() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long CrossPointSettings::getSleepTimeoutMs() const {
|
|
||||||
switch (sleepTimeout) {
|
|
||||||
case SLEEP_1_MIN:
|
|
||||||
return 1UL * 60 * 1000;
|
|
||||||
case SLEEP_5_MIN:
|
|
||||||
return 5UL * 60 * 1000;
|
|
||||||
case SLEEP_10_MIN:
|
|
||||||
default:
|
|
||||||
return 10UL * 60 * 1000;
|
|
||||||
case SLEEP_15_MIN:
|
|
||||||
return 15UL * 60 * 1000;
|
|
||||||
case SLEEP_30_MIN:
|
|
||||||
return 30UL * 60 * 1000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int CrossPointSettings::getRefreshFrequency() const {
|
int CrossPointSettings::getRefreshFrequency() const {
|
||||||
switch (refreshFrequency) {
|
switch (refreshFrequency) {
|
||||||
case REFRESH_1:
|
case REFRESH_1:
|
||||||
|
|||||||
@ -45,8 +45,7 @@ class CrossPointSettings {
|
|||||||
enum LINE_COMPRESSION { TIGHT = 0, NORMAL = 1, WIDE = 2 };
|
enum LINE_COMPRESSION { TIGHT = 0, NORMAL = 1, WIDE = 2 };
|
||||||
enum PARAGRAPH_ALIGNMENT { JUSTIFIED = 0, LEFT_ALIGN = 1, CENTER_ALIGN = 2, RIGHT_ALIGN = 3 };
|
enum PARAGRAPH_ALIGNMENT { JUSTIFIED = 0, LEFT_ALIGN = 1, CENTER_ALIGN = 2, RIGHT_ALIGN = 3 };
|
||||||
|
|
||||||
// Auto-sleep timeout options (in minutes)
|
// Auto-sleep timeout options (enum index to minutes: 0=2min, 1=5min, 2=10min, 3=15min, 4=20min, 5=30min, 6=60min, 7=Never)
|
||||||
enum SLEEP_TIMEOUT { SLEEP_1_MIN = 0, SLEEP_5_MIN = 1, SLEEP_10_MIN = 2, SLEEP_15_MIN = 3, SLEEP_30_MIN = 4 };
|
|
||||||
|
|
||||||
// E-ink refresh frequency (pages between full refreshes)
|
// E-ink refresh frequency (pages between full refreshes)
|
||||||
enum REFRESH_FREQUENCY { REFRESH_1 = 0, REFRESH_5 = 1, REFRESH_10 = 2, REFRESH_15 = 3, REFRESH_30 = 4 };
|
enum REFRESH_FREQUENCY { REFRESH_1 = 0, REFRESH_5 = 1, REFRESH_10 = 2, REFRESH_15 = 3, REFRESH_30 = 4 };
|
||||||
@ -70,8 +69,8 @@ class CrossPointSettings {
|
|||||||
uint8_t fontSize = MEDIUM;
|
uint8_t fontSize = MEDIUM;
|
||||||
uint8_t lineSpacing = NORMAL;
|
uint8_t lineSpacing = NORMAL;
|
||||||
uint8_t paragraphAlignment = JUSTIFIED;
|
uint8_t paragraphAlignment = JUSTIFIED;
|
||||||
// Auto-sleep timeout setting (default 10 minutes)
|
// Auto-sleep timeout (enum index: 0=2min, 1=5min, 2=10min, 3=15min, 4=20min, 5=30min, 6=60min, 7=Never)
|
||||||
uint8_t sleepTimeout = SLEEP_10_MIN;
|
uint8_t autoSleepMinutes = 1; // Default to 5 minutes
|
||||||
// E-ink refresh frequency (default 15 pages)
|
// E-ink refresh frequency (default 15 pages)
|
||||||
uint8_t refreshFrequency = REFRESH_15;
|
uint8_t refreshFrequency = REFRESH_15;
|
||||||
|
|
||||||
@ -87,7 +86,20 @@ class CrossPointSettings {
|
|||||||
bool loadFromFile();
|
bool loadFromFile();
|
||||||
|
|
||||||
float getReaderLineCompression() const;
|
float getReaderLineCompression() const;
|
||||||
unsigned long getSleepTimeoutMs() const;
|
unsigned long getAutoSleepTimeoutMs() const {
|
||||||
|
// Map enum index to milliseconds: 0=2min, 1=5min, 2=10min, 3=15min, 4=20min, 5=30min, 6=60min, 7=Never(0)
|
||||||
|
constexpr unsigned long timeouts[] = {
|
||||||
|
2UL * 60UL * 1000UL, // 0: 2 minutes
|
||||||
|
5UL * 60UL * 1000UL, // 1: 5 minutes (default)
|
||||||
|
10UL * 60UL * 1000UL, // 2: 10 minutes
|
||||||
|
15UL * 60UL * 1000UL, // 3: 15 minutes
|
||||||
|
20UL * 60UL * 1000UL, // 4: 20 minutes
|
||||||
|
30UL * 60UL * 1000UL, // 5: 30 minutes
|
||||||
|
60UL * 60UL * 1000UL, // 6: 60 minutes
|
||||||
|
0UL // 7: Never (disabled)
|
||||||
|
};
|
||||||
|
return (autoSleepMinutes < 8) ? timeouts[autoSleepMinutes] : timeouts[2];
|
||||||
|
}
|
||||||
int getRefreshFrequency() const;
|
int getRefreshFrequency() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -38,10 +38,10 @@ const SettingInfo settingsList[settingsCount] = {
|
|||||||
SettingType::ENUM,
|
SettingType::ENUM,
|
||||||
&CrossPointSettings::paragraphAlignment,
|
&CrossPointSettings::paragraphAlignment,
|
||||||
{"Justify", "Left", "Center", "Right"}},
|
{"Justify", "Left", "Center", "Right"}},
|
||||||
{"Time to Sleep",
|
{"Auto Sleep Timeout",
|
||||||
SettingType::ENUM,
|
SettingType::ENUM,
|
||||||
&CrossPointSettings::sleepTimeout,
|
&CrossPointSettings::autoSleepMinutes,
|
||||||
{"1 min", "5 min", "10 min", "15 min", "30 min"}},
|
{"2 min", "5 min", "10 min", "15 min", "20 min", "30 min", "60 min", "Never"}},
|
||||||
{"Refresh Frequency",
|
{"Refresh Frequency",
|
||||||
SettingType::ENUM,
|
SettingType::ENUM,
|
||||||
&CrossPointSettings::refreshFrequency,
|
&CrossPointSettings::refreshFrequency,
|
||||||
|
|||||||
12
src/main.cpp
12
src/main.cpp
@ -316,16 +316,16 @@ void loop() {
|
|||||||
lastMemPrint = millis();
|
lastMemPrint = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for any user activity (button press or release) or active background work
|
// Check for any user activity (button press or release)
|
||||||
static unsigned long lastActivityTime = millis();
|
static unsigned long lastActivityTime = millis();
|
||||||
if (inputManager.wasAnyPressed() || inputManager.wasAnyReleased() ||
|
if (inputManager.wasAnyPressed() || inputManager.wasAnyReleased()) {
|
||||||
(currentActivity && currentActivity->preventAutoSleep())) {
|
|
||||||
lastActivityTime = millis(); // Reset inactivity timer
|
lastActivityTime = millis(); // Reset inactivity timer
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned long sleepTimeoutMs = SETTINGS.getSleepTimeoutMs();
|
// Check auto-sleep timeout (if enabled - 0 means never sleep)
|
||||||
if (millis() - lastActivityTime >= sleepTimeoutMs) {
|
const unsigned long autoSleepTimeout = SETTINGS.getAutoSleepTimeoutMs();
|
||||||
Serial.printf("[%lu] [SLP] Auto-sleep triggered after %lu ms of inactivity\n", millis(), sleepTimeoutMs);
|
if (autoSleepTimeout > 0 && millis() - lastActivityTime >= autoSleepTimeout) {
|
||||||
|
Serial.printf("[%lu] [SLP] Auto-sleep triggered after %lu ms of inactivity\n", millis(), autoSleepTimeout);
|
||||||
enterDeepSleep();
|
enterDeepSleep();
|
||||||
// This should never be hit as `enterDeepSleep` calls esp_deep_sleep_start
|
// This should never be hit as `enterDeepSleep` calls esp_deep_sleep_start
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user