diff options
| author | Luke Hoersten <[email protected]> | 2026-06-13 22:42:14 -0500 |
|---|---|---|
| committer | Luke Hoersten <[email protected]> | 2026-06-13 22:42:14 -0500 |
| commit | e7feac61e5ea275f303574fedd942ebed8fc8e73 (patch) | |
| tree | 26bbb23c8faf16294325b27c254df6dd6fbdf1e8 /main/nvs_config.h | |
| parent | e91ed43dee0f2715362fed9f52fa684e655de7be (diff) | |
M4: NVS-backed /config with partial updates + validation
nvs_config.{h,c} — persist the runtime config (viewport, scrypted,
idle_timeout_ms, orientation, brightness) under a single NVS namespace.
nvs_config_load() applies persisted values over the in-RAM defaults on
boot and flips state from UNCONFIGURED to ASLEEP once both name and
Scrypted URL are present. nvs_config_save() commits the whole record
atomically.
http_api.c — add GET /config and POST /config:
- GET serializes viewport_state to the spec's JSON shape, with null
for unset string fields and defaults filled in for the rest.
- POST is partial: each field is optional; only present fields are
validated and applied. Validation runs on a staged copy and errors
short-circuit with 400 + reason before any state mutation, so a
rejected request leaves the device untouched.
- Validation rules: viewport non-empty <64 chars; scrypted starts with
http:// and <256 chars; idle_timeout_ms 0 or >=5000; orientation in
{portrait,landscape}; brightness 0..100.
- Side-effects fire after the lock + save: brightness change pushes
PWM to the panel MCU; viewport/orientation change reapplies mDNS
hostname + TXT.
- 204 on success; 400 with a single-line reason on validation error.
app_main calls nvs_config_load() right after viewport_state_init(), so
mdns_service_start() and display_init() see the persisted hostname,
orientation, and brightness from the first packet/PWM.
Build clean against ESP-IDF 5.4 (binary ~620 KB).
TESTING.md M3 now documents the Hosyond jumper wiring (5V/GND/SDA=GPIO7/
SCL=GPIO8 from board to panel header; DSI FPC carries only the high-
speed lanes). M4 entry expands the validation matrix and side-effects
to verify.
Diffstat (limited to 'main/nvs_config.h')
| -rw-r--r-- | main/nvs_config.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/main/nvs_config.h b/main/nvs_config.h new file mode 100644 index 0000000..7688d81 --- /dev/null +++ b/main/nvs_config.h @@ -0,0 +1,16 @@ +#pragma once + +#include "esp_err.h" + +// Read the persisted config into viewport_state. Safe to call on a fresh +// device: missing keys keep their first-boot defaults from viewport_state_init. +// Sets state = ASLEEP and configured = true if a viewport name + scrypted URL +// are both present. +esp_err_t nvs_config_load(void); + +// Persist the current viewport_state to NVS atomically. The caller is expected +// to have already mutated viewport_state under viewport_state_lock(). +esp_err_t nvs_config_save(void); + +// Clear all persisted config. Caller is responsible for rebooting. +esp_err_t nvs_config_reset(void); |
