From 140792d8a93c62acbdcb7af3f6a3a5c435194fe6 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 12 Jun 2025 14:43:09 +1200 Subject: [PATCH] Fix print --- esphome/components/esp32_touch/esp32_touch.cpp | 14 +++++++++----- esphome/components/esp32_touch/esp32_touch.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/esphome/components/esp32_touch/esp32_touch.cpp b/esphome/components/esp32_touch/esp32_touch.cpp index ff5128f884..3345c862d8 100644 --- a/esphome/components/esp32_touch/esp32_touch.cpp +++ b/esphome/components/esp32_touch/esp32_touch.cpp @@ -293,10 +293,8 @@ uint32_t ESP32TouchComponent::component_touch_pad_read(touch_pad_t tp) { void ESP32TouchComponent::loop() { const uint32_t now = App.get_loop_component_start_time(); - bool should_print = this->setup_mode_ && now - this->setup_mode_last_log_print_ > 250; - if (should_print && this->current_child_ == this->children_.size() - 1) { - // Avoid spamming logs - this->setup_mode_last_log_print_ = now; + if (this->current_child_ == 0) { + this->should_print_ = this->setup_mode_ && now - this->setup_mode_last_log_print_ > 250; } if (this->children_.empty()) { return; @@ -310,11 +308,17 @@ void ESP32TouchComponent::loop() { child->publish_state(child->value_ > child->get_threshold()); #endif - if (should_print) { + if (this->should_print_) { ESP_LOGD(TAG, "Touch Pad '%s' (T%" PRIu32 "): %" PRIu32, child->get_name().c_str(), (uint32_t) child->get_touch_pad(), child->value_); } + if (this->should_print_ && this->current_child_ == this->children_.size() - 1) { + // Avoid spamming logs + this->setup_mode_last_log_print_ = now; + this->should_print_ = false; + } + this->current_child_ = (this->current_child_ + 1) % this->children_.size(); } diff --git a/esphome/components/esp32_touch/esp32_touch.h b/esphome/components/esp32_touch/esp32_touch.h index 38adb02836..d93e9926f2 100644 --- a/esphome/components/esp32_touch/esp32_touch.h +++ b/esphome/components/esp32_touch/esp32_touch.h @@ -75,6 +75,7 @@ class ESP32TouchComponent : public Component { std::vector children_; uint8_t current_child_{0}; bool setup_mode_{false}; + bool should_print_{false}; uint32_t setup_mode_last_log_print_{0}; // common parameters uint16_t sleep_cycle_{4095};