Rework after feedback

This commit is contained in:
Jonas Diemer 2025-12-15 12:49:35 +01:00
parent 4d2802422a
commit c3db4c0503
7 changed files with 33 additions and 21 deletions

View File

@ -9,7 +9,7 @@
#include "Page.h" #include "Page.h"
#include "parsers/ChapterHtmlSlimParser.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) { void Section::onPageComplete(std::unique_ptr<Page> page) {
const auto filePath = cachePath + "/page_" + std::to_string(pageCount) + ".bin"; const auto filePath = cachePath + "/page_" + std::to_string(pageCount) + ".bin";

View File

@ -4,24 +4,27 @@
#include <SD.h> #include <SD.h>
#include <Serialization.h> #include <Serialization.h>
#include <cstdint>
#include <fstream> #include <fstream>
// Initialize the static instance // Initialize the static instance
CrossPointSettings CrossPointSettings::instance; CrossPointSettings CrossPointSettings::instance;
constexpr uint8_t SETTINGS_FILE_VERSION = 1; constexpr uint8_t SETTINGS_FILE_VERSION = 1;
constexpr uint8_t SETTINGS_COUNT = 2;
constexpr char SETTINGS_FILE[] = "/sd/.crosspoint/settings.bin"; constexpr char SETTINGS_FILE[] = "/sd/.crosspoint/settings.bin";
bool CrossPointSettings::saveToFile() const { bool CrossPointSettings::saveToFile() const {
// Make sure the directory exists // Make sure the directory exists
SD.mkdir("/.crosspoint"); SD.mkdir("/.crosspoint");
std::ofstream outputFile(SETTINGS_FILE); std::ofstream outputFile(SETTINGS_FILE);
serialization::writePod(outputFile, SETTINGS_FILE_VERSION); serialization::writePod(outputFile, SETTINGS_FILE_VERSION);
serialization::writePod(outputFile, SETTINGS_COUNT);
serialization::writePod(outputFile, whiteSleepScreen); serialization::writePod(outputFile, whiteSleepScreen);
serialization::writePod(outputFile, extraParagraphSpacing); serialization::writePod(outputFile, extraParagraphSpacing);
outputFile.close(); outputFile.close();
Serial.printf("[%lu] [CPS] Settings saved to file\n", millis()); Serial.printf("[%lu] [CPS] Settings saved to file\n", millis());
return true; return true;
} }
@ -42,10 +45,21 @@ bool CrossPointSettings::loadFromFile() {
return false; return false;
} }
serialization::readPod(inputFile, whiteSleepScreen); uint8_t fileSettingsCount = 0;
serialization::readPod(inputFile, extraParagraphSpacing); 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(); inputFile.close();
Serial.printf("[%lu] [CPS] Settings loaded from file\n", millis()); Serial.printf("[%lu] [CPS] Settings loaded from file\n", millis());
return true; return true;
} }

View File

@ -5,21 +5,21 @@ class CrossPointSettings {
private: private:
// Private constructor for singleton // Private constructor for singleton
CrossPointSettings() = default; CrossPointSettings() = default;
// Static instance // Static instance
static CrossPointSettings instance; static CrossPointSettings instance;
public: public:
// Delete copy constructor and assignment // Delete copy constructor and assignment
CrossPointSettings(const CrossPointSettings&) = delete; CrossPointSettings(const CrossPointSettings&) = delete;
CrossPointSettings& operator=(const CrossPointSettings&) = delete; CrossPointSettings& operator=(const CrossPointSettings&) = delete;
// Sleep screen settings // Sleep screen settings
bool whiteSleepScreen = false; bool whiteSleepScreen = false;
// Text rendering settings // Text rendering settings
bool extraParagraphSpacing = false; bool extraParagraphSpacing = true;
~CrossPointSettings() = default; ~CrossPointSettings() = default;
// Get singleton instance // Get singleton instance
@ -32,4 +32,4 @@ class CrossPointSettings {
}; };
// Helper macro to access settings // Helper macro to access settings
#define SETTINGS CrossPointSettings::getInstance() #define SETTINGS CrossPointSettings::getInstance()

View File

@ -133,7 +133,6 @@ void waitForPowerRelease() {
// Enter deep sleep mode // Enter deep sleep mode
void enterDeepSleep() { void enterDeepSleep() {
exitScreen(); exitScreen();
SETTINGS.saveToFile();
enterNewScreen(new SleepScreen(renderer, inputManager)); enterNewScreen(new SleepScreen(renderer, inputManager));
Serial.printf("[%lu] [ ] Power button released after a long press. Entering deep sleep.\n", millis()); Serial.printf("[%lu] [ ] Power button released after a long press. Entering deep sleep.\n", millis());

View File

@ -6,6 +6,7 @@
#include "config.h" #include "config.h"
// Define the static settings list // Define the static settings list
const SettingInfo SettingsScreen::settingsList[SettingsScreen::settingsCount] = { const SettingInfo SettingsScreen::settingsList[SettingsScreen::settingsCount] = {
{"White Sleep Screen", &CrossPointSettings::whiteSleepScreen}, {"White Sleep Screen", &CrossPointSettings::whiteSleepScreen},
{"Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing} {"Extra Paragraph Spacing", &CrossPointSettings::extraParagraphSpacing}
@ -134,7 +135,7 @@ void SettingsScreen::render() const {
} }
// Draw help text // 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"); "Press OK to toggle, BACK to save & exit");
// Always use standard refresh for settings screen // Always use standard refresh for settings screen

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <cstdint>
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/semphr.h> #include <freertos/semphr.h>
#include <freertos/task.h> #include <freertos/task.h>
@ -13,7 +14,7 @@ class CrossPointSettings;
// 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
bool CrossPointSettings::* valuePtr; // Pointer to member in CrossPointSettings uint8_t CrossPointSettings::* valuePtr; // Pointer to member in CrossPointSettings
}; };
class SettingsScreen final : public Screen { class SettingsScreen final : public Screen {
@ -22,7 +23,7 @@ class SettingsScreen final : public Screen {
bool updateRequired = false; bool updateRequired = false;
int selectedSettingIndex = 0; // Currently selected setting int selectedSettingIndex = 0; // Currently selected setting
const std::function<void()> onGoHome; const std::function<void()> onGoHome;
// Static settings list // Static settings list
static constexpr int settingsCount = 2; // Number of settings static constexpr int settingsCount = 2; // Number of settings
static const SettingInfo settingsList[settingsCount]; static const SettingInfo settingsList[settingsCount];

View File

@ -1,11 +1,8 @@
#pragma once #pragma once
#include "Screen.h" #include "Screen.h"
class CrossPointSettings;
class SleepScreen final : public Screen { class SleepScreen final : public Screen {
public: public:
explicit SleepScreen(GfxRenderer& renderer, InputManager& inputManager) explicit SleepScreen(GfxRenderer& renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
: Screen(renderer, inputManager) {}
void onEnter() override; void onEnter() override;
}; };