mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 10:42:21 +01:00
touch ups
This commit is contained in:
@@ -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,15 +290,11 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
// For INACTIVE events, we only process one pad
|
|
||||||
if (!is_touch_event) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// In setup mode, periodically log all pad values
|
// In setup mode, periodically log all pad values
|
||||||
if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > SETUP_MODE_LOG_INTERVAL_MS) {
|
if (this->setup_mode_ && now - this->setup_mode_last_log_print_ > SETUP_MODE_LOG_INTERVAL_MS) {
|
||||||
|
Reference in New Issue
Block a user