1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-06 20:03:46 +01:00

Add deep sleep wakeup from touch (#1238) (#2281)

This commit is contained in:
Christian Taedcke
2021-09-20 10:12:32 +02:00
committed by GitHub
parent 3052c64dd7
commit 9ebe075f9b
6 changed files with 43 additions and 4 deletions

View File

@@ -133,15 +133,34 @@ void ESP32TouchComponent::loop() {
}
void ESP32TouchComponent::on_shutdown() {
bool is_wakeup_source = false;
if (this->iir_filter_enabled_()) {
touch_pad_filter_stop();
touch_pad_filter_delete();
}
touch_pad_deinit();
for (auto *child : this->children_) {
if (child->get_wakeup_threshold() != 0) {
if (!is_wakeup_source) {
is_wakeup_source = true;
// Touch sensor FSM mode must be 'TOUCH_FSM_MODE_TIMER' to use it to wake-up.
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
}
// No filter available when using as wake-up source.
touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold());
}
}
if (!is_wakeup_source) {
touch_pad_deinit();
}
}
ESP32TouchBinarySensor::ESP32TouchBinarySensor(const std::string &name, touch_pad_t touch_pad, uint16_t threshold)
: BinarySensor(name), touch_pad_(touch_pad), threshold_(threshold) {}
ESP32TouchBinarySensor::ESP32TouchBinarySensor(const std::string &name, touch_pad_t touch_pad, uint16_t threshold,
uint16_t wakeup_threshold)
: BinarySensor(name), touch_pad_(touch_pad), threshold_(threshold), wakeup_threshold_(wakeup_threshold) {}
} // namespace esp32_touch
} // namespace esphome