ac7b2da611
Don't use relative imports like `../foo.h` as those depend on the relative position of both files. Rather than that use imports relative to the `src` directory, which explicitly is part of the include directories.
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
#include "components/settings/Settings.h"
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
using namespace Pinetime::Controllers;
|
|
|
|
Settings::Settings(Pinetime::Controllers::FS& fs) : fs {fs} {
|
|
}
|
|
|
|
void Settings::Init() {
|
|
|
|
// Load default settings from Flash
|
|
LoadSettingsFromFile();
|
|
}
|
|
|
|
void Settings::SaveSettings() {
|
|
|
|
// verify if is necessary to save
|
|
if (settingsChanged) {
|
|
SaveSettingsToFile();
|
|
}
|
|
settingsChanged = false;
|
|
}
|
|
|
|
void Settings::LoadSettingsFromFile() {
|
|
SettingsData bufferSettings;
|
|
lfs_file_t settingsFile;
|
|
|
|
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
|
|
return;
|
|
}
|
|
fs.FileRead(&settingsFile, reinterpret_cast<uint8_t*>(&bufferSettings), sizeof(settings));
|
|
fs.FileClose(&settingsFile);
|
|
if ( bufferSettings.version == settingsVersion ) {
|
|
settings = bufferSettings;
|
|
}
|
|
}
|
|
|
|
void Settings::SaveSettingsToFile() {
|
|
lfs_file_t settingsFile;
|
|
|
|
if ( fs.FileOpen(&settingsFile, "/settings.dat", LFS_O_RDWR | LFS_O_CREAT) != LFS_ERR_OK) {
|
|
return;
|
|
}
|
|
fs.FileWrite(&settingsFile, reinterpret_cast<uint8_t*>(&settings), sizeof(settings));
|
|
fs.FileClose(&settingsFile);
|
|
}
|