Fix print

This commit is contained in:
Jesse Hills 2025-06-12 14:43:09 +12:00
parent 14e6918eb1
commit 140792d8a9
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
2 changed files with 10 additions and 5 deletions

View File

@ -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();
}

View File

@ -75,6 +75,7 @@ class ESP32TouchComponent : public Component {
std::vector<ESP32TouchBinarySensor *> 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};