From 240fe06229d0edcb77eeb78014b0319e1d233538 Mon Sep 17 00:00:00 2001 From: Joshua King Date: Mon, 2 Mar 2026 21:39:09 -0500 Subject: [PATCH] Enhance touchscreen handling: Implement backlight control on first touch and debounce touch events to improve responsiveness --- esphome/master_bedroom_remote.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/esphome/master_bedroom_remote.yaml b/esphome/master_bedroom_remote.yaml index 2a049e6..45d0f86 100644 --- a/esphome/master_bedroom_remote.yaml +++ b/esphome/master_bedroom_remote.yaml @@ -120,13 +120,22 @@ touchscreen: y_max: 3860 on_touch: - lambda: |- - id(last_interaction_ms) = millis(); + uint32_t now = millis(); + id(last_interaction_ms) = now; + + // Wake backlight on first touch only, don't also trigger a button if (!id(backlight_is_on)) { auto call = id(backlight).turn_on(); call.perform(); id(backlight_is_on) = true; + id(last_button_press_ms) = now; return; } + + // Debounce: ignore repeated touch events within 600ms + if ((uint32_t)(now - id(last_button_press_ms)) < 600) return; + id(last_button_press_ms) = now; + ESP_LOGD("touch", "Touch at x=%d, y=%d", touch.x, touch.y); // Button 1: Toggle All (top-left) @@ -236,6 +245,9 @@ globals: - id: last_interaction_ms type: uint32_t initial_value: "0" + - id: last_button_press_ms + type: uint32_t + initial_value: "0" - id: backlight_is_on type: bool initial_value: "true"