From cc4495c1fa7f6dd1e81dd32a8c8f773761f24b27 Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 9 Jun 2026 23:03:05 -0600 Subject: [PATCH] dashboard: refresh relay status immediately after command --- .../esp32-s3-dashboard/esp32-s3-dashboard.ino | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino b/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino index 55734c1..4358b63 100644 --- a/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino +++ b/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino @@ -10,7 +10,7 @@ using namespace esp_panel::drivers; using namespace esp_panel::board; -static const char *DASHBOARD_VERSION = "0.0.5-relay-control"; +static const char *DASHBOARD_VERSION = "0.0.6-immediate-relay-refresh"; // Update these if your Cargo ESP AP credentials are different. static const char *CARGO_WIFI_SSID = "OverlandController"; @@ -72,7 +72,7 @@ static String on_off(bool value) return value ? "ON" : "OFF"; } -static void force_status_poll_soon() +static void force_status_poll_now() { last_status_poll_ms = 0; } @@ -137,10 +137,22 @@ static void relay_button_event_cb(lv_event_t *event) bool ok = post_relay_state(relay_id, next_state); - String result_text = ok ? "Relay command sent\nRefreshing status..." : "Relay command failed"; - set_label_text_if_changed(system_label, last_system_text, result_text); + if (ok) { + relay_states[index] = next_state; + update_relay_buttons(); - force_status_poll_soon(); + String optimistic_text = "Relay command sent\n"; + optimistic_text += relay_id; + optimistic_text += " -> "; + optimistic_text += on_off(next_state); + optimistic_text += "\nRefreshing status..."; + set_label_text_if_changed(system_label, last_system_text, optimistic_text); + + force_status_poll_now(); + poll_status_api(); + } else { + set_label_text_if_changed(system_label, last_system_text, "Relay command failed"); + } } static void update_relay_buttons()