ESPHome
2023.5.5
esphome
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
{
4
namespace
touchscreen {
5
6
void
TouchscreenBinarySensor::touch
(
TouchPoint
tp) {
7
bool
touched = (tp.
x
>= this->
x_min_
&& tp.
x
<= this->
x_max_
&& tp.
y
>= this->
y_min_
&& tp.
y
<= this->
y_max_
);
8
9
if
(this->
page_
!=
nullptr
) {
10
touched &= this->
page_
== this->
parent_
->get_display()->get_active_page();
11
}
12
13
if
(touched) {
14
this->
publish_state
(
true
);
15
}
else
{
16
release
();
17
}
18
}
19
20
void
TouchscreenBinarySensor::release
() { this->
publish_state
(
false
); }
21
22
}
// namespace touchscreen
23
}
// namespace esphome
touchscreen_binary_sensor.h
esphome::touchscreen::TouchscreenBinarySensor::y_min_
int16_t y_min_
Definition:
touchscreen_binary_sensor.h:39
esphome::touchscreen::TouchscreenBinarySensor::x_max_
int16_t x_max_
Definition:
touchscreen_binary_sensor.h:39
esphome::Parented< Touchscreen >::parent_
Touchscreen * parent_
Definition:
helpers.h:519
esphome::touchscreen::TouchscreenBinarySensor::y_max_
int16_t y_max_
Definition:
touchscreen_binary_sensor.h:39
esphome::touchscreen::TouchscreenBinarySensor::release
void release() override
Definition:
touchscreen_binary_sensor.cpp:20
esphome::touchscreen::TouchPoint::x
uint16_t x
Definition:
touchscreen.h:13
esphome::touchscreen::TouchPoint
Definition:
touchscreen.h:12
esphome::binary_sensor::BinarySensor::publish_state
void publish_state(bool state)
Publish a new state to the front-end.
Definition:
binary_sensor.cpp:14
esphome::touchscreen::TouchscreenBinarySensor::page_
display::DisplayPage * page_
Definition:
touchscreen_binary_sensor.h:40
esphome::touchscreen::TouchscreenBinarySensor::touch
void touch(TouchPoint tp) override
Definition:
touchscreen_binary_sensor.cpp:6
esphome
Definition:
a4988.cpp:4
esphome::touchscreen::TouchscreenBinarySensor::x_min_
int16_t x_min_
Definition:
touchscreen_binary_sensor.h:39
esphome::touchscreen::TouchPoint::y
uint16_t y
Definition:
touchscreen.h:14
Generated by
1.8.13