1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-17 10:42:21 +01:00

touch ups

This commit is contained in:
J. Nick Koston
2025-06-12 13:14:29 -05:00
parent 376be1f009
commit 8517420356

View File

@@ -270,26 +270,15 @@ void ESP32TouchComponent::loop() {
if (event.intr_mask & (TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE)) { if (event.intr_mask & (TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE)) {
bool is_touch_event = (event.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) != 0; bool is_touch_event = (event.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) != 0;
// For INACTIVE events, we check specific pad. For ACTIVE events, check pad status mask // Find the child for the pad that triggered the interrupt
for (auto *child : this->children_) { for (auto *child : this->children_) {
touch_pad_t pad = child->get_touch_pad(); if (child->get_touch_pad() == event.pad) {
bool should_process = false;
if (is_touch_event) {
// ACTIVE event - check if this pad is in the status mask
should_process = (event.pad_status & BIT(pad)) != 0;
} else {
// INACTIVE event - check if this is the specific pad that was released
should_process = (pad == event.pad);
}
if (should_process) {
// Read current value // Read current value
uint32_t value = 0; uint32_t value = 0;
if (this->filter_configured_()) { if (this->filter_configured_()) {
touch_pad_filter_read_smooth(pad, &value); touch_pad_filter_read_smooth(event.pad, &value);
} else { } else {
touch_pad_read_benchmark(pad, &value); touch_pad_read_benchmark(event.pad, &value);
} }
child->value_ = value; child->value_ = value;
@@ -301,11 +290,7 @@ void ESP32TouchComponent::loop() {
ESP_LOGD(TAG, "Touch Pad '%s' %s (value: %d, threshold: %d)", child->get_name().c_str(), ESP_LOGD(TAG, "Touch Pad '%s' %s (value: %d, threshold: %d)", child->get_name().c_str(),
is_touch_event ? "touched" : "released", value, child->get_threshold()); is_touch_event ? "touched" : "released", value, child->get_threshold());
} }
break;
// For INACTIVE events, we only process one pad
if (!is_touch_event) {
break;
}
} }
} }
} }