Files
roro9stack/lib/services/src/settings.h
T
twislaandClaude Opus 5.5 1a0baf4ac7 M1 step 2: Wi-Fi Service, Saved Networks, NTP, Settings page
- lib/wifi (host-tested): SavedNetworks (up to 8, validated, hidden
  flag, persisted) and WifiController (joins the strongest Saved
  Network, tries hidden ones in turn, backoff 10/30/60 s, connect
  timeout, Monitoring override, radio off without Saved Networks)
- WifiService carries out the controller's actions, sets the EU
  country code, and syncs the Clock over SNTP without touching the TZ
- Wi-Fi On/Off setting; Settings > Wi-Fi page: status, add from a scan
  or a hidden network, forget
- Status Bar: W + signal bars, W? while searching, MON while monitoring
- Serial: wifi add / wifi status (replaces the step 1 heap probe)

Verified on the device: joins the test network ~5 s after boot, clock
set over NTP, ~129 KB free heap while connected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-02 14:46:07 +02:00

64 lines
1.9 KiB
C++

#pragma once
#include <array>
#include <string>
#include "event_bus.h"
#include "key_value_store.h"
namespace roro {
enum class Setting : uint8_t {
SetupDone, // bool: first-boot wizard completed
LongName, // string, 1..39 bytes
ShortName, // string, 1..4 bytes
Region, // string, a known Region ("EU868")
RegionConfirmed, // bool: nothing transmits until true
Timezone, // string, POSIX TZ
Brightness, // int, 10..100 %
DimTimeoutS, // int, 5..600, below OffTimeoutS
OffTimeoutS, // int, 10..3600, above DimTimeoutS
Sound, // bool
ProbeMacRaw, // bool: probe-request Logs keep raw MAC addresses
WifiEnabled, // bool: the Wi-Fi Service stays Connected when a Saved Network is in range
Count
};
// Typed, validated settings in internal flash. Every accepted change is persisted immediately and
// announced with a SettingChanged event; rejected values leave the current value untouched.
class Settings {
public:
Settings(KeyValueStore& store, EventBus& bus);
// Reads every setting; missing or invalid stored values fall back to defaults.
void load();
int32_t getInt(Setting s) const;
bool getBool(Setting s) const;
const std::string& getString(Setting s) const;
bool setInt(Setting s, int32_t value);
bool setBool(Setting s, bool value);
bool setString(Setting s, const std::string& value);
bool canTransmit() const { return getBool(Setting::RegionConfirmed); }
static const char* key(Setting s);
private:
struct Value {
int32_t i = 0;
std::string str;
};
bool validInt(Setting s, int32_t value) const;
bool validString(Setting s, const std::string& value) const;
void changed(Setting s);
KeyValueStore& store_;
EventBus& bus_;
std::array<Value, static_cast<size_t>(Setting::Count)> values_;
};
} // namespace roro