2025-12-04 00:07:25 +11:00
|
|
|
#include "CrossPointState.h"
|
|
|
|
|
|
|
|
|
|
#include <HardwareSerial.h>
|
|
|
|
|
#include <SD.h>
|
|
|
|
|
#include <Serialization.h>
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
constexpr uint8_t STATE_VERSION = 1;
|
|
|
|
|
constexpr char STATE_FILE[] = "/sd/.crosspoint/state.bin";
|
|
|
|
|
|
2025-12-06 12:56:39 +11:00
|
|
|
bool CrossPointState::saveToFile() const {
|
|
|
|
|
std::ofstream outputFile(STATE_FILE);
|
|
|
|
|
serialization::writePod(outputFile, STATE_VERSION);
|
|
|
|
|
serialization::writeString(outputFile, openEpubPath);
|
|
|
|
|
outputFile.close();
|
|
|
|
|
return true;
|
2025-12-04 00:07:25 +11:00
|
|
|
}
|
|
|
|
|
|
2025-12-06 12:56:39 +11:00
|
|
|
bool CrossPointState::loadFromFile() {
|
|
|
|
|
std::ifstream inputFile(STATE_FILE);
|
2025-12-04 00:07:25 +11:00
|
|
|
|
|
|
|
|
uint8_t version;
|
2025-12-06 12:56:39 +11:00
|
|
|
serialization::readPod(inputFile, version);
|
2025-12-04 00:07:25 +11:00
|
|
|
if (version != STATE_VERSION) {
|
|
|
|
|
Serial.printf("CrossPointState: Unknown version %u\n", version);
|
2025-12-06 12:56:39 +11:00
|
|
|
inputFile.close();
|
|
|
|
|
return false;
|
2025-12-04 00:07:25 +11:00
|
|
|
}
|
|
|
|
|
|
2025-12-06 12:56:39 +11:00
|
|
|
serialization::readString(inputFile, openEpubPath);
|
2025-12-04 00:07:25 +11:00
|
|
|
|
|
|
|
|
inputFile.close();
|
2025-12-06 12:56:39 +11:00
|
|
|
return true;
|
2025-12-04 00:07:25 +11:00
|
|
|
}
|