240 lines
7.0 KiB
YAML
240 lines
7.0 KiB
YAML
####################################################################################################
|
|
##### TX Ultimate Easy for ESPHome #####
|
|
##### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy #####
|
|
####################################################################################################
|
|
##### Purpose: ESPHome Core - Hardware - Touch panel #####
|
|
####################################################################################################
|
|
##### Author: edwardtfn - https://github.com/edwardtfn - https://buymeacoffee.com/edwardfirmo #####
|
|
####################################################################################################
|
|
##### NOTE: #####
|
|
##### - Make changes ONLY if absolutely necessary and you have the required knowledge. #####
|
|
##### - For normal system use, modifications to this file are NOT required. #####
|
|
####################################################################################################
|
|
---
|
|
binary_sensor:
|
|
- id: bs_multi_touch
|
|
name: Multi-touch
|
|
icon: mdi:gesture-two-tap
|
|
internal: false
|
|
platform: template
|
|
on_click:
|
|
then:
|
|
- lambda: send_event_to_ha->execute("multi_touch", "multi_touch");
|
|
|
|
- id: bs_swipe_left
|
|
name: Swipe left
|
|
icon: mdi:gesture-swipe-left
|
|
internal: true
|
|
platform: template
|
|
on_click:
|
|
then:
|
|
- lambda: send_event_to_ha->execute("swipe", "left");
|
|
|
|
- id: bs_swipe_right
|
|
name: Swipe right
|
|
icon: mdi:gesture-swipe-right
|
|
internal: true
|
|
platform: template
|
|
on_click:
|
|
then:
|
|
- lambda: send_event_to_ha->execute("swipe", "right");
|
|
|
|
- id: bs_swipe_up
|
|
name: Swipe up
|
|
icon: mdi:gesture-swipe-up
|
|
internal: true
|
|
platform: template
|
|
on_click:
|
|
then:
|
|
- lambda: send_event_to_ha->execute("swipe", "up");
|
|
|
|
- id: bs_swipe_down
|
|
name: Swipe down
|
|
icon: mdi:gesture-swipe-down
|
|
internal: true
|
|
platform: template
|
|
on_click:
|
|
then:
|
|
- lambda: send_event_to_ha->execute("swipe", "down");
|
|
|
|
external_components:
|
|
- source:
|
|
type: git
|
|
url: https://github.com/edwardtfn/TX-Ultimate-Easy
|
|
ref: ${version}
|
|
refresh: 1h
|
|
components:
|
|
- tx_ultimate_easy
|
|
|
|
number:
|
|
- id: nr_touch_duration
|
|
name: Touch duration
|
|
icon: mdi:timer-cog-outline
|
|
unit_of_measurement: ms
|
|
# mode: box
|
|
internal: false
|
|
entity_category: config
|
|
platform: template
|
|
min_value: 10
|
|
max_value: 1500
|
|
step: 1
|
|
initial_value: 250
|
|
optimistic: true
|
|
restore_value: true
|
|
|
|
script:
|
|
- id: !extend boot_initialize
|
|
then:
|
|
- script.execute: boot_initialize_touch
|
|
|
|
- id: boot_initialize_touch
|
|
mode: restart
|
|
then:
|
|
- wait_until:
|
|
condition:
|
|
- lambda: return sl_tx_model_format->active_index().has_value();
|
|
- lambda: |-
|
|
const bool is_model_us = sl_tx_model_format->active_index().has_value() and
|
|
sl_tx_model_format->active_index().value() == 1;
|
|
bs_multi_touch->publish_state(false);
|
|
bs_swipe_down->publish_state(false);
|
|
bs_swipe_down->set_internal(!is_model_us);
|
|
bs_swipe_left->publish_state(false);
|
|
bs_swipe_left->set_internal(is_model_us);
|
|
bs_swipe_right->publish_state(false);
|
|
bs_swipe_right->set_internal(is_model_us);
|
|
bs_swipe_up->publish_state(false);
|
|
bs_swipe_up->set_internal(!is_model_us);
|
|
|
|
- id: touch_on_multi_touch_release
|
|
mode: restart
|
|
then:
|
|
# Extended by:
|
|
# - HW Buttons
|
|
# - HW Vibration
|
|
- script.execute: touch_on_multi_touch_release_touch
|
|
|
|
- id: touch_on_multi_touch_release_touch
|
|
mode: restart
|
|
then:
|
|
- lambda: bs_multi_touch->publish_state(true);
|
|
- delay: !lambda return nr_touch_duration->state;
|
|
- lambda: bs_multi_touch->publish_state(false);
|
|
|
|
- id: touch_on_press
|
|
mode: restart
|
|
parameters:
|
|
touch_x: uint8_t
|
|
then:
|
|
# Extended by:
|
|
# - HW Buttons
|
|
# - HW Vibration
|
|
|
|
- id: touch_on_release
|
|
mode: restart
|
|
then:
|
|
# Extended by:
|
|
# - HW Buttons
|
|
# - HW Vibration
|
|
- script.execute: touch_swipe_turn_off_binary_sensor
|
|
|
|
- id: touch_swipe_left
|
|
mode: restart
|
|
then:
|
|
# Extended by:
|
|
# - HW Buttons
|
|
- script.execute: touch_swipe_left_touch
|
|
|
|
- id: touch_swipe_left_touch
|
|
mode: restart
|
|
then:
|
|
- binary_sensor.template.publish:
|
|
id: bs_swipe_left
|
|
state: ON # yamllint disable-line rule:truthy
|
|
- delay: !lambda return nr_touch_duration->state;
|
|
- script.execute: touch_swipe_turn_off_binary_sensor
|
|
|
|
- id: touch_swipe_right
|
|
mode: restart
|
|
then:
|
|
# Extended by:
|
|
# - HW Buttons
|
|
- script.execute: touch_swipe_right_touch
|
|
|
|
- id: touch_swipe_right_touch
|
|
mode: restart
|
|
then:
|
|
- binary_sensor.template.publish:
|
|
id: bs_swipe_right
|
|
state: ON # yamllint disable-line rule:truthy
|
|
- delay: !lambda return nr_touch_duration->state;
|
|
- script.execute: touch_swipe_turn_off_binary_sensor
|
|
|
|
- id: touch_swipe_turn_off_binary_sensor
|
|
mode: restart
|
|
then:
|
|
- if:
|
|
condition:
|
|
binary_sensor.is_on: bs_swipe_left
|
|
then:
|
|
- binary_sensor.template.publish:
|
|
id: bs_swipe_left
|
|
state: OFF # yamllint disable-line rule:truthy
|
|
- if:
|
|
condition:
|
|
binary_sensor.is_on: bs_swipe_right
|
|
then:
|
|
- binary_sensor.template.publish:
|
|
id: bs_swipe_right
|
|
state: OFF # yamllint disable-line rule:truthy
|
|
|
|
switch:
|
|
- id: sw_touch_panel_power
|
|
name: Touch panel - Power
|
|
platform: gpio
|
|
pin:
|
|
number: GPIO5
|
|
inverted: true
|
|
restore_mode: ALWAYS_ON
|
|
internal: false
|
|
entity_category: config
|
|
|
|
tx_ultimate_easy:
|
|
id: tx_ultimate
|
|
uart: uart_touch
|
|
|
|
on_multi_touch_release:
|
|
- lambda: ESP_LOGI("tx_ultimate_easy", "Multi-touch released");
|
|
- script.execute: touch_on_multi_touch_release
|
|
|
|
on_press:
|
|
- lambda: ESP_LOGI("tx_ultimate_easy", "Pressed");
|
|
- script.execute:
|
|
id: touch_on_press
|
|
touch_x: !lambda return static_cast<uint8_t>(touch.x);
|
|
|
|
on_release:
|
|
- lambda: ESP_LOGI("tx_ultimate_easy", "Released");
|
|
- script.execute: touch_on_release
|
|
|
|
on_swipe_left:
|
|
- lambda: ESP_LOGI("tx_ultimate_easy", "Swipe left");
|
|
- script.execute: touch_swipe_left
|
|
|
|
on_swipe_right:
|
|
- lambda: ESP_LOGI("tx_ultimate_easy", "Swipe right");
|
|
- script.execute: touch_swipe_right
|
|
|
|
on_touch_event:
|
|
- lambda: |-
|
|
ESP_LOGD("tx_ultimate_easy", "Touch event:");
|
|
ESP_LOGD("tx_ultimate_easy", " State: %i (%s)", touch.state, touch.state_str.c_str());
|
|
ESP_LOGD("tx_ultimate_easy", " Position: %i", touch.x);
|
|
|
|
uart:
|
|
id: uart_touch
|
|
tx_pin: GPIO19
|
|
rx_pin: GPIO22
|
|
baud_rate: 115200
|
|
...
|