Update auto-sleep timeout options and handle watchdog timer in web server loop

This commit is contained in:
altsysrq 2026-01-03 22:34:30 -06:00
parent 9ab27f848c
commit d3d0f684aa
4 changed files with 24 additions and 13 deletions

View File

@ -66,8 +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
// Auto-sleep timeout (enum index: 0=2min, 1=5min, 2=10min, 3=15min, 4=20min, 5=30min, 6=60min, 7=Never)
uint8_t autoSleepMinutes = 1; // Default to 5 minutes
~CrossPointSettings() = default;
@ -77,17 +77,18 @@ 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)
// 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[] = {
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)
2UL * 60UL * 1000UL, // 0: 2 minutes
5UL * 60UL * 1000UL, // 1: 5 minutes
10UL * 60UL * 1000UL, // 2: 10 minutes (default)
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 < 7) ? timeouts[autoSleepMinutes] : timeouts[1];
return (autoSleepMinutes < 8) ? timeouts[autoSleepMinutes] : timeouts[2];
}
bool saveToFile() const;

View File

@ -4,6 +4,7 @@
#include <ESPmDNS.h>
#include <GfxRenderer.h>
#include <WiFi.h>
#include <esp_task_wdt.h>
#include <qrcode.h>
#include <cstddef>
@ -308,9 +309,14 @@ void CrossPointWebServerActivity::loop() {
// Call handleClient multiple times to process pending requests faster
// This is critical for upload performance - HTTP file uploads send data
// in chunks and each handleClient() call processes incoming data
constexpr int HANDLE_CLIENT_ITERATIONS = 10;
// Reduced from 10 to 3 to prevent watchdog timer issues
constexpr int HANDLE_CLIENT_ITERATIONS = 3;
for (int i = 0; i < HANDLE_CLIENT_ITERATIONS && webServer->isRunning(); i++) {
webServer->handleClient();
// Feed the watchdog timer between iterations to prevent resets
esp_task_wdt_reset();
// Yield to other tasks to prevent starvation
yield();
}
lastHandleClientTime = millis();
}

View File

@ -38,7 +38,7 @@ const SettingInfo settingsList[settingsCount] = {
{"Auto Sleep Timeout",
SettingType::ENUM,
&CrossPointSettings::autoSleepMinutes,
{"5 min", "10 min", "15 min", "20 min", "30 min", "60 min", "Never"}},
{"2 min", "5 min", "10 min", "15 min", "20 min", "30 min", "60 min", "Never"}},
{"Bluetooth", SettingType::TOGGLE, &CrossPointSettings::bluetoothEnabled, {}},
{"Check for updates", SettingType::ACTION, nullptr, {}},
};

View File

@ -6,6 +6,7 @@
#include <SDCardManager.h>
#include <SPI.h>
#include <builtinFonts/all.h>
#include <esp_task_wdt.h>
#include "Battery.h"
#include "CrossPointSettings.h"
@ -359,6 +360,9 @@ void loop() {
}
}
// Feed the watchdog timer to prevent resets during long-running operations
esp_task_wdt_reset();
// Add delay at the end of the loop to prevent tight spinning
// When an activity requests skip loop delay (e.g., webserver running), use yield() for faster response
// Otherwise, use longer delay to save power