ESPHome
2026.6.0-dev
Loading...
Searching...
No Matches
esphome
components
touchscreen
binary_sensor
touchscreen_binary_sensor.cpp
Go to the documentation of this file.
1
#include "
touchscreen_binary_sensor.h
"
2
3
namespace
esphome::touchscreen
{
4
5
void
TouchscreenBinarySensor::setup
() {
6
this->
parent_
->register_listener(
this
);
7
this->
publish_initial_state
(
false
);
8
}
9
10
void
TouchscreenBinarySensor::touch
(
TouchPoint
tp) {
11
bool
touched;
12
if
(this->
use_raw_
) {
13
touched =
14
(tp.
x_raw
>= this->
x_min_
&& tp.
x_raw
<= this->
x_max_
&& tp.
y_raw
>= this->
y_min_
&& tp.
y_raw
<= this->
y_max_
);
15
}
else
{
16
touched = (tp.
x
>= this->
x_min_
&& tp.
x
<= this->
x_max_
&& tp.
y
>= this->
y_min_
&& tp.
y
<= this->
y_max_
);
17
}
18
19
if
(!this->
pages_
.empty()) {
20
auto
*current_page = this->
parent_
->get_display()->get_active_page();
21
touched &= std::find(this->
pages_
.begin(), this->pages_.end(), current_page) != this->
pages_
.end();
22
}
23
if
(touched) {
24
this->
publish_state
(
true
);
25
}
else
{
26
this->
release
();
27
}
28
}
29
30
void
TouchscreenBinarySensor::release
() { this->
publish_state
(
false
); }
31
32
}
// namespace esphome::touchscreen
esphome::Parented< Touchscreen >::parent_
Touchscreen * parent_
Definition
helpers.h:1872
esphome::binary_sensor::BinarySensor::publish_state
void publish_state(bool new_state)
Publish a new state to the front-end.
Definition
binary_sensor.cpp:20
esphome::binary_sensor::BinarySensor::publish_initial_state
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...
Definition
binary_sensor.cpp:31
esphome::touchscreen::TouchscreenBinarySensor::x_max_
int16_t x_max_
Definition
touchscreen_binary_sensor.h:41
esphome::touchscreen::TouchscreenBinarySensor::y_max_
int16_t y_max_
Definition
touchscreen_binary_sensor.h:41
esphome::touchscreen::TouchscreenBinarySensor::x_min_
int16_t x_min_
Definition
touchscreen_binary_sensor.h:41
esphome::touchscreen::TouchscreenBinarySensor::touch
void touch(TouchPoint tp) override
Definition
touchscreen_binary_sensor.cpp:10
esphome::touchscreen::TouchscreenBinarySensor::setup
void setup() override
Definition
touchscreen_binary_sensor.cpp:5
esphome::touchscreen::TouchscreenBinarySensor::pages_
std::vector< display::DisplayPage * > pages_
Definition
touchscreen_binary_sensor.h:43
esphome::touchscreen::TouchscreenBinarySensor::use_raw_
bool use_raw_
Definition
touchscreen_binary_sensor.h:42
esphome::touchscreen::TouchscreenBinarySensor::release
void release() override
Definition
touchscreen_binary_sensor.cpp:30
esphome::touchscreen::TouchscreenBinarySensor::y_min_
int16_t y_min_
Definition
touchscreen_binary_sensor.h:41
esphome::touchscreen
Definition
touchscreen_binary_sensor.cpp:3
esphome::touchscreen::TouchPoint
Definition
touchscreen.h:20
esphome::touchscreen::TouchPoint::y
uint16_t y
Definition
touchscreen.h:25
esphome::touchscreen::TouchPoint::x_raw
int16_t x_raw
Definition
touchscreen.h:22
esphome::touchscreen::TouchPoint::y_raw
int16_t y_raw
Definition
touchscreen.h:22
esphome::touchscreen::TouchPoint::x
uint16_t x
Definition
touchscreen.h:25
touchscreen_binary_sensor.h
Generated by
1.12.0