Enhance touchscreen handling: Implement backlight control on first touch and debounce touch events to improve responsiveness
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user