mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 23:27:44 +03:00
## Summary
* This PR drastically reshapes the structure of the codebase, moving
from the concept of "Screens" to "Activities", restructing the files and
setting up the concept of subactivities.
* This should help with keep the main file clean and containing all
functional logic in the relevant activity.
* CrossPointState is now also a global singleton which should help with
accessing it from within activities.
## Additional Context
* This is probably going to be a bit disruptive for people with open
PRs, sorry 😞
40 lines
954 B
C++
40 lines
954 B
C++
#include "CrossPointState.h"
|
|
|
|
#include <HardwareSerial.h>
|
|
#include <SD.h>
|
|
#include <Serialization.h>
|
|
|
|
#include <fstream>
|
|
|
|
namespace {
|
|
constexpr uint8_t STATE_FILE_VERSION = 1;
|
|
constexpr char STATE_FILE[] = "/sd/.crosspoint/state.bin";
|
|
} // namespace
|
|
|
|
CrossPointState CrossPointState::instance;
|
|
|
|
bool CrossPointState::saveToFile() const {
|
|
std::ofstream outputFile(STATE_FILE);
|
|
serialization::writePod(outputFile, STATE_FILE_VERSION);
|
|
serialization::writeString(outputFile, openEpubPath);
|
|
outputFile.close();
|
|
return true;
|
|
}
|
|
|
|
bool CrossPointState::loadFromFile() {
|
|
std::ifstream inputFile(STATE_FILE);
|
|
|
|
uint8_t version;
|
|
serialization::readPod(inputFile, version);
|
|
if (version != STATE_FILE_VERSION) {
|
|
Serial.printf("[%lu] [CPS] Deserialization failed: Unknown version %u\n", millis(), version);
|
|
inputFile.close();
|
|
return false;
|
|
}
|
|
|
|
serialization::readString(inputFile, openEpubPath);
|
|
|
|
inputFile.close();
|
|
return true;
|
|
}
|