ESPHome 2025.5.0
Loading...
Searching...
No Matches
touchscreen_binary_sensor.cpp
Go to the documentation of this file.
2
3namespace esphome {
4namespace touchscreen {
5
7 this->parent_->register_listener(this);
8 this->publish_initial_state(false);
9}
10
12 bool touched;
13 if (this->use_raw_) {
14 touched =
15 (tp.x_raw >= this->x_min_ && tp.x_raw <= this->x_max_ && tp.y_raw >= this->y_min_ && tp.y_raw <= this->y_max_);
16 } else {
17 touched = (tp.x >= this->x_min_ && tp.x <= this->x_max_ && tp.y >= this->y_min_ && tp.y <= this->y_max_);
18 }
19
20 if (!this->pages_.empty()) {
21 auto *current_page = this->parent_->get_display()->get_active_page();
22 touched &= std::find(this->pages_.begin(), this->pages_.end(), current_page) != this->pages_.end();
23 }
24 if (touched) {
25 this->publish_state(true);
26 } else {
27 this->release();
28 }
29}
30
32
33} // namespace touchscreen
34} // namespace esphome
void publish_initial_state(bool state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
void publish_state(bool state)
Publish a new state to the front-end.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7