ESPHome
2024.11.0
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::setup
() {
7
this->
parent_
->register_listener(
this
);
8
this->
publish_initial_state
(
false
);
9
}
10
11
void
TouchscreenBinarySensor::touch
(
TouchPoint
tp) {
12
bool
touched = (tp.
x
>= this->
x_min_
&& tp.
x
<= this->
x_max_
&& tp.
y
>= this->
y_min_
&& tp.
y
<= this->
y_max_
);
13
14
if
(!this->
pages_
.empty()) {
15
auto
*current_page = this->
parent_
->get_display()->get_active_page();
16
touched &= std::find(this->
pages_
.begin(), this->
pages_
.end(), current_page) != this->
pages_
.end();
17
}
18
if
(touched) {
19
this->
publish_state
(
true
);
20
}
else
{
21
this->
release
();
22
}
23
}
24
25
void
TouchscreenBinarySensor::release
() { this->
publish_state
(
false
); }
26
27
}
// namespace touchscreen
28
}
// namespace esphome
touchscreen_binary_sensor.h
esphome::binary_sensor::BinarySensor::publish_initial_state
void publish_initial_state(bool state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
Definition:
binary_sensor.cpp:23
esphome::touchscreen::TouchscreenBinarySensor::y_min_
int16_t y_min_
Definition:
touchscreen_binary_sensor.h:41
esphome::touchscreen::TouchscreenBinarySensor::setup
void setup() override
Definition:
touchscreen_binary_sensor.cpp:6
esphome::touchscreen::TouchscreenBinarySensor::x_max_
int16_t x_max_
Definition:
touchscreen_binary_sensor.h:41
esphome::Parented< Touchscreen >::parent_
Touchscreen * parent_
Definition:
helpers.h:533
esphome::touchscreen::TouchscreenBinarySensor::y_max_
int16_t y_max_
Definition:
touchscreen_binary_sensor.h:41
esphome::touchscreen::TouchscreenBinarySensor::release
void release() override
Definition:
touchscreen_binary_sensor.cpp:25
esphome::touchscreen::TouchPoint::x
uint16_t x
Definition:
touchscreen.h:26
esphome::touchscreen::TouchPoint
Definition:
touchscreen.h:21
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::pages_
std::vector< display::DisplayPage * > pages_
Definition:
touchscreen_binary_sensor.h:42
esphome::touchscreen::TouchscreenBinarySensor::touch
void touch(TouchPoint tp) override
Definition:
touchscreen_binary_sensor.cpp:11
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
esphome::touchscreen::TouchscreenBinarySensor::x_min_
int16_t x_min_
Definition:
touchscreen_binary_sensor.h:41
esphome::touchscreen::TouchPoint::y
uint16_t y
Definition:
touchscreen.h:26
Generated by
1.8.13