Enhance touchscreen functionality: Add buttons for medication control and simplify touch event handling

This commit is contained in:
Joshua King
2026-03-04 17:23:41 -05:00
parent 4aecb61673
commit 58e4ca6c03

View File

@@ -129,6 +129,7 @@ display:
# XPT2046 Touchscreen # XPT2046 Touchscreen
touchscreen: touchscreen:
- platform: xpt2046 - platform: xpt2046
id: my_touchscreen
spi_id: tft_spi spi_id: tft_spi
cs_pin: GPIO33 cs_pin: GPIO33
interrupt_pin: GPIO36 interrupt_pin: GPIO36
@@ -138,34 +139,60 @@ touchscreen:
x_max: 3850 x_max: 3850
y_min: 340 y_min: 340
y_max: 3860 y_max: 3860
on_release:
# Touch buttons as binary sensors
binary_sensor:
- platform: touchscreen
touchscreen_id: my_touchscreen
name: "Penelope Button"
id: penelope_button
x_min: 30
x_max: 210
y_min: 60
y_max: 140
on_press:
then: then:
- lambda: |- - switch.toggle: penelope_medicated
// Ignore touches at edges (phantom touches usually report at extremes)
int touch_x = touch.x;
int touch_y = touch.y;
// Filter out phantom touches (typically at corners/edges) - platform: touchscreen
if (touch_x < 10 || touch_x > 230 || touch_y < 10 || touch_y > 310) { touchscreen_id: my_touchscreen
return; name: "Tess Button"
} id: tess_button
x_min: 30
x_max: 210
y_min: 155
y_max: 235
on_press:
then:
- switch.toggle: tess_medicated
ESP_LOGI("touch", "Valid touch at x=%d, y=%d", touch_x, touch_y); - platform: touchscreen
touchscreen_id: my_touchscreen
name: "Reset Button"
id: reset_button
x_min: 70
x_max: 170
y_min: 260
y_max: 300
on_press:
then:
- switch.turn_off: penelope_medicated
- switch.turn_off: tess_medicated
// Penelope button bounds: x=30-210, y=60-140 - platform: template
if (touch_x >= 30 && touch_x <= 210 && touch_y >= 60 && touch_y <= 140) { name: "Penelope Medication Status"
id(penelope_medicated).toggle(); lambda: 'return id(penelope_medicated).state;'
} device_class: running
// Tess button bounds: x=30-210, y=155-235
else if (touch_x >= 30 && touch_x <= 210 && touch_y >= 155 && touch_y <= 235) { - platform: template
id(tess_medicated).toggle(); name: "Tess Medication Status"
} lambda: 'return id(tess_medicated).state;'
// Reset button bounds: x=70-170, y=260-300 device_class: running
else if (touch_x >= 70 && touch_x <= 170 && touch_y >= 260 && touch_y <= 300) {
id(penelope_medicated).turn_off(); - platform: template
id(tess_medicated).turn_off(); name: "All Cats Medicated"
} lambda: 'return id(penelope_medicated).state && id(tess_medicated).state;'
- script.execute: update_display device_class: running
# Backlight control # Backlight control
output: output:
@@ -210,23 +237,6 @@ switch:
- switch.turn_off: penelope_medicated - switch.turn_off: penelope_medicated
- switch.turn_off: tess_medicated - switch.turn_off: tess_medicated
# Binary sensors for Home Assistant dashboard
binary_sensor:
- platform: template
name: "Penelope Medication Status"
lambda: 'return id(penelope_medicated).state;'
device_class: running
- platform: template
name: "Tess Medication Status"
lambda: 'return id(tess_medicated).state;'
device_class: running
- platform: template
name: "All Cats Medicated"
lambda: 'return id(penelope_medicated).state && id(tess_medicated).state;'
device_class: running
# Script to update display # Script to update display
script: script:
- id: update_display - id: update_display