mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 23:27:38 +03:00
Enhance CrossPointSettings with hotspot scheduler settings and update related serialization methods
This commit is contained in:
parent
6bcd01269e
commit
32552e9d91
@ -12,7 +12,7 @@ CrossPointSettings CrossPointSettings::instance;
|
|||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
||||||
// Increment this when adding new persisted settings fields
|
// Increment this when adding new persisted settings fields
|
||||||
constexpr uint8_t SETTINGS_COUNT = 17;
|
constexpr uint8_t SETTINGS_COUNT = 22;
|
||||||
constexpr char SETTINGS_FILE[] = "/.crosspoint/settings.bin";
|
constexpr char SETTINGS_FILE[] = "/.crosspoint/settings.bin";
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -44,6 +44,11 @@ bool CrossPointSettings::saveToFile() const {
|
|||||||
serialization::writeString(outputFile, ftpPassword);
|
serialization::writeString(outputFile, ftpPassword);
|
||||||
serialization::writeString(outputFile, httpUsername);
|
serialization::writeString(outputFile, httpUsername);
|
||||||
serialization::writeString(outputFile, httpPassword);
|
serialization::writeString(outputFile, httpPassword);
|
||||||
|
serialization::writePod(outputFile, hotspotSchedulerEnabled);
|
||||||
|
serialization::writePod(outputFile, hotspotSchedulerHour);
|
||||||
|
serialization::writePod(outputFile, hotspotSchedulerMinute);
|
||||||
|
serialization::writePod(outputFile, hotspotSchedulerShutdownTime);
|
||||||
|
serialization::writePod(outputFile, screenMargin);
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
|
|
||||||
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
||||||
@ -104,6 +109,16 @@ bool CrossPointSettings::loadFromFile() {
|
|||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
serialization::readString(inputFile, httpPassword);
|
serialization::readString(inputFile, httpPassword);
|
||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
|
serialization::readPod(inputFile, hotspotSchedulerEnabled);
|
||||||
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
|
serialization::readPod(inputFile, hotspotSchedulerHour);
|
||||||
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
|
serialization::readPod(inputFile, hotspotSchedulerMinute);
|
||||||
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
|
serialization::readPod(inputFile, hotspotSchedulerShutdownTime);
|
||||||
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
|
serialization::readPod(inputFile, screenMargin);
|
||||||
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
@ -220,3 +235,21 @@ int CrossPointSettings::getReaderFontId() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unsigned int CrossPointSettings::getHotspotShutdownMinutes() const {
|
||||||
|
switch (hotspotSchedulerShutdownTime) {
|
||||||
|
case SHUTDOWN_5_MIN:
|
||||||
|
return 5;
|
||||||
|
case SHUTDOWN_10_MIN:
|
||||||
|
return 10;
|
||||||
|
case SHUTDOWN_15_MIN:
|
||||||
|
return 15;
|
||||||
|
case SHUTDOWN_30_MIN:
|
||||||
|
return 30;
|
||||||
|
case SHUTDOWN_60_MIN:
|
||||||
|
return 60;
|
||||||
|
case SHUTDOWN_120_MIN:
|
||||||
|
return 120;
|
||||||
|
default:
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -53,6 +53,9 @@ class CrossPointSettings {
|
|||||||
// 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 };
|
||||||
|
|
||||||
|
// Hotspot scheduler settings
|
||||||
|
enum HOTSPOT_SHUTDOWN_TIME { SHUTDOWN_5_MIN = 0, SHUTDOWN_10_MIN = 1, SHUTDOWN_15_MIN = 2, SHUTDOWN_30_MIN = 3, SHUTDOWN_60_MIN = 4, SHUTDOWN_120_MIN = 5 };
|
||||||
|
|
||||||
// Sleep screen settings
|
// Sleep screen settings
|
||||||
uint8_t sleepScreen = DARK;
|
uint8_t sleepScreen = DARK;
|
||||||
// Sleep screen cover mode settings
|
// Sleep screen cover mode settings
|
||||||
@ -78,6 +81,8 @@ class CrossPointSettings {
|
|||||||
uint8_t sleepTimeout = SLEEP_10_MIN;
|
uint8_t sleepTimeout = SLEEP_10_MIN;
|
||||||
// E-ink refresh frequency (default 15 pages)
|
// E-ink refresh frequency (default 15 pages)
|
||||||
uint8_t refreshFrequency = REFRESH_15;
|
uint8_t refreshFrequency = REFRESH_15;
|
||||||
|
// Screen margin setting (in pixels, default 0)
|
||||||
|
uint8_t screenMargin = 0;
|
||||||
|
|
||||||
// Network credentials for FTP and HTTP servers
|
// Network credentials for FTP and HTTP servers
|
||||||
std::string ftpUsername = "crosspoint";
|
std::string ftpUsername = "crosspoint";
|
||||||
@ -85,6 +90,12 @@ class CrossPointSettings {
|
|||||||
std::string httpUsername = "crosspoint";
|
std::string httpUsername = "crosspoint";
|
||||||
std::string httpPassword = "reader";
|
std::string httpPassword = "reader";
|
||||||
|
|
||||||
|
// Hotspot scheduler settings
|
||||||
|
uint8_t hotspotSchedulerEnabled = 0; // 0 = disabled, 1 = enabled
|
||||||
|
uint8_t hotspotSchedulerHour = 12; // Hour (0-23)
|
||||||
|
uint8_t hotspotSchedulerMinute = 0; // Minute (0-59)
|
||||||
|
uint8_t hotspotSchedulerShutdownTime = SHUTDOWN_30_MIN; // Default 30 minutes
|
||||||
|
|
||||||
~CrossPointSettings() = default;
|
~CrossPointSettings() = default;
|
||||||
|
|
||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
@ -92,6 +103,7 @@ 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 int getHotspotShutdownMinutes() const;
|
||||||
|
|
||||||
bool saveToFile() const;
|
bool saveToFile() const;
|
||||||
bool loadFromFile();
|
bool loadFromFile();
|
||||||
|
|||||||
@ -75,10 +75,8 @@ void FileTransferActivity::onEnter() {
|
|||||||
|
|
||||||
// Launch protocol selection subactivity
|
// Launch protocol selection subactivity
|
||||||
Serial.printf("[%lu] [FTACT] Launching ProtocolSelectionActivity...\n", millis());
|
Serial.printf("[%lu] [FTACT] Launching ProtocolSelectionActivity...\n", millis());
|
||||||
enterNewActivity(new ProtocolSelectionActivity(renderer, mappedInput,
|
enterNewActivity(new ProtocolSelectionActivity(
|
||||||
[this](const FileTransferProtocol protocol) {
|
renderer, mappedInput, [this](const FileTransferProtocol protocol) { onProtocolSelected(protocol); }));
|
||||||
onProtocolSelected(protocol);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTransferActivity::onExit() {
|
void FileTransferActivity::onExit() {
|
||||||
@ -144,7 +142,8 @@ void FileTransferActivity::onExit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileTransferActivity::onProtocolSelected(const FileTransferProtocol protocol) {
|
void FileTransferActivity::onProtocolSelected(const FileTransferProtocol protocol) {
|
||||||
Serial.printf("[%lu] [FTACT] Protocol selected: %s\n", millis(), protocol == FileTransferProtocol::HTTP ? "HTTP" : "FTP");
|
Serial.printf("[%lu] [FTACT] Protocol selected: %s\n", millis(),
|
||||||
|
protocol == FileTransferProtocol::HTTP ? "HTTP" : "FTP");
|
||||||
|
|
||||||
selectedProtocol = protocol;
|
selectedProtocol = protocol;
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,11 @@ namespace {
|
|||||||
constexpr int settingsCount = 16;
|
constexpr int settingsCount = 16;
|
||||||
const SettingInfo settingsList[settingsCount] = {
|
const SettingInfo settingsList[settingsCount] = {
|
||||||
// Should match with SLEEP_SCREEN_MODE
|
// Should match with SLEEP_SCREEN_MODE
|
||||||
{"Sleep Screen", SettingType::ENUM, &CrossPointSettings::sleepScreen, nullptr, {"Dark", "Light", "Custom", "Cover"}},
|
{"Sleep Screen",
|
||||||
|
SettingType::ENUM,
|
||||||
|
&CrossPointSettings::sleepScreen,
|
||||||
|
nullptr,
|
||||||
|
{"Dark", "Light", "Custom", "Cover"}},
|
||||||
{"Status Bar", SettingType::ENUM, &CrossPointSettings::statusBar, nullptr, {"None", "No Progress", "Full"}},
|
{"Status Bar", SettingType::ENUM, &CrossPointSettings::statusBar, nullptr, {"None", "No Progress", "Full"}},
|
||||||
{"Extra Paragraph Spacing", SettingType::TOGGLE, &CrossPointSettings::extraParagraphSpacing, nullptr, {}},
|
{"Extra Paragraph Spacing", SettingType::TOGGLE, &CrossPointSettings::extraParagraphSpacing, nullptr, {}},
|
||||||
{"Short Power Button Click", SettingType::TOGGLE, &CrossPointSettings::shortPwrBtn, nullptr, {}},
|
{"Short Power Button Click", SettingType::TOGGLE, &CrossPointSettings::shortPwrBtn, nullptr, {}},
|
||||||
@ -37,7 +41,11 @@ const SettingInfo settingsList[settingsCount] = {
|
|||||||
&CrossPointSettings::fontFamily,
|
&CrossPointSettings::fontFamily,
|
||||||
nullptr,
|
nullptr,
|
||||||
{"Bookerly", "Noto Sans", "Open Dyslexic"}},
|
{"Bookerly", "Noto Sans", "Open Dyslexic"}},
|
||||||
{"Reader Font Size", SettingType::ENUM, &CrossPointSettings::fontSize, nullptr, {"Small", "Medium", "Large", "X Large"}},
|
{"Reader Font Size",
|
||||||
|
SettingType::ENUM,
|
||||||
|
&CrossPointSettings::fontSize,
|
||||||
|
nullptr,
|
||||||
|
{"Small", "Medium", "Large", "X Large"}},
|
||||||
{"Reader Line Spacing", SettingType::ENUM, &CrossPointSettings::lineSpacing, nullptr, {"Tight", "Normal", "Wide"}},
|
{"Reader Line Spacing", SettingType::ENUM, &CrossPointSettings::lineSpacing, nullptr, {"Tight", "Normal", "Wide"}},
|
||||||
{"Reader Paragraph Alignment",
|
{"Reader Paragraph Alignment",
|
||||||
SettingType::ENUM,
|
SettingType::ENUM,
|
||||||
|
|||||||
@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
class CrossPointSettings;
|
class CrossPointSettings;
|
||||||
|
|
||||||
enum class SettingType { TOGGLE, ENUM, ACTION, TEXT };
|
enum class SettingType { TOGGLE, ENUM, ACTION, TEXT, VALUE };
|
||||||
|
|
||||||
// Structure to hold setting information
|
// Structure to hold setting information
|
||||||
struct SettingInfo {
|
struct SettingInfo {
|
||||||
const char* name; // Display name of the setting
|
const char* name; // Display name of the setting
|
||||||
SettingType type; // Type of setting
|
SettingType type; // Type of setting
|
||||||
uint8_t CrossPointSettings::* valuePtr; // Pointer to member in CrossPointSettings (for TOGGLE/ENUM)
|
uint8_t CrossPointSettings::* valuePtr; // Pointer to member in CrossPointSettings (for TOGGLE/ENUM)
|
||||||
std::string CrossPointSettings::* stringValuePtr; // Pointer to string member (for TEXT)
|
std::string CrossPointSettings::* stringValuePtr; // Pointer to string member (for TEXT)
|
||||||
std::vector<std::string> enumValues;
|
std::vector<std::string> enumValues;
|
||||||
|
|
||||||
@ -31,17 +31,19 @@ struct SettingInfo {
|
|||||||
|
|
||||||
// Static constructors
|
// Static constructors
|
||||||
static SettingInfo Toggle(const char* name, uint8_t CrossPointSettings::* ptr) {
|
static SettingInfo Toggle(const char* name, uint8_t CrossPointSettings::* ptr) {
|
||||||
return {name, SettingType::TOGGLE, ptr};
|
return {name, SettingType::TOGGLE, ptr, nullptr, {}, {0, 0, 0}};
|
||||||
}
|
}
|
||||||
|
|
||||||
static SettingInfo Enum(const char* name, uint8_t CrossPointSettings::* ptr, std::vector<std::string> values) {
|
static SettingInfo Enum(const char* name, uint8_t CrossPointSettings::* ptr, std::vector<std::string> values) {
|
||||||
return {name, SettingType::ENUM, ptr, std::move(values)};
|
return {name, SettingType::ENUM, ptr, nullptr, std::move(values), {0, 0, 0}};
|
||||||
}
|
}
|
||||||
|
|
||||||
static SettingInfo Action(const char* name) { return {name, SettingType::ACTION, nullptr}; }
|
static SettingInfo Action(const char* name) {
|
||||||
|
return {name, SettingType::ACTION, nullptr, nullptr, {}, {0, 0, 0}};
|
||||||
|
}
|
||||||
|
|
||||||
static SettingInfo Value(const char* name, uint8_t CrossPointSettings::* ptr, const ValueRange valueRange) {
|
static SettingInfo Value(const char* name, uint8_t CrossPointSettings::* ptr, const ValueRange valueRange) {
|
||||||
return {name, SettingType::VALUE, ptr, {}, valueRange};
|
return {name, SettingType::VALUE, ptr, nullptr, {}, valueRange};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -7,9 +7,7 @@
|
|||||||
|
|
||||||
#include "../CrossPointSettings.h"
|
#include "../CrossPointSettings.h"
|
||||||
|
|
||||||
CrossPointFtpServer::~CrossPointFtpServer() {
|
CrossPointFtpServer::~CrossPointFtpServer() { stop(); }
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CrossPointFtpServer::begin() {
|
bool CrossPointFtpServer::begin() {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user