diff options
| author | Luke Hoersten <[email protected]> | 2026-06-14 18:30:44 -0500 |
|---|---|---|
| committer | Luke Hoersten <[email protected]> | 2026-06-14 18:30:44 -0500 |
| commit | 186fd85422f99dfb59d89ae9338dc50627f7c3e5 (patch) | |
| tree | 59db53e2962dc815151b9e70a4d6f1ce53c22a98 /main/state_machine.c | |
| parent | 4a6bbdb075a5e4f9910cb9b85e615ff8c50aa4ec (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/state_machine.c')
| -rw-r--r-- | main/state_machine.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/main/state_machine.c b/main/state_machine.c index a4d4dab..0a6d491 100644 --- a/main/state_machine.c +++ b/main/state_machine.c @@ -12,21 +12,15 @@ static const char *TAG = "state"; static esp_timer_handle_t s_idle_timer; -static void arm_idle_timer_unlocked(void) +// ms = idle_timeout_ms snapshotted under the caller's state lock. +// ms == 0 disables the timer (caller's idle_timeout_ms feature). +static void arm_idle_timer(uint32_t ms) { - viewport_state_lock(); - uint32_t ms = viewport_state_get()->idle_timeout_ms; - viewport_state_unlock(); - if (ms == 0) return; esp_timer_stop(s_idle_timer); + if (ms == 0) return; esp_timer_start_once(s_idle_timer, (uint64_t)ms * 1000ULL); } -static void disarm_idle_timer(void) -{ - esp_timer_stop(s_idle_timer); -} - static void idle_timer_fired(void *arg) { ESP_LOGI(TAG, "idle timer expired — sleeping"); @@ -56,6 +50,7 @@ esp_err_t state_machine_set(viewport_run_state_t target) } st->state = target; bool configured = st->configured; + uint32_t idle_ms = st->idle_timeout_ms; viewport_state_unlock(); if (target == VIEWPORT_STATE_AWAKE) { @@ -67,10 +62,10 @@ esp_err_t state_machine_set(viewport_run_state_t target) if (configured) local_screens_show_loading(); else local_screens_show_info(); } - arm_idle_timer_unlocked(); + arm_idle_timer(idle_ms); ESP_LOGI(TAG, "AWAKE (%s)", configured ? "configured" : "no scrypted URL"); } else { - disarm_idle_timer(); + arm_idle_timer(0); if (display_is_up()) display_sleep(); ESP_LOGI(TAG, "ASLEEP"); } @@ -80,9 +75,11 @@ esp_err_t state_machine_set(viewport_run_state_t target) void state_machine_frame_painted(void) { viewport_state_lock(); - bool awake = (viewport_state_get()->state == VIEWPORT_STATE_AWAKE); + viewport_state_t *st = viewport_state_get(); + bool awake = (st->state == VIEWPORT_STATE_AWAKE); + uint32_t idle_ms = st->idle_timeout_ms; viewport_state_unlock(); - if (awake) arm_idle_timer_unlocked(); + if (awake) arm_idle_timer(idle_ms); } void state_machine_set_local(viewport_run_state_t target) |
