1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-05 19:33:47 +01:00

help with setup

This commit is contained in:
J. Nick Koston
2025-06-12 17:34:24 -05:00
parent 1d90388ffc
commit 88d9361050
2 changed files with 23 additions and 19 deletions

View File

@@ -133,6 +133,11 @@ class ESP32TouchComponent : public Component {
return (this->waterproof_guard_ring_pad_ != TOUCH_PAD_MAX) && return (this->waterproof_guard_ring_pad_ != TOUCH_PAD_MAX) &&
(this->waterproof_shield_driver_ != TOUCH_PAD_SHIELD_DRV_MAX); (this->waterproof_shield_driver_ != TOUCH_PAD_SHIELD_DRV_MAX);
} }
// Helper method to read touch values - non-blocking operation
// Returns the current touch pad value using either filtered or raw reading
// based on the filter configuration
uint32_t read_touch_value(touch_pad_t pad) const;
#endif #endif
// Helper functions for dump_config - common to both implementations // Helper functions for dump_config - common to both implementations

View File

@@ -115,12 +115,7 @@ void ESP32TouchComponent::setup() {
// Read initial states after all hardware is initialized // Read initial states after all hardware is initialized
for (auto *child : this->children_) { for (auto *child : this->children_) {
// Read current value // Read current value
uint32_t value = 0; uint32_t value = this->read_touch_value(child->get_touch_pad());
if (this->filter_configured_()) {
touch_pad_filter_read_smooth(child->get_touch_pad(), &value);
} else {
touch_pad_read_raw_data(child->get_touch_pad(), &value);
}
// IMPORTANT: ESP32-S2/S3 v2 touch detection logic - INVERTED compared to 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 // ESP32-S2/S3 v2: Touch is detected when capacitance INCREASES, causing the measured value to INCREASE
@@ -290,12 +285,7 @@ void ESP32TouchComponent::loop() {
} }
// Read current value // Read current value
uint32_t value = 0; uint32_t value = this->read_touch_value(event.pad);
if (this->filter_configured_()) {
touch_pad_filter_read_smooth(event.pad, &value);
} else {
touch_pad_read_raw_data(event.pad, &value);
}
child->last_state_ = is_touch_event; child->last_state_ = is_touch_event;
child->publish_state(is_touch_event); child->publish_state(is_touch_event);
@@ -309,14 +299,8 @@ void ESP32TouchComponent::loop() {
// 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) {
for (auto *child : this->children_) { for (auto *child : this->children_) {
uint32_t value = 0;
// Read the value being used for touch detection // Read the value being used for touch detection
if (this->filter_configured_()) { uint32_t value = this->read_touch_value(child->get_touch_pad());
touch_pad_filter_read_smooth(child->get_touch_pad(), &value);
} else {
touch_pad_read_raw_data(child->get_touch_pad(), &value);
}
ESP_LOGD(TAG, "Touch Pad '%s' (T%d): %d", child->get_name().c_str(), child->get_touch_pad(), value); ESP_LOGD(TAG, "Touch Pad '%s' (T%d): %d", child->get_name().c_str(), child->get_touch_pad(), value);
} }
@@ -368,6 +352,21 @@ void IRAM_ATTR ESP32TouchComponent::touch_isr_handler(void *arg) {
} }
} }
uint32_t ESP32TouchComponent::read_touch_value(touch_pad_t pad) const {
// Unlike ESP32 v1, touch reads on ESP32-S2/S3 v2 are non-blocking operations.
// The hardware continuously samples in the background and we can read the
// latest value at any time without waiting.
uint32_t value = 0;
if (this->filter_configured_()) {
// Read filtered/smoothed value when filter is enabled
touch_pad_filter_read_smooth(pad, &value);
} else {
// Read raw value when filter is not configured
touch_pad_read_raw_data(pad, &value);
}
return value;
}
} // namespace esp32_touch } // namespace esp32_touch
} // namespace esphome } // namespace esphome