56 lines
1.9 KiB
C++
56 lines
1.9 KiB
C++
#pragma once
|
|
#include <LittleFS.h>
|
|
#include <settings.pb.h>
|
|
|
|
class Settings {
|
|
public:
|
|
Settings();
|
|
~Settings();
|
|
|
|
// Set callback that gets called when settings change
|
|
void setChangeCallback(std::function<void(const settings_SettingsData&)> callback);
|
|
|
|
// Load settings from LittleFS, use defaults if file doesn't exist
|
|
bool load();
|
|
|
|
// Save current settings to LittleFS
|
|
bool save();
|
|
|
|
// Get reference to settings data
|
|
settings_SettingsData& getData() { return data_; }
|
|
|
|
// Set settings data and update timestamp/version
|
|
void setData(const settings_SettingsData& newData);
|
|
|
|
// Reset to default values
|
|
void resetToDefaults();
|
|
|
|
private:
|
|
void runCallback();
|
|
settings_SettingsData data_;
|
|
const char* filename_ = "/settings.pb";
|
|
std::function<void(const settings_SettingsData&)> changeCallback_ = nullptr;
|
|
SemaphoreHandle_t dataMutex_ = nullptr;
|
|
|
|
|
|
// Default values
|
|
static constexpr const char* DEFAULT_SYNC_SERVER_URL = "https://sync.example.com/api";
|
|
static constexpr const char* DEFAULT_DEVICE_API_KEY = "";
|
|
static constexpr uint32_t DEFAULT_SYNC_INTERVAL = 1800;
|
|
static constexpr bool DEFAULT_AUTO_SYNC = true;
|
|
static constexpr settings_WifiMode DEFAULT_WIFI_MODE = settings_WifiMode_WIFI_MODE_AP_STATION;
|
|
static constexpr const char* DEFAULT_STATION_SSID = "HOME";
|
|
static constexpr const char* DEFAULT_STATION_PASSWORD = "redacted";
|
|
static constexpr const char* DEFAULT_AP_SSID = "RFID-Master-AP";
|
|
static constexpr const char* DEFAULT_AP_PASSWORD = "rfid12345";
|
|
static constexpr uint32_t DEFAULT_AP_CHANNEL = 6;
|
|
static constexpr bool DEFAULT_ENABLE_FALLBACK_AP = true;
|
|
static constexpr settings_LogLevel DEFAULT_LOG_LEVEL = settings_LogLevel_LOG_LEVEL_INFO;
|
|
static constexpr uint32_t DEFAULT_VERSION = 1;
|
|
|
|
// Helper methods
|
|
void setDefaults();
|
|
bool fileExists();
|
|
};
|
|
|
|
extern Settings settings; |