src.nth.io/

summaryrefslogtreecommitdiff
path: root/main/app_main.c
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-13 23:01:23 -0500
committerLuke Hoersten <[email protected]>2026-06-13 23:01:23 -0500
commit1d6cbb222ced226fcb482c0b19130774d181c8f8 (patch)
tree768d964dc962e111c8c596e10e2da95748bc738a /main/app_main.c
parent57c93fd2978ed5b5e64f4620803b7a2cd7767ed2 (diff)
M7: touch + outbound /state POST to Scrypted
state_client.{h,c}: - Worker task drains a depth-1 queue (xQueueOverwrite gives the replace-on-full semantics from the spec — in-flight POST is never cancelled; the next queued entry is overwritten by newer state). - esp_http_client POST to <scrypted>/state with Content-Type application/ json, User-Agent ScryptedViewport/<version>, Connection: close, 1s timeout. Body: {"viewport":"<name>","state":"wake"|"sleep"}. - Any non-2xx or transport error increments state_post_failures and is otherwise ignored. Silently drops if no Scrypted URL is configured. touch.{h,c}: - FT5426 capacitive touch on the shared I2C bus at 0x38. - 30ms polling task; tracks down/up transitions, detects taps as down-then-up within 500ms with a 150ms debounce. - On tap, toggles wake/sleep via state_machine_set_local(), which drives the local transition AND fires state_client_post() at Scrypted. state_machine adds state_machine_set_local(): runs the same transition as state_machine_set() then enqueues an outbound POST. Idle-timer expiry now uses this path so Scrypted sees idle-driven sleeps too (the spec's "tighten the race with /frame 409" path stays in place as the fallback). display.h exposes display_i2c_bus(); touch.c uses it instead of re-initializing the same I2C port. app_main starts state_client right after the state machine and starts touch after display init (touch is skipped if display isn't up since they share the bus). CMakeLists.txt: add esp_http_client to REQUIRES. Build clean against ESP-IDF 5.4 (binary ~860 KB; jumped ~210 KB from M6 because esp_http_client + cJSON path pulls in tcp_transport, mbedtls, http_parser). TESTING.md M7: flask-based test receiver, tap dispatch verification, failure-path check (kill receiver, confirm counter increments), queue-coalescing behavior, no-POST-on-Scrypted-initiated, no-POST- when-unconfigured.
Diffstat (limited to 'main/app_main.c')
-rw-r--r--main/app_main.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/main/app_main.c b/main/app_main.c
index 126bf15..e7bff0a 100644
--- a/main/app_main.c
+++ b/main/app_main.c
@@ -4,7 +4,9 @@
#include "mdns_service.h"
#include "net_eth.h"
#include "nvs_config.h"
+#include "state_client.h"
#include "state_machine.h"
+#include "touch.h"
#include "viewport_state.h"
#include "esp_event.h"
@@ -32,6 +34,7 @@ void app_main(void)
}
ESP_ERROR_CHECK(state_machine_init());
+ ESP_ERROR_CHECK(state_client_init());
ESP_ERROR_CHECK(mdns_service_start());
ESP_ERROR_CHECK(http_api_start());
@@ -62,6 +65,12 @@ void app_main(void)
ESP_LOGW(TAG, "jpeg decoder init failed — /frame will be unavailable");
}
- // TODO M7: Capacitive touch -> outbound /state POST to <scrypted>/state
+ // Touch shares the panel I2C bus; only meaningful if display came up.
+ if (display_is_up()) {
+ if (touch_init() != ESP_OK) {
+ ESP_LOGW(TAG, "touch init failed — taps won't work");
+ }
+ }
+
// TODO M8: Local screens (IP, loading) + BOOT button
}