From 9ab27f848cc14cf9c4c34719ba488d4ed7168e7e Mon Sep 17 00:00:00 2001 From: altsysrq Date: Sat, 3 Jan 2026 22:27:02 -0600 Subject: [PATCH] Add auto-sleep timeout setting and handle it in loop Incremented settings count, added autoSleepMinutes to CrossPointSettings, updated save/load functions, and integrated auto-sleep logic based on the new setting. --- .envrc | 1 - docs/Upload_EPUBs_to_CrossPoint.macro | 1 + docs/Upload_EPUBs_to_CrossPoint.tsk.xml | 174 +++++++++++++++++++ docs/test.sh | 10 ++ flake.nix | 32 ---- shell.nix | 15 -- src/CrossPointSettings.cpp | 5 +- src/CrossPointSettings.h | 15 ++ src/activities/settings/SettingsActivity.cpp | 6 +- src/main.cpp | 8 +- 10 files changed, 213 insertions(+), 54 deletions(-) delete mode 100644 .envrc create mode 100644 docs/Upload_EPUBs_to_CrossPoint.macro create mode 100644 docs/Upload_EPUBs_to_CrossPoint.tsk.xml create mode 100644 docs/test.sh delete mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc deleted file mode 100644 index 1d953f4b..00000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -use nix diff --git a/docs/Upload_EPUBs_to_CrossPoint.macro b/docs/Upload_EPUBs_to_CrossPoint.macro new file mode 100644 index 00000000..16e2c529 --- /dev/null +++ b/docs/Upload_EPUBs_to_CrossPoint.macro @@ -0,0 +1 @@ +{"globalVariables":[],"macro":{"disabledTimestamp":0,"exportedActionBlocks":[],"forceEvenIfNotEnabledTimestamp":0,"isActionBlock":false,"isExtra":false,"isFavourite":false,"lastEditedTimestamp":1767287000000,"localVariables":[{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"reader_ip","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"source_dir","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"target_dir","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"upload_count","m_stringValue":"","m_type":1,"supportsInput":false,"supportsOutput":true},{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":false,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"epub_files","m_stringValue":"","m_type":4,"supportsInput":false,"supportsOutput":true},{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"current_file","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"filename","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"file_list","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true}],"localVarsAlphabetical":true,"m_GUID":-6743406536052058632,"m_actionList":[{"booleanDictionaryKeys":{"keys":[]},"dictionaryKeys":[],"dictionaryOrArrayType":-1,"existingManualKeyType":0,"m_booleanInvert":false,"m_darkMode":-1,"m_doubleRandomMax":0.0,"m_doubleRandomMin":0.0,"m_falseLabel":"False","m_intExpression":false,"m_intRandom":false,"m_intRandomMax":0,"m_intRandomMin":0,"m_intValueDecrement":false,"m_intValueIncrement":false,"m_newBooleanValue":false,"m_newDoubleValue":0.0,"m_newIntValue":0,"m_newStringValue":"192.168.4.1","m_trueLabel":"True","m_userPrompt":false,"m_userPromptEmptyAtStart":false,"m_userPromptPassword":false,"m_userPromptShowCancel":true,"m_userPromptStopAfterCancel":true,"m_variable":{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"reader_ip","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},"disableLogging":false,"m_SIGUID":-8462510831770928567,"m_classType":"SetVariableAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"booleanDictionaryKeys":{"keys":[]},"dictionaryKeys":[],"dictionaryOrArrayType":-1,"existingManualKeyType":0,"m_booleanInvert":false,"m_darkMode":-1,"m_doubleRandomMax":0.0,"m_doubleRandomMin":0.0,"m_falseLabel":"False","m_intExpression":false,"m_intRandom":false,"m_intRandomMax":0,"m_intRandomMin":0,"m_intValueDecrement":false,"m_intValueIncrement":false,"m_newBooleanValue":false,"m_newDoubleValue":0.0,"m_newIntValue":0,"m_newStringValue":"/storage/emulated/0/Documents/ereader","m_trueLabel":"True","m_userPrompt":false,"m_userPromptEmptyAtStart":false,"m_userPromptPassword":false,"m_userPromptShowCancel":true,"m_userPromptStopAfterCancel":true,"m_variable":{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"source_dir","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},"disableLogging":false,"m_SIGUID":-8881672898422720773,"m_classType":"SetVariableAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"booleanDictionaryKeys":{"keys":[]},"dictionaryKeys":[],"dictionaryOrArrayType":-1,"existingManualKeyType":0,"m_booleanInvert":false,"m_darkMode":-1,"m_doubleRandomMax":0.0,"m_doubleRandomMin":0.0,"m_falseLabel":"False","m_intExpression":false,"m_intRandom":false,"m_intRandomMax":0,"m_intRandomMin":0,"m_intValueDecrement":false,"m_intValueIncrement":false,"m_newBooleanValue":false,"m_newDoubleValue":0.0,"m_newIntValue":0,"m_newStringValue":"/books","m_trueLabel":"True","m_userPrompt":false,"m_userPromptEmptyAtStart":false,"m_userPromptPassword":false,"m_userPromptShowCancel":true,"m_userPromptStopAfterCancel":true,"m_variable":{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"target_dir","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},"disableLogging":false,"m_SIGUID":-6845762134556002186,"m_classType":"SetVariableAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"booleanDictionaryKeys":{"keys":[]},"dictionaryKeys":[],"dictionaryOrArrayType":-1,"existingManualKeyType":0,"m_booleanInvert":false,"m_darkMode":-1,"m_doubleRandomMax":0.0,"m_doubleRandomMin":0.0,"m_falseLabel":"False","m_intExpression":false,"m_intRandom":false,"m_intRandomMax":0,"m_intRandomMin":0,"m_intValueDecrement":false,"m_intValueIncrement":false,"m_newBooleanValue":false,"m_newDoubleValue":0.0,"m_newIntValue":0,"m_trueLabel":"True","m_userPrompt":false,"m_userPromptEmptyAtStart":false,"m_userPromptPassword":false,"m_userPromptShowCancel":true,"m_userPromptStopAfterCancel":true,"m_variable":{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"upload_count","m_stringValue":"","m_type":1,"supportsInput":false,"supportsOutput":true},"disableLogging":false,"m_SIGUID":-8185353260764052907,"m_classType":"SetVariableAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"fileExtensions":[],"fileOption":5,"filePattern":"*.epub","fromPath":"{lv=source_dir}","listFilesVariableName":"epub_files","option":4,"waitToComplete":true,"disableLogging":false,"m_SIGUID":-5202805459024432846,"m_classType":"FileOperationAllFilesAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"forEachLoopVariableName":"current_file","forEachSourceArray":"epub_files","forEachLimit":0,"m_actionList":[{"manipulationType":5,"sourceString":"{lv=current_file}","m_variable":{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"filename","m_stringValue":"","m_type":2,"supportsInput":false,"supportsOutput":true},"disableLogging":false,"m_SIGUID":-7123456789012345678,"m_classType":"StringManipulationAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"httpMethod":0,"url":"http://{lv=reader_ip}/api/files?path={lv=target_dir}","timeout":10000,"outputVariable":"file_list","continueOnError":true,"disableLogging":false,"m_SIGUID":-8234567890123456789,"m_classType":"HttpRequestAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"m_constraint":{"lhs_variable":"file_list","lhs_variableType":2,"lhs_value":"","rhs_value":"\"{lv=filename}\"","constraintType":2,"m_not":true,"m_isOrCondition":false},"m_actionList":[{"httpMethod":1,"url":"http://{lv=reader_ip}/upload?path={lv=target_dir}","contentType":"multipart/form-data","fileToUpload":"{lv=current_file}","fileFieldName":"file","timeout":60000,"continueOnError":true,"disableLogging":false,"m_SIGUID":-9345678901234567890,"m_classType":"HttpRequestAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"message":"✓ {lv=filename}","duration":0,"disableLogging":false,"m_SIGUID":-1234567890123456780,"m_classType":"ToastAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"booleanDictionaryKeys":{"keys":[]},"dictionaryKeys":[],"dictionaryOrArrayType":-1,"existingManualKeyType":0,"m_booleanInvert":false,"m_darkMode":-1,"m_doubleRandomMax":0.0,"m_doubleRandomMin":0.0,"m_falseLabel":"False","m_intExpression":true,"m_intRandom":false,"m_intRandomMax":0,"m_intRandomMin":0,"m_intValueDecrement":false,"m_intValueIncrement":false,"m_newBooleanValue":false,"m_newDoubleValue":0.0,"m_newIntValue":0,"m_newStringValue":"{lv=upload_count} + 1","m_trueLabel":"True","m_userPrompt":false,"m_userPromptEmptyAtStart":false,"m_userPromptPassword":false,"m_userPromptShowCancel":true,"m_userPromptStopAfterCancel":true,"m_variable":{"dictionary":{"entries":[],"isArray":false,"variableType":4,"type":"Dictionary"},"isActionBlockWorkingVar":true,"isLocalVar":true,"isSecure":false,"m_booleanValue":false,"m_decimalValue":0.0,"m_intValue":0,"m_name":"upload_count","m_stringValue":"","m_type":1,"supportsInput":false,"supportsOutput":true},"disableLogging":false,"m_SIGUID":-2345678901234567891,"m_classType":"SetVariableAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false}],"disableLogging":false,"m_SIGUID":-3456789012345678902,"m_classType":"IfConditionAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false}],"disableLogging":false,"m_SIGUID":-4567890123456789013,"m_classType":"ForEachLoopAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false},{"title":"Upload Complete","text":"Uploaded {lv=upload_count} file(s)","priority":0,"disableLogging":false,"m_SIGUID":-5678901234567890124,"m_classType":"NotificationAction","m_constraintList":[],"m_isDisabled":false,"m_isOrCondition":false}],"m_category":"File Management","m_constraintList":[],"m_description":"Upload EPUB files to CrossPoint Reader via WiFi","m_descriptionOpen":false,"m_enabled":true,"m_excludeLog":false,"m_headingColor":0,"m_isOrCondition":false,"m_name":"Upload EPUBs to CrossPoint","m_triggerList":[]},"macroExportVersion":1} diff --git a/docs/Upload_EPUBs_to_CrossPoint.tsk.xml b/docs/Upload_EPUBs_to_CrossPoint.tsk.xml new file mode 100644 index 00000000..0b99f6e8 --- /dev/null +++ b/docs/Upload_EPUBs_to_CrossPoint.tsk.xml @@ -0,0 +1,174 @@ + + + 1767235270638 + 1767236697913 + 6 + Upload EPUBs to CrossPoint + + 398 + CrossPoint-Reader + + + 547 + %READER_IP + 192.168.4.1 + + + + + + + + 37 + + + %file_list + 13 + "%filename" + + + + + 339 + false + + + %epub_file:file + java.lang.String + + + + + + + http://%READER_IP/upload?path=%TARGET_DIR + + + + + %upload_response + + + + + 548 + ✓ %filename + + + + 43 + + + 40 + + + 523 + Upload Complete + Processed %EPUB_FILES(#) files + + + + + + + + + + + + + + 30 + + + + + + + + 547 + %SOURCE_DIR + /storage/emulated/0/Documents/ereader + + + + + + + + 547 + %TARGET_DIR + /books + + + + + + + + 412 + %SOURCE_DIR + *.epub + + + + %EPUB_FILES + + + + 39 + %epub_file + %EPUB_FILES() + + + + 590 + %epub_file + / + + + + + 547 + %filename + %epub_file(#) + + + + + + + + 339 + false + + + <StringArray sr=""><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0>%http_cookies +Cookies +The cookies the server sent in the response in the Cookie:COOKIE_VALUE format. You can use this directly in the 'Headers' field of the HTTP Request action</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1>%http_file_output +File Output +Will always contain the file's full path even if you specified a directory as the File to save.</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2>%http_response_code +Response Code +The HTTP Code the server responded</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3>%http_headers() +Response Headers +The HTTP Headers the server sent in the response. Each header is in the 'key:value' format</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3><_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4>%http_response_length +Response Length +The size of the response in bytes</_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4></StringArray> + [Ljava.lang.String; + + + + + + + http://%READER_IP/api/files?path=%TARGET_DIR + + + + + %file_list + + + + + diff --git a/docs/test.sh b/docs/test.sh new file mode 100644 index 00000000..269dd19c --- /dev/null +++ b/docs/test.sh @@ -0,0 +1,10 @@ + # Test 1: Check if curl exists + which curl + echo "---" + # Test 2: Try simple HTTP request + curl -v "http://192.168.4.1/" 2>&1 + echo "---" + # Test 3: Try file upload with simple filename (no spaces) + echo "test" > /sdcard/test.txt + curl -v -X POST -F "file=@/sdcard/test.txt" "http://192.168.4.1/upload?path=/" 2>&1 + \ No newline at end of file diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 73451a05..00000000 --- a/flake.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ - description = "CrossPoint Reader - ESP32 E-Paper Firmware"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; - }; - - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - platformio - python3 - git - ]; - - shellHook = '' - echo "CrossPoint Reader development environment" - echo "Commands:" - echo " pio run - Build firmware" - echo " pio run -t upload - Build and flash to device" - echo " pio run -t clean - Clean build artifacts" - ''; - }; - } - ); -} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 4300dd4b..00000000 --- a/shell.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs ? import {} }: - -pkgs.mkShell { - buildInputs = with pkgs; [ - platformio - python3 - git - ]; - - shellHook = '' - echo "PlatformIO development environment loaded" - echo "Run 'pio run' to build the firmware" - echo "Run 'pio run -t upload' to build and flash" - ''; -} diff --git a/src/CrossPointSettings.cpp b/src/CrossPointSettings.cpp index 480d3bec..01c09e8a 100644 --- a/src/CrossPointSettings.cpp +++ b/src/CrossPointSettings.cpp @@ -12,7 +12,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 = 12; +constexpr uint8_t SETTINGS_COUNT = 13; constexpr char SETTINGS_FILE[] = "/.crosspoint/settings.bin"; } // namespace @@ -39,6 +39,7 @@ bool CrossPointSettings::saveToFile() const { serialization::writePod(outputFile, lineSpacing); serialization::writePod(outputFile, bluetoothEnabled); serialization::writePod(outputFile, useCoverArtPicker); + serialization::writePod(outputFile, autoSleepMinutes); outputFile.close(); Serial.printf("[%lu] [CPS] Settings saved to file\n", millis()); @@ -89,6 +90,8 @@ bool CrossPointSettings::loadFromFile() { if (++settingsRead >= fileSettingsCount) break; serialization::readPod(inputFile, useCoverArtPicker); if (++settingsRead >= fileSettingsCount) break; + serialization::readPod(inputFile, autoSleepMinutes); + if (++settingsRead >= fileSettingsCount) break; } while (false); inputFile.close(); diff --git a/src/CrossPointSettings.h b/src/CrossPointSettings.h index 13b29983..2b5878d0 100644 --- a/src/CrossPointSettings.h +++ b/src/CrossPointSettings.h @@ -66,6 +66,8 @@ class CrossPointSettings { uint8_t bluetoothEnabled = 0; // File browser settings uint8_t useCoverArtPicker = 0; + // Auto-sleep timeout (enum index: 0=5min, 1=10min, 2=15min, 3=20min, 4=30min, 5=60min, 6=Never) + uint8_t autoSleepMinutes = 1; // Default to 10 minutes ~CrossPointSettings() = default; @@ -74,6 +76,19 @@ class CrossPointSettings { uint16_t getPowerButtonDuration() const { return shortPwrBtn ? 10 : 400; } int getReaderFontId() const; + unsigned long getAutoSleepTimeoutMs() const { + // Map enum index to milliseconds: 0=5min, 1=10min, 2=15min, 3=20min, 4=30min, 5=60min, 6=Never(0) + constexpr unsigned long timeouts[] = { + 5UL * 60UL * 1000UL, // 0: 5 minutes + 10UL * 60UL * 1000UL, // 1: 10 minutes (default) + 15UL * 60UL * 1000UL, // 2: 15 minutes + 20UL * 60UL * 1000UL, // 3: 20 minutes + 30UL * 60UL * 1000UL, // 4: 30 minutes + 60UL * 60UL * 1000UL, // 5: 60 minutes + 0UL // 6: Never (disabled) + }; + return (autoSleepMinutes < 7) ? timeouts[autoSleepMinutes] : timeouts[1]; + } bool saveToFile() const; bool loadFromFile(); diff --git a/src/activities/settings/SettingsActivity.cpp b/src/activities/settings/SettingsActivity.cpp index 772eca19..e7a5c46e 100644 --- a/src/activities/settings/SettingsActivity.cpp +++ b/src/activities/settings/SettingsActivity.cpp @@ -9,7 +9,7 @@ // Define the static settings list namespace { -constexpr int settingsCount = 13; +constexpr int settingsCount = 14; const SettingInfo settingsList[settingsCount] = { // Should match with SLEEP_SCREEN_MODE {"Sleep Screen", SettingType::ENUM, &CrossPointSettings::sleepScreen, {"Dark", "Light", "Custom", "Cover"}}, @@ -35,6 +35,10 @@ const SettingInfo settingsList[settingsCount] = { {"Reader Font Size", SettingType::ENUM, &CrossPointSettings::fontSize, {"Small", "Medium", "Large", "X Large"}}, {"Reader Line Spacing", SettingType::ENUM, &CrossPointSettings::lineSpacing, {"Tight", "Normal", "Wide"}}, {"Cover Art Picker", SettingType::TOGGLE, &CrossPointSettings::useCoverArtPicker, {}}, + {"Auto Sleep Timeout", + SettingType::ENUM, + &CrossPointSettings::autoSleepMinutes, + {"5 min", "10 min", "15 min", "20 min", "30 min", "60 min", "Never"}}, {"Bluetooth", SettingType::TOGGLE, &CrossPointSettings::bluetoothEnabled, {}}, {"Check for updates", SettingType::ACTION, nullptr, {}}, }; diff --git a/src/main.cpp b/src/main.cpp index 7f015f41..3e992c6c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,8 +127,6 @@ EpdFont ui12RegularFont(&ubuntu_12_regular); EpdFont ui12BoldFont(&ubuntu_12_bold); EpdFontFamily ui12FontFamily(&ui12RegularFont, &ui12BoldFont); -// Auto-sleep timeout (10 minutes of inactivity) -constexpr unsigned long AUTO_SLEEP_TIMEOUT_MS = 10 * 60 * 1000; // measurement of power button press duration calibration value unsigned long t1 = 0; unsigned long t2 = 0; @@ -330,8 +328,10 @@ void loop() { lastActivityTime = millis(); // Reset inactivity timer } - if (millis() - lastActivityTime >= AUTO_SLEEP_TIMEOUT_MS) { - Serial.printf("[%lu] [SLP] Auto-sleep triggered after %lu ms of inactivity\n", millis(), AUTO_SLEEP_TIMEOUT_MS); + // Check auto-sleep timeout (if enabled - 0 means never sleep) + const unsigned long autoSleepTimeout = SETTINGS.getAutoSleepTimeoutMs(); + if (autoSleepTimeout > 0 && millis() - lastActivityTime >= autoSleepTimeout) { + Serial.printf("[%lu] [SLP] Auto-sleep triggered after %lu ms of inactivity\n", millis(), autoSleepTimeout); enterDeepSleep(); // This should never be hit as `enterDeepSleep` calls esp_deep_sleep_start return;