src.nth.io/

summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-14 18:16:46 -0500
committerLuke Hoersten <[email protected]>2026-06-14 18:16:46 -0500
commit4a6bbdb075a5e4f9910cb9b85e615ff8c50aa4ec (patch)
tree39bf9c7fb9ef39d15bbad3526e16d1c3ddd88dca /main
parentd4fcec3a4d012332e7c476562f9363977ac65561 (diff)
Drop VIEWPORT_STATE_UNCONFIGURED — state is just awake/asleep
\`state\` now reports only the screen's runtime state (awake or asleep). Whether a viewport is set up to talk to Scrypted is a separate \`configured\` flag, derived from \`viewport_name && scrypted_url\`. There's no third state. Behaviour changes: - POST /state always succeeds; the previous 409 "device unconfigured" path is gone. The screen toggles regardless of /config status. - POST /config now sets \`configured\` directly from the derived predicate instead of mutating the state enum. - Outbound state-client POST to Scrypted is still gated on a scrypted URL being present — that's the only thing the configured flag now actually controls in the runtime path. GET /state JSON unchanged in shape, but \`state\` is now never "unconfigured" — that's reported through the existing \`configured\` boolean instead.
Diffstat (limited to 'main')
-rw-r--r--main/http_api.c18
-rw-r--r--main/local_screens.c5
-rw-r--r--main/nvs_config.c2
-rw-r--r--main/state_machine.c12
-rw-r--r--main/state_machine.h5
-rw-r--r--main/viewport_state.h3
6 files changed, 14 insertions, 31 deletions
diff --git a/main/http_api.c b/main/http_api.c
index 5b5769a..dce57bb 100644
--- a/main/http_api.c
+++ b/main/http_api.c
@@ -26,11 +26,7 @@ static const char *TAG = "http_api";
static const char *state_name(viewport_run_state_t s)
{
- switch (s) {
- case VIEWPORT_STATE_AWAKE: return "awake";
- case VIEWPORT_STATE_ASLEEP: return "asleep";
- default: return "unconfigured";
- }
+ return (s == VIEWPORT_STATE_AWAKE) ? "awake" : "asleep";
}
static const char *orientation_name(viewport_orientation_t o)
@@ -246,10 +242,7 @@ static esp_err_t config_post_handler(httpd_req_t *req)
}
// A configured device has both a viewport name and a scrypted URL.
- if (st->viewport_name[0] && st->scrypted_url[0] && !st->configured) {
- st->configured = true;
- if (st->state == VIEWPORT_STATE_UNCONFIGURED) st->state = VIEWPORT_STATE_ASLEEP;
- }
+ st->configured = (st->viewport_name[0] && st->scrypted_url[0]);
viewport_state_unlock();
@@ -304,11 +297,6 @@ static esp_err_t state_post_handler(httpd_req_t *req)
cJSON_Delete(root);
esp_err_t err = state_machine_set(target);
- if (err == ESP_ERR_INVALID_STATE) {
- httpd_resp_set_status(req, "409 Conflict");
- httpd_resp_set_type(req, "text/plain");
- return httpd_resp_send(req, "device unconfigured", HTTPD_RESP_USE_STRLEN);
- }
if (err != ESP_OK) {
httpd_resp_set_status(req, "500 Internal Server Error");
httpd_resp_set_type(req, "text/plain");
@@ -358,7 +346,7 @@ static esp_err_t frame_post_handler(httpd_req_t *req)
return respond_status(req, "500 Internal Server Error", "display not initialized");
}
- // /frame requires AWAKE. Asleep / unconfigured → 409.
+ // /frame requires AWAKE. Asleep → 409.
if (state_machine_current() != VIEWPORT_STATE_AWAKE) {
return respond_status(req, "409 Conflict",
"device asleep — POST /state {\"state\":\"wake\"} first");
diff --git a/main/local_screens.c b/main/local_screens.c
index 4b639ef..7459d9a 100644
--- a/main/local_screens.c
+++ b/main/local_screens.c
@@ -297,10 +297,7 @@ esp_err_t local_screens_show_info(void)
char heap_str[12]; fmt_bytes(heap_str, sizeof(heap_str), free_heap);
char psram_str[12]; fmt_bytes(psram_str, sizeof(psram_str), free_psram);
- const char *state_str =
- (state == VIEWPORT_STATE_AWAKE) ? "awake"
- : (state == VIEWPORT_STATE_ASLEEP) ? "asleep"
- : "unconfigured";
+ const char *state_str = (state == VIEWPORT_STATE_AWAKE) ? "awake" : "asleep";
// Label width is fixed at 8 chars (trailing spaces pad it). Values are
// left-aligned at column 8. Auto-scaler then picks a font scale to fit.
diff --git a/main/nvs_config.c b/main/nvs_config.c
index 164db53..f6a9805 100644
--- a/main/nvs_config.c
+++ b/main/nvs_config.c
@@ -70,7 +70,7 @@ esp_err_t nvs_config_load(void)
? "landscape" : "portrait",
st->brightness);
} else {
- ESP_LOGI(TAG, "partial config in NVS — staying unconfigured");
+ ESP_LOGI(TAG, "partial config in NVS — viewport or scrypted URL still missing");
}
done:
diff --git a/main/state_machine.c b/main/state_machine.c
index 3d95308..a4d4dab 100644
--- a/main/state_machine.c
+++ b/main/state_machine.c
@@ -61,14 +61,14 @@ esp_err_t state_machine_set(viewport_run_state_t target)
if (target == VIEWPORT_STATE_AWAKE) {
if (display_is_up()) {
display_wake();
- // Content choice: configured devices show "Loading…" until
- // Scrypted pushes a /frame; unconfigured devices show the
- // info screen since there's no Scrypted to push anything.
+ // Content choice: a configured device shows "Loading…" until
+ // Scrypted pushes a /frame; a device with no scrypted URL
+ // shows the info screen since there's no Scrypted to push.
if (configured) local_screens_show_loading();
else local_screens_show_info();
}
arm_idle_timer_unlocked();
- ESP_LOGI(TAG, "AWAKE (%s)", configured ? "configured" : "unconfigured");
+ ESP_LOGI(TAG, "AWAKE (%s)", configured ? "configured" : "no scrypted URL");
} else {
disarm_idle_timer();
if (display_is_up()) display_sleep();
@@ -89,8 +89,8 @@ void state_machine_set_local(viewport_run_state_t target)
{
esp_err_t err = state_machine_set(target);
if (err != ESP_OK) return;
- // Only POST when there's a Scrypted to talk to. Unconfigured tap toggles
- // change the local display state without notifying anyone.
+ // Only POST when there's a Scrypted to talk to. Without a scrypted URL,
+ // tap toggles change the local display state without notifying anyone.
viewport_state_lock();
bool configured = viewport_state_get()->configured;
viewport_state_unlock();
diff --git a/main/state_machine.h b/main/state_machine.h
index 8caf670..22aebad 100644
--- a/main/state_machine.h
+++ b/main/state_machine.h
@@ -6,7 +6,6 @@
esp_err_t state_machine_init(void);
// Transition to AWAKE or ASLEEP. Idempotent: no-op if already there.
-// Returns ESP_ERR_INVALID_STATE if the device is unconfigured.
// Side-effects (under one critical section):
// AWAKE -> backlight on, idle timer (re)armed
// ASLEEP -> backlight off, idle timer cancelled, framebuffer discarded
@@ -14,8 +13,8 @@ esp_err_t state_machine_set(viewport_run_state_t target);
// Device-initiated variant (tap, idle timer expiry). Drives the same
// transition as state_machine_set() and additionally enqueues a
-// {viewport,state} POST to <scrypted>/state via state_client.
-// Silently no-ops if the device is unconfigured.
+// {viewport,state} POST to <scrypted>/state via state_client when a
+// `scrypted` URL is configured.
void state_machine_set_local(viewport_run_state_t target);
// Called by /frame after a successful paint. Restarts the idle timer
diff --git a/main/viewport_state.h b/main/viewport_state.h
index b580ff7..3f6147f 100644
--- a/main/viewport_state.h
+++ b/main/viewport_state.h
@@ -13,9 +13,8 @@ typedef enum {
} viewport_orientation_t;
typedef enum {
- VIEWPORT_STATE_UNCONFIGURED = 0,
+ VIEWPORT_STATE_ASLEEP = 0, // boot default; backlight off
VIEWPORT_STATE_AWAKE,
- VIEWPORT_STATE_ASLEEP,
} viewport_run_state_t;
// Read-mostly snapshot of device state used by /state. Counters are