8static const char *
const TAG =
"touchscreen";
16 ESP_LOGD(TAG,
"Attach Touch Interupt");
32 ESP_LOGW(TAG,
"Touch Polling Stopped. You can safely remove the 'update_interval:' variable from the YAML file.");
39 ESP_LOGVV(TAG,
"<< Do Touch loop >>");
45 if (tp.second.state == STATE_PRESSED || tp.second.state == STATE_UPDATED) {
46 tp.second.state |= STATE_RELEASING;
48 tp.second.state = STATE_RELEASED;
50 tp.second.x_prev = tp.second.x;
51 tp.second.y_prev = tp.second.y;
58 for (
auto &tp : this->touches_) {
59 tp.second.state &= ~STATE_RELEASING;
80 std::swap(x_raw, y_raw);
83 tp.
state = STATE_PRESSED;
87 tp.
state = STATE_UPDATED;
101 tp.
state |= STATE_CALIBRATE;
103 if (tp.
state == STATE_PRESSED) {
120 ESP_LOGV(TAG,
"Touch status: %d/%d: raw:(%4d,%4d,%4d) calc:(%3d,%4d)", tp.second.id, tp.second.state,
121 tp.second.x_raw, tp.second.y_raw, tp.second.z_raw, tp.second.x, tp.second.y);
122 touches.push_back(tp.second);
127 listener->update(touches);
135 this->touches_.clear();
139 TouchPoint tp = this->touches_.begin()->second;
152 if (
val <= min_val) {
154 }
else if (
val >= max_val) {
157 ret = (int16_t) ((
int) 0xfff * (
val - min_val) / (max_val - min_val));
160 ret = (inverted) ? 0xfff - ret : ret;
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
void call_setup() override
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
virtual int get_height()
Get the calculated height of the display in pixels with rotation applied.
virtual int get_width()
Get the calculated width of the display in pixels with rotation applied.
void call_setup() override
std::map< uint8_t, TouchPoint > touches_
int16_t normalize_(int16_t val, int16_t min_val, int16_t max_val, bool inverted=false)
void attach_interrupt_(InternalGPIOPin *irq_pin, esphome::gpio::InterruptType type)
Call this function to send touch points to the on_touch listener and the binary_sensors.
virtual void update_touches()=0
std::vector< TouchListener * > touch_listeners_
display::Display * display_
TouchscreenInterrupt store_
Trigger< const TouchPoints_t & > update_trigger_
Trigger< TouchPoint, const TouchPoints_t & > touch_trigger_
void add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw=0)
std::vector< TouchPoint > TouchPoints_t
Providing packet encoding functions for exchanging data with a remote host.
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
static void gpio_intr(TouchscreenInterrupt *store)