From 86be1f56d00159fa3c0032ae67db6f34891fbbf2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 12 Jun 2025 17:14:00 -0500 Subject: [PATCH] preen --- esphome/components/esp32_touch/esp32_touch_v1.cpp | 5 ++++- esphome/components/esp32_touch/esp32_touch_v2.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/esphome/components/esp32_touch/esp32_touch_v1.cpp b/esphome/components/esp32_touch/esp32_touch_v1.cpp index 0f5a65970b..27aa5fc5f4 100644 --- a/esphome/components/esp32_touch/esp32_touch_v1.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v1.cpp @@ -249,7 +249,10 @@ void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) { continue; } - // For original ESP32, lower value means touched + // IMPORTANT: ESP32 v1 touch detection logic - INVERTED compared to v2! + // ESP32 v1: Touch is detected when capacitance INCREASES, causing the measured value to DECREASE + // Therefore: touched = (value < threshold) + // This is opposite to ESP32-S2/S3 v2 where touched = (value > threshold) bool is_touched = value < child->get_threshold(); // Always send the current state - the main loop will filter for changes diff --git a/esphome/components/esp32_touch/esp32_touch_v2.cpp b/esphome/components/esp32_touch/esp32_touch_v2.cpp index e0122202e9..0f3b3f5ebf 100644 --- a/esphome/components/esp32_touch/esp32_touch_v2.cpp +++ b/esphome/components/esp32_touch/esp32_touch_v2.cpp @@ -250,7 +250,10 @@ void ESP32TouchComponent::loop() { touch_pad_read_benchmark(child->get_touch_pad(), &value); } - // For S2/S3 v2, higher value means touched (opposite of v1) + // IMPORTANT: ESP32-S2/S3 v2 touch detection logic - INVERTED compared to v1! + // ESP32-S2/S3 v2: Touch is detected when capacitance INCREASES, causing the measured value to INCREASE + // Therefore: touched = (value > threshold) + // This is opposite to original ESP32 v1 where touched = (value < threshold) bool is_touched = value > child->get_threshold(); child->last_state_ = is_touched; child->publish_state(is_touched);