mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-16 22:27:42 +03:00
Rework after feedback
This commit is contained in:
parent
4d2802422a
commit
c3db4c0503
@ -9,7 +9,7 @@
|
||||
#include "Page.h"
|
||||
#include "parsers/ChapterHtmlSlimParser.h"
|
||||
|
||||
constexpr uint8_t SECTION_FILE_VERSION = 4;
|
||||
constexpr uint8_t SECTION_FILE_VERSION = 5;
|
||||
|
||||
void Section::onPageComplete(std::unique_ptr<Page> page) {
|
||||
const auto filePath = cachePath + "/page_" + std::to_string(pageCount) + ".bin";
|
||||
|
||||
@ -4,24 +4,27 @@
|
||||
#include <SD.h>
|
||||
#include <Serialization.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
|
||||
// Initialize the static instance
|
||||
CrossPointSettings CrossPointSettings::instance;
|
||||
|
||||
constexpr uint8_t SETTINGS_FILE_VERSION = 1;
|
||||
constexpr uint8_t SETTINGS_COUNT = 2;
|
||||
constexpr char SETTINGS_FILE[] = "/sd/.crosspoint/settings.bin";
|
||||
|
||||
bool CrossPointSettings::saveToFile() const {
|
||||
// Make sure the directory exists
|
||||
SD.mkdir("/.crosspoint");
|
||||
|
||||
|
||||
std::ofstream outputFile(SETTINGS_FILE);
|
||||
serialization::writePod(outputFile, SETTINGS_FILE_VERSION);
|
||||
serialization::writePod(outputFile, SETTINGS_COUNT);
|
||||
serialization::writePod(outputFile, whiteSleepScreen);
|
||||
serialization::writePod(outputFile, extraParagraphSpacing);
|
||||
outputFile.close();
|
||||
|
||||
|
||||
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
|
||||
return true;
|
||||
}
|
||||
@ -42,10 +45,21 @@ bool CrossPointSettings::loadFromFile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
serialization::readPod(inputFile, whiteSleepScreen);
|
||||
serialization::readPod(inputFile, extraParagraphSpacing);
|
||||
uint8_t fileSettingsCount = 0;
|
||||
serialization::readPod(inputFile, fileSettingsCount);
|
||||
|
||||
// load settings that exist
|
||||
switch (fileSettingsCount) {
|
||||
case 1:
|
||||
serialization::readPod(inputFile, whiteSleepScreen);
|
||||
break;
|
||||
case 2:
|
||||
serialization::readPod(inputFile, whiteSleepScreen);
|
||||
serialization::readPod(inputFile, extraParagraphSpacing);
|
||||
break;
|
||||
}
|
||||
|
||||
inputFile.close();
|
||||
Serial.printf("[%lu] [CPS] Settings loaded from file\n", millis());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,21 +5,21 @@ class CrossPointSettings {
|
||||
private:
|
||||
// Private constructor for singleton
|
||||
CrossPointSettings() = default;
|
||||
|
||||
|
||||
// Static instance
|
||||
static CrossPointSettings instance;
|
||||
|
||||
|
||||
public:
|
||||
// Delete copy constructor and assignment
|
||||
CrossPointSettings(const CrossPointSettings&) = delete;
|
||||
CrossPointSettings& operator=(const CrossPointSettings&) = delete;
|
||||
|
||||
|
||||
// Sleep screen settings
|
||||
bool whiteSleepScreen = false;
|
||||
|
||||
|
||||
// Text rendering settings
|
||||
bool extraParagraphSpacing = false;
|
||||
|
||||
bool extraParagraphSpacing = true;
|
||||
|
||||
~CrossPointSettings() = default;
|
||||
|
||||
// Get singleton instance
|
||||
@ -32,4 +32,4 @@ class CrossPointSettings {
|
||||
};
|
||||
|
||||
// Helper macro to access settings
|
||||
#define SETTINGS CrossPointSettings::getInstance()
|
||||
#define SETTINGS CrossPointSettings::getInstance()
|
||||
|
||||
@ -133,7 +133,6 @@ void waitForPowerRelease() {
|
||||
// Enter deep sleep mode
|
||||
void enterDeepSleep() {
|
||||
exitScreen();
|
||||
SETTINGS.saveToFile();
|
||||
enterNewScreen(new SleepScreen(renderer, inputManager));
|
||||
|
||||
Serial.printf("[%lu] [ ] Power button released after a long press. Entering deep sleep.\n", millis());
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "config.h"
|
||||
|
||||
// Define the static settings list
|
||||
|
||||
const SettingInfo SettingsScreen::settingsList[SettingsScreen::settingsCount] = {
|
||||
{"White Sleep Screen", &CrossPointSettings::whiteSleepScreen},
|
||||
{"Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing}
|
||||
@ -134,7 +135,7 @@ void SettingsScreen::render() const {
|
||||
}
|
||||
|
||||
// Draw help text
|
||||
renderer.drawText(SMALL_FONT_ID, 20, pageHeight - 40,
|
||||
renderer.drawText(SMALL_FONT_ID, 20, pageHeight - 30,
|
||||
"Press OK to toggle, BACK to save & exit");
|
||||
|
||||
// Always use standard refresh for settings screen
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
@ -13,7 +14,7 @@ class CrossPointSettings;
|
||||
// Structure to hold setting information
|
||||
struct SettingInfo {
|
||||
const char* name; // Display name of the setting
|
||||
bool CrossPointSettings::* valuePtr; // Pointer to member in CrossPointSettings
|
||||
uint8_t CrossPointSettings::* valuePtr; // Pointer to member in CrossPointSettings
|
||||
};
|
||||
|
||||
class SettingsScreen final : public Screen {
|
||||
@ -22,7 +23,7 @@ class SettingsScreen final : public Screen {
|
||||
bool updateRequired = false;
|
||||
int selectedSettingIndex = 0; // Currently selected setting
|
||||
const std::function<void()> onGoHome;
|
||||
|
||||
|
||||
// Static settings list
|
||||
static constexpr int settingsCount = 2; // Number of settings
|
||||
static const SettingInfo settingsList[settingsCount];
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
#pragma once
|
||||
#include "Screen.h"
|
||||
|
||||
class CrossPointSettings;
|
||||
|
||||
class SleepScreen final : public Screen {
|
||||
public:
|
||||
explicit SleepScreen(GfxRenderer& renderer, InputManager& inputManager)
|
||||
: Screen(renderer, inputManager) {}
|
||||
explicit SleepScreen(GfxRenderer& renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user