From 75d1eeeffe162878368b96f7fc50e21e671b47e8 Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Mon, 10 Mar 2025 14:04:34 +1100 Subject: [PATCH] [touchscreen] Axis swap bugfix (#8376) --- esphome/components/touchscreen/touchscreen.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/esphome/components/touchscreen/touchscreen.cpp b/esphome/components/touchscreen/touchscreen.cpp index dfe723aedf..11207908fa 100644 --- a/esphome/components/touchscreen/touchscreen.cpp +++ b/esphome/components/touchscreen/touchscreen.cpp @@ -74,6 +74,9 @@ void Touchscreen::loop() { void Touchscreen::add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw) { TouchPoint tp; uint16_t x, y; + if (this->swap_x_y_) { + std::swap(x_raw, y_raw); + } if (this->touches_.count(id) == 0) { tp.state = STATE_PRESSED; tp.id = id; @@ -90,10 +93,6 @@ void Touchscreen::add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_r x = this->normalize_(x_raw, this->x_raw_min_, this->x_raw_max_, this->invert_x_); y = this->normalize_(y_raw, this->y_raw_min_, this->y_raw_max_, this->invert_y_); - if (this->swap_x_y_) { - std::swap(x, y); - } - tp.x = (uint16_t) ((int) x * this->display_width_ / 0x1000); tp.y = (uint16_t) ((int) y * this->display_height_ / 0x1000); } else {