src.nth.io/

summaryrefslogtreecommitdiff
path: root/main/viewport_state.h
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-13 22:08:02 -0500
committerLuke Hoersten <[email protected]>2026-06-13 22:08:02 -0500
commit4756daedaefd18919e96fadaabc7f1a00b383b4c (patch)
treeb2eeefb22f53673ac9437920d7447442a205fc8b /main/viewport_state.h
parente2ac22e58901e18b0b567b85d93a8f68335180bc (diff)
M2: HTTP server + mDNS service discovery + shared state
- viewport_state.{h,c}: shared state struct (config, run-state, counters, orientation, timestamps) behind a FreeRTOS mutex. Modules update it under viewport_state_lock(); GET /state serializes a snapshot. - http_api.{h,c}: starts esp_http_server on :80, registers GET /state. Returns the full JSON shape from the spec (name, version, configured, state, uptime_ms, last_frame_ms_ago, frames_received, decode_errors, state_post_failures, resolution, ip, free_heap, free_psram). - mdns_service.{h,c}: mdns_init + advertise _scrypted-viewport._tcp.local on :80 with version/resolution/orientation/name TXT records. mdns_service_refresh() reapplies hostname + TXT after /config writes (called from M4 onward). - main/CMakeLists.txt: add esp_http_server, esp_timer, json, mdns to REQUIRES. espressif/mdns added as managed component via main/idf_component.yml. app_main calls viewport_state_init early so any module can read defaults before /config arrives. Also adds TESTING.md tracking per-milestone verification status and an integration test plan to run after M9 (races, failure modes, longevity, power cycles, negative protocol, multi-viewport). M1 promoted to "🟡 builds clean" in TESTING.md; combined HW verification of M1+M2 will be one flash session. Build verified against ESP-IDF 5.4 for target esp32p4 (binary ~550 KB).
Diffstat (limited to 'main/viewport_state.h')
-rw-r--r--main/viewport_state.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/main/viewport_state.h b/main/viewport_state.h
new file mode 100644
index 0000000..b580ff7
--- /dev/null
+++ b/main/viewport_state.h
@@ -0,0 +1,49 @@
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#define VIEWPORT_VERSION "0.1.0"
+#define VIEWPORT_PANEL_WIDTH 800
+#define VIEWPORT_PANEL_HEIGHT 480
+
+typedef enum {
+ VIEWPORT_ORIENTATION_PORTRAIT = 0, // effective: 480x800
+ VIEWPORT_ORIENTATION_LANDSCAPE, // effective: 800x480
+} viewport_orientation_t;
+
+typedef enum {
+ VIEWPORT_STATE_UNCONFIGURED = 0,
+ VIEWPORT_STATE_AWAKE,
+ VIEWPORT_STATE_ASLEEP,
+} viewport_run_state_t;
+
+// Read-mostly snapshot of device state used by /state. Counters are
+// updated under a mutex by the modules that own them.
+typedef struct {
+ char viewport_name[64]; // empty before /config
+ char scrypted_url[256]; // empty before /config
+ bool configured;
+ viewport_run_state_t state;
+
+ uint8_t brightness; // 0–100, default 80
+ uint32_t idle_timeout_ms; // 0 = disabled, else >= 5000, default 60000
+ viewport_orientation_t orientation; // default portrait
+
+ uint64_t boot_us; // esp_timer_get_time() at boot
+ int64_t last_frame_us; // -1 if no frame received yet
+
+ uint64_t frames_received;
+ uint64_t decode_errors;
+ uint64_t state_post_failures;
+} viewport_state_t;
+
+void viewport_state_init(void);
+viewport_state_t *viewport_state_get(void);
+void viewport_state_lock(void);
+void viewport_state_unlock(void);
+
+// Returns the effective resolution string ("480x800" or "800x480") based
+// on the current orientation. Caller-owned static storage; safe to read
+// without the lock (atomic snapshot).
+const char *viewport_state_resolution_str(void);