src.nth.io/

summaryrefslogtreecommitdiff
path: root/main/state_machine.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/state_machine.c')
-rw-r--r--main/state_machine.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/main/state_machine.c b/main/state_machine.c
index 22f3f56..2808738 100644
--- a/main/state_machine.c
+++ b/main/state_machine.c
@@ -5,6 +5,7 @@
#include "esp_timer.h"
#include "display.h"
+#include "state_client.h"
static const char *TAG = "state";
@@ -28,8 +29,7 @@ static void disarm_idle_timer(void)
static void idle_timer_fired(void *arg)
{
ESP_LOGI(TAG, "idle timer expired — sleeping");
- state_machine_set(VIEWPORT_STATE_ASLEEP);
- // TODO M7: state_client_post(VIEWPORT_STATE_ASLEEP); // tell Scrypted
+ state_machine_set_local(VIEWPORT_STATE_ASLEEP);
}
esp_err_t state_machine_init(void)
@@ -80,6 +80,16 @@ void state_machine_frame_painted(void)
if (awake) arm_idle_timer_unlocked();
}
+void state_machine_set_local(viewport_run_state_t target)
+{
+ // For idempotent no-op (already in target), state_machine_set returns OK
+ // without changing state; we still call state_client to keep Scrypted in
+ // sync if it's drifted. State POSTs are idempotent on both ends.
+ esp_err_t err = state_machine_set(target);
+ if (err != ESP_OK) return; // unconfigured / invalid
+ state_client_post(target);
+}
+
viewport_run_state_t state_machine_current(void)
{
viewport_state_lock();