src.nth.io/

summaryrefslogtreecommitdiff
path: root/main/http_api.c
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-14 18:30:44 -0500
committerLuke Hoersten <[email protected]>2026-06-14 18:30:44 -0500
commit186fd85422f99dfb59d89ae9338dc50627f7c3e5 (patch)
tree59db53e2962dc815151b9e70a4d6f1ce53c22a98 /main/http_api.c
parent4a6bbdb075a5e4f9910cb9b85e615ff8c50aa4ec (diff)
Tidy: delete dead code, inline single-use helpers, fix double-lock
Code-review pass after the M5 colour fix. -126 net lines (-215 / +89). Dead code removed: - display_fill, display_test_pattern — M3 bring-up self-tests, no callers - net_eth_is_up — no callers - nvs_config_reset — no callers (factory-reset gesture was removed earlier; NVS wipe now goes through `idf.py erase-flash`) Helpers inlined or collapsed (each had one call site): - state_name / orientation_name — ternaries at the cJSON site - fmt_bytes / fmt_uptime — inline scope in local_screens_show_info - expected_dims (http_api) + effective_dims (local_screens) — merged into viewport_state_effective_dims() in viewport_state, one canonical source state_machine cleanup: - arm_idle_timer_unlocked / disarm_idle_timer collapsed to one arm_idle_timer(ms) that takes the snapshotted timeout (ms==0 disables). Removes the misleading name and the second viewport_state lock acquisition per painted frame. - state_machine_set + state_machine_frame_painted now snapshot state + idle_ms under one lock. mdns_service cleanup: - snapshot_state / apply_hostname / apply_txt collapsed into a single apply_state(include_hostname) helper; mdns_service_start grabs hostname once for hostname_set + log instead of going under the lock three times. http_api cleanup: - POST /config brightness-changed path uses the local `bright` it already validated instead of re-locking + re-reading st->brightness. - Trimmed verbose bring-up comments (stack-size justification, M5 saga, DSI shadow struct) to one line each — kept the load-bearing facts. Smoke-tested on hardware: boot clean, display + JPEG + touch all up ([DJT]), info screen renders, no crashes.
Diffstat (limited to 'main/http_api.c')
-rw-r--r--main/http_api.c38
1 files changed, 7 insertions, 31 deletions
diff --git a/main/http_api.c b/main/http_api.c
index dce57bb..028d3a7 100644
--- a/main/http_api.c
+++ b/main/http_api.c
@@ -24,16 +24,6 @@ static const char *TAG = "http_api";
#define MAX_BODY_BYTES 2048
#define MIN_IDLE_TIMEOUT 5000
-static const char *state_name(viewport_run_state_t s)
-{
- return (s == VIEWPORT_STATE_AWAKE) ? "awake" : "asleep";
-}
-
-static const char *orientation_name(viewport_orientation_t o)
-{
- return (o == VIEWPORT_ORIENTATION_LANDSCAPE) ? "landscape" : "portrait";
-}
-
// ============================================================================
// GET /state
// ============================================================================
@@ -54,7 +44,8 @@ static esp_err_t state_get_handler(httpd_req_t *req)
: cJSON_CreateNull());
cJSON_AddStringToObject(root, "version", VIEWPORT_VERSION);
cJSON_AddBoolToObject (root, "configured", st->configured);
- cJSON_AddStringToObject(root, "state", state_name(st->state));
+ cJSON_AddStringToObject(root, "state",
+ (st->state == VIEWPORT_STATE_AWAKE) ? "awake" : "asleep");
cJSON_AddNumberToObject(root, "uptime_ms", (double)up_ms);
cJSON_AddItemToObject (root, "last_frame_ms_ago",
last_age_ms < 0 ? cJSON_CreateNull()
@@ -97,7 +88,8 @@ static esp_err_t config_get_handler(httpd_req_t *req)
st->scrypted_url[0] ? cJSON_CreateString(st->scrypted_url)
: cJSON_CreateNull());
cJSON_AddNumberToObject(root, "idle_timeout_ms", (double)st->idle_timeout_ms);
- cJSON_AddStringToObject(root, "orientation", orientation_name(st->orientation));
+ cJSON_AddStringToObject(root, "orientation",
+ (st->orientation == VIEWPORT_ORIENTATION_LANDSCAPE) ? "landscape" : "portrait");
cJSON_AddNumberToObject(root, "brightness", (double)st->brightness);
viewport_state_unlock();
@@ -254,10 +246,7 @@ static esp_err_t config_post_handler(httpd_req_t *req)
}
if (brightness_changed && display_is_up()) {
- viewport_state_lock();
- uint8_t b = viewport_state_get()->brightness;
- viewport_state_unlock();
- display_set_brightness(b);
+ display_set_brightness(bright);
}
if (name_or_orient_changed) {
mdns_service_refresh();
@@ -317,15 +306,6 @@ static esp_err_t respond_status(httpd_req_t *req, const char *status, const char
return httpd_resp_send(req, body, body ? HTTPD_RESP_USE_STRLEN : 0);
}
-static void expected_dims(uint16_t *w, uint16_t *h)
-{
- viewport_state_lock();
- bool portrait = (viewport_state_get()->orientation == VIEWPORT_ORIENTATION_PORTRAIT);
- viewport_state_unlock();
- if (portrait) { *w = 480; *h = 800; }
- else { *w = 800; *h = 480; }
-}
-
static esp_err_t frame_post_handler(httpd_req_t *req)
{
// Content-Type must be image/jpeg.
@@ -383,7 +363,7 @@ static esp_err_t frame_post_handler(httpd_req_t *req)
}
uint16_t want_w, want_h;
- expected_dims(&want_w, &want_h);
+ viewport_state_effective_dims(&want_w, &want_h);
if (w != want_w || h != want_h) {
viewport_state_lock();
viewport_state_get()->decode_errors++;
@@ -439,11 +419,7 @@ esp_err_t http_api_start(void)
cfg.server_port = 80;
cfg.max_uri_handlers = 8;
cfg.lru_purge_enable = true;
- // Default 4 KiB is tight: /config alone has ~2.4 KiB of stack locals
- // (2 KiB body buffer + 256 B scrypted URL + 64 B name + cJSON frames)
- // and POST /frame pushes a JPEG header onto the stack too. 8 KiB gives
- // both handlers comfortable headroom without doubling RAM usage.
- cfg.stack_size = 8192;
+ cfg.stack_size = 8192; // POST /config alone has ~2.4 KiB of stack locals
httpd_handle_t server = NULL;
ESP_RETURN_ON_ERROR(httpd_start(&server, &cfg), TAG, "httpd_start");