ESPHome  2023.8.3
touchscreen.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/hal.h"
6 
7 #include <vector>
8 
9 namespace esphome {
10 namespace touchscreen {
11 
12 struct TouchPoint {
13  uint16_t x;
14  uint16_t y;
15  uint8_t id;
16  uint8_t state;
17 };
18 
20  public:
21  virtual void touch(TouchPoint tp) = 0;
22  virtual void release() {}
23 };
24 
30 };
31 
32 class Touchscreen {
33  public:
34  void set_display(display::Display *display);
35  display::Display *get_display() const { return this->display_; }
36 
37  Trigger<TouchPoint> *get_touch_trigger() { return &this->touch_trigger_; }
38 
39  void register_listener(TouchListener *listener) { this->touch_listeners_.push_back(listener); }
40 
41  protected:
43  void send_touch_(TouchPoint tp);
44 
45  uint16_t display_width_;
46  uint16_t display_height_;
50  std::vector<TouchListener *> touch_listeners_;
51 };
52 
53 } // namespace touchscreen
54 } // namespace esphome
display::Display * get_display() const
Definition: touchscreen.h:35
Trigger< TouchPoint > touch_trigger_
Definition: touchscreen.h:49
Trigger< TouchPoint > * get_touch_trigger()
Definition: touchscreen.h:37
std::vector< TouchListener * > touch_listeners_
Definition: touchscreen.h:50
void register_listener(TouchListener *listener)
Definition: touchscreen.h:39