1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-02 16:11:53 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Jesse Hills
140792d8a9 Fix print 2025-06-12 14:43:09 +12:00
Jesse Hills
14e6918eb1 Print all children 2025-06-12 14:32:42 +12:00
Jesse Hills
a794a8f3e4 [esp32_touch] Only read one touch sensor per loop 2025-06-12 14:26:38 +12:00
2 changed files with 23 additions and 15 deletions

View File

@@ -2,8 +2,8 @@
#include "esp32_touch.h" #include "esp32_touch.h"
#include "esphome/core/application.h" #include "esphome/core/application.h"
#include "esphome/core/log.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include <cinttypes> #include <cinttypes>
@@ -293,27 +293,33 @@ uint32_t ESP32TouchComponent::component_touch_pad_read(touch_pad_t tp) {
void ESP32TouchComponent::loop() { void ESP32TouchComponent::loop() {
const uint32_t now = App.get_loop_component_start_time(); 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 (this->current_child_ == 0) {
for (auto *child : this->children_) { this->should_print_ = this->setup_mode_ && now - this->setup_mode_last_log_print_ > 250;
child->value_ = this->component_touch_pad_read(child->get_touch_pad()); }
if (this->children_.empty()) {
return;
}
auto *child = this->children_[this->current_child_];
child->value_ = this->component_touch_pad_read(child->get_touch_pad());
#if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) #if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3))
child->publish_state(child->value_ < child->get_threshold()); child->publish_state(child->value_ < child->get_threshold());
#else #else
child->publish_state(child->value_ > child->get_threshold()); child->publish_state(child->value_ > child->get_threshold());
#endif #endif
if (should_print) { if (this->should_print_) {
ESP_LOGD(TAG, "Touch Pad '%s' (T%" PRIu32 "): %" PRIu32, child->get_name().c_str(), ESP_LOGD(TAG, "Touch Pad '%s' (T%" PRIu32 "): %" PRIu32, child->get_name().c_str(),
(uint32_t) child->get_touch_pad(), child->value_); (uint32_t) child->get_touch_pad(), child->value_);
}
App.feed_wdt();
} }
if (should_print) { if (this->should_print_ && this->current_child_ == this->children_.size() - 1) {
// Avoid spamming logs // Avoid spamming logs
this->setup_mode_last_log_print_ = now; this->setup_mode_last_log_print_ = now;
this->should_print_ = false;
} }
this->current_child_ = (this->current_child_ + 1) % this->children_.size();
} }
void ESP32TouchComponent::on_shutdown() { void ESP32TouchComponent::on_shutdown() {

View File

@@ -2,9 +2,9 @@
#ifdef USE_ESP32 #ifdef USE_ESP32
#include "esphome/core/component.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
#include <esp_idf_version.h> #include <esp_idf_version.h>
#include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/core/component.h"
#include <vector> #include <vector>
@@ -73,7 +73,9 @@ class ESP32TouchComponent : public Component {
#endif #endif
std::vector<ESP32TouchBinarySensor *> children_; std::vector<ESP32TouchBinarySensor *> children_;
uint8_t current_child_{0};
bool setup_mode_{false}; bool setup_mode_{false};
bool should_print_{false};
uint32_t setup_mode_last_log_print_{0}; uint32_t setup_mode_last_log_print_{0};
// common parameters // common parameters
uint16_t sleep_cycle_{4095}; uint16_t sleep_cycle_{4095};