feat: settings manager with NVS persistence
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
71
src/settings.h
Normal file
71
src/settings.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
|
||||
enum class CycleMode : uint8_t {
|
||||
Random = 0,
|
||||
Chronological = 1,
|
||||
ReverseChronological = 2,
|
||||
FavoritesWeighted = 3
|
||||
};
|
||||
|
||||
enum class ImageQuality : uint8_t {
|
||||
Preview = 0,
|
||||
Original = 1
|
||||
};
|
||||
|
||||
enum class MetaPosition : uint8_t {
|
||||
Bottom = 0,
|
||||
Top = 1
|
||||
};
|
||||
|
||||
// Metadata flags bitmask
|
||||
constexpr uint8_t META_DATE = 0x01;
|
||||
constexpr uint8_t META_LOCATION = 0x02;
|
||||
constexpr uint8_t META_PEOPLE = 0x04;
|
||||
constexpr uint8_t META_ALBUM = 0x08;
|
||||
constexpr uint8_t META_CAMERA = 0x10;
|
||||
|
||||
struct Settings {
|
||||
// WiFi
|
||||
String wifi_ssid;
|
||||
String wifi_pass;
|
||||
|
||||
// Immich
|
||||
String immich_url;
|
||||
String immich_key;
|
||||
|
||||
// Slideshow
|
||||
uint8_t interval_min;
|
||||
CycleMode cycle_mode;
|
||||
ImageQuality img_quality;
|
||||
|
||||
// Display
|
||||
uint8_t meta_flags;
|
||||
MetaPosition meta_pos;
|
||||
|
||||
// Device
|
||||
uint8_t led_brightness;
|
||||
uint32_t queue_cursor;
|
||||
String albums_json;
|
||||
};
|
||||
|
||||
class SettingsManager {
|
||||
public:
|
||||
void begin();
|
||||
Settings get();
|
||||
void save(const Settings& s);
|
||||
void saveField(const char* key, uint8_t value);
|
||||
void saveField(const char* key, const char* value);
|
||||
void factoryReset();
|
||||
bool isProvisioned();
|
||||
|
||||
private:
|
||||
String readString(const char* key, const char* defaultValue = "");
|
||||
uint8_t readU8(const char* key, uint8_t defaultValue = 0);
|
||||
uint32_t readU32(const char* key, uint32_t defaultValue = 0);
|
||||
void writeString(const char* key, const String& value);
|
||||
void writeU8(const char* key, uint8_t value);
|
||||
void writeU32(const char* key, uint32_t value);
|
||||
};
|
||||
Reference in New Issue
Block a user