From 5ae4564e6a7804e7d2e5c471a55fcf4613ed9006 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:08:19 +0100 Subject: [PATCH] CodeRabbitAI Nitpick 2 --- .../TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml | 8 ++++---- ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_touch.yaml | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml index 072479e..667b380 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml @@ -148,16 +148,16 @@ script: then: - script.execute: id: touch_on_press_buttons - touch_x: !lambda return touch_x; + touch_position: !lambda return touch_position; - id: touch_on_press_buttons mode: restart parameters: - touch_x: uint8_t + touch_position: uint8_t then: - lambda: |- id(button_press_start_time) = millis(); - id(button_press_position) = touch_x; + id(button_press_position) = touch_position; uint8_t button = 0; auto model_index = sl_tx_model_gang->active_index(); if (model_index.has_value()) { @@ -166,7 +166,7 @@ script: button = 1; // Single button, always 1 } else { const uint8_t step = ${TOUCH_POSITION_MAX_VALUE} / model_idx; // Width of each button region - button = (touch_x / step) + 1; // Determine button region + button = (touch_position / step) + 1; // Determine button region if (button > model_idx) button = model_idx; // Clamp to max button count } diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_touch.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_touch.yaml index b8c8b90..81636b3 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_touch.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_touch.yaml @@ -127,7 +127,7 @@ script: - id: touch_on_press mode: restart parameters: - touch_x: uint8_t + touch_position: uint8_t then: # Extended by: # - HW Buttons @@ -212,10 +212,13 @@ tx_ultimate_easy: on_press: - lambda: |- - ESP_LOGI("tx_ultimate_easy", "Pressed at position %" PRIu8, static_cast(touch.x)); - - script.execute: - id: touch_on_press - touch_x: !lambda return static_cast(touch.x); + const uint8_t touch_position = static_cast(touch.x); + if (touch_position > ${TOUCH_POSITION_MAX_VALUE}) { // Check for valid range + ESP_LOGE("core_hw_buttons", "Invalid touch position: %" PRIu8, touch_position); + } else { + ESP_LOGI("tx_ultimate_easy", "Pressed at position %" PRIu8, touch_position); + touch_on_press->execute(touch_position); + } on_release: - lambda: ESP_LOGI("tx_ultimate_easy", "Released");