10namespace esp32_touch {
12static const char *
const TAG =
"esp32_touch";
20 "Config for ESP32 Touch Hub:\n"
21 " Meas cycle: %.2fms\n"
22 " Sleep cycle: %.2fms\n"
23 " Low Voltage Reference: %s\n"
24 " High Voltage Reference: %s\n"
25 " Voltage Attenuation: %s\n"
26 " Release Timeout: %" PRIu32
"ms\n",
33 LOG_BINARY_SENSOR(
" ",
"Touch Pad", child);
36 " Threshold: %" PRIu32
"\n"
37 " Benchmark: %" PRIu32,
38 (
unsigned) child->touch_pad_, child->threshold_, child->benchmark_);
45 size_t queue_size = this->
children_.size() * 4;
49#ifdef USE_ESP32_VARIANT_ESP32
50 this->
touch_queue_ = xQueueCreate(queue_size,
sizeof(TouchPadEventV1));
52 this->
touch_queue_ = xQueueCreate(queue_size,
sizeof(TouchPadEventV2));
56 ESP_LOGE(TAG,
"Failed to create touch event queue of size %" PRIu32, (uint32_t) queue_size);
71 bool is_wakeup_source =
false;
75 if (child->get_wakeup_threshold() != 0) {
76 is_wakeup_source =
true;
78#ifdef USE_ESP32_VARIANT_ESP32
80 touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold());
83 touch_pad_set_thresh(child->get_touch_pad(), child->get_wakeup_threshold());
88 if (!is_wakeup_source) {
97#ifdef USE_ESP32_VARIANT_ESP32
98 ESP_LOGD(TAG,
"Touch Pad '%s' (T%" PRIu32
"): %" PRIu32, child->get_name().c_str(),
99 (uint32_t) child->get_touch_pad(), child->value_);
103 ESP_LOGD(TAG,
"Touch Pad '%s' (T%d): %d", child->get_name().c_str(), child->get_touch_pad(), value);
124 ESP_LOGV(TAG,
"Touch Pad '%s' state: OFF (initial)", child->
get_name().
c_str());
131 if (pads_off == this->
children_.size() && !this->setup_mode_) {
143 uint32_t rtc_freq = rtc_clk_slow_freq_get_hz();
virtual void mark_failed()
Mark this component as failed.
void disable_loop()
Disable this component's loop.
const StringRef & get_name() const
constexpr const char * c_str() const
void publish_initial_state(bool new_state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
Simple helper class to expose a touch pad value as a binary sensor.
bool initial_state_published_
touch_volt_atten_t voltage_attenuation_
bool create_touch_queue_()
uint32_t release_check_interval_ms_
uint32_t setup_mode_last_log_print_
void check_and_disable_loop_if_all_released_(size_t pads_off)
void publish_initial_state_if_needed_(ESP32TouchBinarySensor *child, uint32_t now)
static const char * get_high_voltage_reference_str(touch_high_volt_t ref)
QueueHandle_t touch_queue_
void calculate_release_timeout_()
static constexpr uint32_t MINIMUM_RELEASE_TIME_MS
static const char * get_low_voltage_reference_str(touch_low_volt_t ref)
touch_high_volt_t high_voltage_reference_
void process_setup_mode_logging_(uint32_t now)
uint32_t release_timeout_ms_
void dump_config_sensors_()
std::vector< ESP32TouchBinarySensor * > children_
uint32_t read_touch_value(touch_pad_t pad) const
touch_low_volt_t low_voltage_reference_
void cleanup_touch_queue_()
void configure_wakeup_pads_()
bool should_check_for_releases_(uint32_t now)
static const char * get_voltage_attenuation_str(touch_volt_atten_t atten)
uint32_t last_release_check_
Providing packet encoding functions for exchanging data with a remote host.