ESPHome  2023.3.1
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:
35  this->display_ = display;
36  this->display_width_ = display->get_width_internal();
37  this->display_height_ = display->get_height_internal();
38  this->rotation_ = static_cast<TouchRotation>(display->get_rotation());
39  }
40  display::DisplayBuffer *get_display() const { return this->display_; }
41 
42  Trigger<TouchPoint> *get_touch_trigger() { return &this->touch_trigger_; }
43 
44  void register_listener(TouchListener *listener) { this->touch_listeners_.push_back(listener); }
45 
46  protected:
48  void send_touch_(TouchPoint tp);
49 
50  uint16_t display_width_;
51  uint16_t display_height_;
55  std::vector<TouchListener *> touch_listeners_;
56 };
57 
58 } // namespace touchscreen
59 } // namespace esphome
void set_display(display::DisplayBuffer *display)
Definition: touchscreen.h:34
Trigger< TouchPoint > touch_trigger_
Definition: touchscreen.h:54
display::DisplayBuffer * display_
Definition: touchscreen.h:52
virtual int get_width_internal()=0
DisplayRotation get_rotation() const
display::DisplayBuffer * get_display() const
Definition: touchscreen.h:40
Trigger< TouchPoint > * get_touch_trigger()
Definition: touchscreen.h:42
std::vector< TouchListener * > touch_listeners_
Definition: touchscreen.h:55
virtual int get_height_internal()=0
Definition: a4988.cpp:4
void register_listener(TouchListener *listener)
Definition: touchscreen.h:44