src.nth.io/

summaryrefslogtreecommitdiff
path: root/main/http_api.c
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/http_api.c
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/http_api.c')
-rw-r--r--main/http_api.c18
1 files changed, 3 insertions, 15 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");