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,12 +4,14 @@
#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 {
@ -18,6 +20,7 @@ bool CrossPointSettings::saveToFile() const {
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();
@ -42,8 +45,19 @@ 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());

View File

@ -18,7 +18,7 @@ class CrossPointSettings {
bool whiteSleepScreen = false; bool whiteSleepScreen = false;
// Text rendering settings // Text rendering settings
bool extraParagraphSpacing = false; bool extraParagraphSpacing = true;
~CrossPointSettings() = default; ~CrossPointSettings() = default;

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 {

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;
}; };