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

View File

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

View File

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

View File

@ -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());

View File

@ -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

View File

@ -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 {

View File

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