mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 23:57:39 +03:00
Update auto-sleep timeout options and handle watchdog timer in web server loop
This commit is contained in:
parent
9ab27f848c
commit
d3d0f684aa
@ -66,8 +66,8 @@ class CrossPointSettings {
|
|||||||
uint8_t bluetoothEnabled = 0;
|
uint8_t bluetoothEnabled = 0;
|
||||||
// File browser settings
|
// File browser settings
|
||||||
uint8_t useCoverArtPicker = 0;
|
uint8_t useCoverArtPicker = 0;
|
||||||
// Auto-sleep timeout (enum index: 0=5min, 1=10min, 2=15min, 3=20min, 4=30min, 5=60min, 6=Never)
|
// 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 10 minutes
|
uint8_t autoSleepMinutes = 1; // Default to 5 minutes
|
||||||
|
|
||||||
~CrossPointSettings() = default;
|
~CrossPointSettings() = default;
|
||||||
|
|
||||||
@ -77,17 +77,18 @@ class CrossPointSettings {
|
|||||||
uint16_t getPowerButtonDuration() const { return shortPwrBtn ? 10 : 400; }
|
uint16_t getPowerButtonDuration() const { return shortPwrBtn ? 10 : 400; }
|
||||||
int getReaderFontId() const;
|
int getReaderFontId() const;
|
||||||
unsigned long getAutoSleepTimeoutMs() 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[] = {
|
constexpr unsigned long timeouts[] = {
|
||||||
5UL * 60UL * 1000UL, // 0: 5 minutes
|
2UL * 60UL * 1000UL, // 0: 2 minutes
|
||||||
10UL * 60UL * 1000UL, // 1: 10 minutes (default)
|
5UL * 60UL * 1000UL, // 1: 5 minutes
|
||||||
15UL * 60UL * 1000UL, // 2: 15 minutes
|
10UL * 60UL * 1000UL, // 2: 10 minutes (default)
|
||||||
20UL * 60UL * 1000UL, // 3: 20 minutes
|
15UL * 60UL * 1000UL, // 3: 15 minutes
|
||||||
30UL * 60UL * 1000UL, // 4: 30 minutes
|
20UL * 60UL * 1000UL, // 4: 20 minutes
|
||||||
60UL * 60UL * 1000UL, // 5: 60 minutes
|
30UL * 60UL * 1000UL, // 5: 30 minutes
|
||||||
0UL // 6: Never (disabled)
|
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;
|
bool saveToFile() const;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include <GfxRenderer.h>
|
#include <GfxRenderer.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <esp_task_wdt.h>
|
||||||
#include <qrcode.h>
|
#include <qrcode.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@ -308,9 +309,14 @@ void CrossPointWebServerActivity::loop() {
|
|||||||
// Call handleClient multiple times to process pending requests faster
|
// Call handleClient multiple times to process pending requests faster
|
||||||
// This is critical for upload performance - HTTP file uploads send data
|
// This is critical for upload performance - HTTP file uploads send data
|
||||||
// in chunks and each handleClient() call processes incoming 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++) {
|
for (int i = 0; i < HANDLE_CLIENT_ITERATIONS && webServer->isRunning(); i++) {
|
||||||
webServer->handleClient();
|
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();
|
lastHandleClientTime = millis();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ const SettingInfo settingsList[settingsCount] = {
|
|||||||
{"Auto Sleep Timeout",
|
{"Auto Sleep Timeout",
|
||||||
SettingType::ENUM,
|
SettingType::ENUM,
|
||||||
&CrossPointSettings::autoSleepMinutes,
|
&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, {}},
|
{"Bluetooth", SettingType::TOGGLE, &CrossPointSettings::bluetoothEnabled, {}},
|
||||||
{"Check for updates", SettingType::ACTION, nullptr, {}},
|
{"Check for updates", SettingType::ACTION, nullptr, {}},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
#include <SDCardManager.h>
|
#include <SDCardManager.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <builtinFonts/all.h>
|
#include <builtinFonts/all.h>
|
||||||
|
#include <esp_task_wdt.h>
|
||||||
|
|
||||||
#include "Battery.h"
|
#include "Battery.h"
|
||||||
#include "CrossPointSettings.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
|
// 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
|
// When an activity requests skip loop delay (e.g., webserver running), use yield() for faster response
|
||||||
// Otherwise, use longer delay to save power
|
// Otherwise, use longer delay to save power
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user