mirror of
https://github.com/esphome/esphome.git
synced 2025-01-03 11:21:43 +01:00
Add set_threshold and get_value methods to ESP32TouchBinarySensor and add a test.
This commit is contained in:
parent
36f47ade70
commit
e11e4eaaee
3 changed files with 21 additions and 1 deletions
|
@ -116,6 +116,7 @@ void ESP32TouchComponent::loop() {
|
|||
touch_pad_read(child->get_touch_pad(), &value);
|
||||
}
|
||||
|
||||
child->value_ = value;
|
||||
child->publish_state(value < child->get_threshold());
|
||||
|
||||
if (this->setup_mode_) {
|
||||
|
@ -157,7 +158,12 @@ ESP32TouchBinarySensor::ESP32TouchBinarySensor(const std::string &name, touch_pa
|
|||
: BinarySensor(name), touch_pad_(touch_pad), threshold_(threshold) {}
|
||||
touch_pad_t ESP32TouchBinarySensor::get_touch_pad() const { return this->touch_pad_; }
|
||||
uint16_t ESP32TouchBinarySensor::get_threshold() const { return this->threshold_; }
|
||||
|
||||
void ESP32TouchBinarySensor::set_threshold(uint16_t threshold) {
|
||||
this->threshold_ = threshold;
|
||||
}
|
||||
uint16_t ESP32TouchBinarySensor::get_value () const {
|
||||
return this->value_;
|
||||
}
|
||||
} // namespace esp32_touch
|
||||
} // namespace esphome
|
||||
|
||||
|
|
|
@ -56,12 +56,15 @@ class ESP32TouchBinarySensor : public binary_sensor::BinarySensor {
|
|||
|
||||
touch_pad_t get_touch_pad() const;
|
||||
uint16_t get_threshold() const;
|
||||
void set_threshold(uint16_t);
|
||||
uint16_t get_value() const;
|
||||
|
||||
protected:
|
||||
friend ESP32TouchComponent;
|
||||
|
||||
touch_pad_t touch_pad_;
|
||||
uint16_t threshold_;
|
||||
uint16_t value_;
|
||||
};
|
||||
|
||||
} // namespace esp32_touch
|
||||
|
|
|
@ -618,6 +618,7 @@ binary_sensor:
|
|||
name: "ESP32 Touch Pad GPIO27"
|
||||
pin: GPIO27
|
||||
threshold: 1000
|
||||
id: btn_left
|
||||
- platform: nextion
|
||||
page_id: 0
|
||||
component_id: 2
|
||||
|
@ -1118,6 +1119,16 @@ interval:
|
|||
if (true) return id(page1); else return id(page2);
|
||||
- display.page.show_next: display1
|
||||
- display.page.show_previous: display1
|
||||
- interval: 2s
|
||||
then:
|
||||
- lambda: |-
|
||||
static uint16_t btn_left_state = id(btn_left)->get_value();
|
||||
|
||||
ESP_LOGD("adaptive touch", "___ Touch Pad '%s' (T%u): val: %u state: %u tres:%u", id(btn_left)->get_name().c_str(), id(btn_left)->get_touch_pad(), id(btn_left)->get_value(), btn_left_state, id(btn_left)->get_threshold());
|
||||
|
||||
btn_left_state = ((uint32_t) id(btn_left)->get_value() + 63 * (uint32_t)btn_left_state) >> 6;
|
||||
|
||||
id(btn_left)->set_threshold(btn_left_state * 0.9);
|
||||
|
||||
display:
|
||||
- platform: lcd_gpio
|
||||
|
|
Loading…
Reference in a new issue