Pass parameters to button_click_event

This commit is contained in:
Edward Firmo
2024-12-22 01:37:07 +01:00
parent 4d8107faf2
commit c65acc3298
3 changed files with 14 additions and 7 deletions

View File

@@ -116,15 +116,18 @@ script:
- id: button_click_event - id: button_click_event
mode: restart mode: restart
parameters:
button_id: uint8_t
click_count: uint8_t
then: then:
- delay: - delay:
milliseconds: ${BUTTON_MULTI_CLICK_DELAY} milliseconds: ${BUTTON_MULTI_CLICK_DELAY}
- lambda: |- - lambda: |-
const std::string button_name = "bs_button_" + std::to_string(id(button_press_button)); const std::string button_name = "bs_button_" + std::to_string(button_id);
std::string event_name; std::string event_name;
if (id(click_counter) == 1) event_name = "click"; if (click_count == 1) event_name = "click";
else if (id(click_counter) == 2) event_name = "double_click"; else if (click_count == 2) event_name = "double_click";
else event_name = std::to_string(id(click_counter)) + "_click"; else event_name = std::to_string(click_count) + "_click";
button_action->execute(button_name.c_str(), event_name.c_str()); button_action->execute(button_name.c_str(), event_name.c_str());
- id: buttons_release - id: buttons_release
@@ -210,7 +213,7 @@ script:
ESP_LOGW("core_hw_buttons", "Ignoring button press (too short)"); ESP_LOGW("core_hw_buttons", "Ignoring button press (too short)");
} else if (press_duration >= ${BUTTON_CLICK_MIN_LENGTH} and } else if (press_duration >= ${BUTTON_CLICK_MIN_LENGTH} and
press_duration <= ${BUTTON_CLICK_MAX_LENGTH}) { // Short/normal click press_duration <= ${BUTTON_CLICK_MAX_LENGTH}) { // Short/normal click
button_click_event->execute(); button_click_event->execute(id(button_press_button), id(click_counter));
} else if (press_duration >= ${BUTTON_LONG_PRESS_DELAY} and press_duration <= ${BUTTON_PRESS_TIMEOUT}) { } else if (press_duration >= ${BUTTON_LONG_PRESS_DELAY} and press_duration <= ${BUTTON_PRESS_TIMEOUT}) {
button_action->execute(("bs_button_" + std::to_string(id(button_press_button))).c_str(), "long_click"); button_action->execute(("bs_button_" + std::to_string(id(button_press_button))).c_str(), "long_click");
} else if (press_duration > ${BUTTON_PRESS_TIMEOUT}) { // Timeout or invalid } else if (press_duration > ${BUTTON_PRESS_TIMEOUT}) { // Timeout or invalid

View File

@@ -113,12 +113,15 @@ script:
- id: !extend button_click_event - id: !extend button_click_event
then: then:
- lambda: |- - lambda: |-
if (id(click_counter) == 1) { // Single click ESP_LOGW("DEBUG", "button_click_event");
ESP_LOGW("DEBUG", " button_id: %" PRIu8, button_id);
ESP_LOGW("DEBUG", " click_count: %" PRIu8, click_count);
if (click_count == 1) { // Single click
if (!bs_multi_touch->state and if (!bs_multi_touch->state and
!bs_swipe_left->state and !bs_swipe_left->state and
!bs_swipe_down->state and !bs_swipe_down->state and
!bs_swipe_right->state) { // Ignore if other events are active !bs_swipe_right->state) { // Ignore if other events are active
switch (id(button_press_button)) { switch (button_id) {
case 1: case 1:
if (sl_button_1_action->active_index().has_value() and if (sl_button_1_action->active_index().has_value() and
sl_button_1_action->active_index().value() == 1) sl_button_1_action->active_index().value() == 1)

View File

@@ -131,6 +131,7 @@ namespace esphome {
state == TOUCH_STATE_SWIPE_LEFT || state == TOUCH_STATE_SWIPE_LEFT ||
state == TOUCH_STATE_SWIPE_RIGHT || state == TOUCH_STATE_SWIPE_RIGHT ||
state == TOUCH_STATE_MULTI_TOUCH) && state == TOUCH_STATE_MULTI_TOUCH) &&
// Multi-touch events may have x < 0, all other events require valid x position
(uart_received_bytes[6] >= 0 || state == TOUCH_STATE_MULTI_TOUCH); (uart_received_bytes[6] >= 0 || state == TOUCH_STATE_MULTI_TOUCH);
} }