46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#pragma once
|
|
#include <LittleFS.h>
|
|
#include <hardware.pb.h>
|
|
|
|
class HardwareConfigRepo {
|
|
public:
|
|
HardwareConfigRepo();
|
|
~HardwareConfigRepo();
|
|
|
|
// Set callback that gets called when config changes (load/save)
|
|
void setChangeCallback(std::function<void(const hardware_HardwareConfig&)> callback);
|
|
|
|
// Load config from LittleFS, use defaults if file doesn't exist
|
|
bool load();
|
|
|
|
|
|
// Get reference to config data
|
|
hardware_HardwareConfig& getData() { return data_; }
|
|
|
|
// Set config data
|
|
void setData(const hardware_HardwareConfig& newData);
|
|
|
|
// Reset to default values
|
|
void resetToDefaults();
|
|
|
|
private:
|
|
// Save current config to LittleFS
|
|
bool save();
|
|
hardware_HardwareConfig data_;
|
|
const char* filename_ = "/hardware.pb";
|
|
std::function<void(const hardware_HardwareConfig&)> changeCallback_ = nullptr;
|
|
|
|
// Default values
|
|
static constexpr uint32_t DEFAULT_HOLD_DURATION_MS = 5000;
|
|
static constexpr bool DEFAULT_OVERRIDE = false;
|
|
static constexpr uint32_t DEFAULT_RELAY_PIN = 2;
|
|
static constexpr uint32_t DEFAULT_SENSOR_RX_PIN = 16;
|
|
static constexpr uint32_t DEFAULT_SENSOR_TX_PIN = 17;
|
|
|
|
// Helper methods
|
|
void setDefaults();
|
|
bool fileExists();
|
|
void runCallback();
|
|
};
|
|
|
|
extern HardwareConfigRepo hardwareConfigRepo; |