TouchScreenAdapter v0.5.0
TouchScreenAdapter is a library providing a unified touchscreen API.
TouchScreenAdapter.h
1
10#ifndef TouchScreenAdapter_h
11#define TouchScreenAdapter_h
12
13#include <Arduino.h>
14
20
21public:
22
27 struct TouchPoint {
28
33 TouchPoint(void) { x = y = z = 0; }
34
42 TouchPoint(int16_t _x, int16_t _y, int16_t _z) {
43 x = _x;
44 y = _y;
45 z = _z;
46 }
47 uint16_t x = 0;
48 uint16_t y = 0;
49 uint16_t z = 0;
50
58 // Check for self-assignment
59 if (this != &tp) {
60 x = tp.x;
61 y = tp.y;
62 z = tp.z;
63 }
64 return *this;
65 }
66 };
67
76 void setDisplayWidth(uint16_t widthPx) {
77 DISPLAY_WIDTH = widthPx;
79 }
80
89 void setDisplayHeight(uint16_t heightPx) {
90 DISPLAY_HEIGHT = heightPx;
92 }
93
102
112
121 virtual bool begin(void) = 0;
122
134 void setRotation(uint8_t r ) {
135 rotation = (r & 3);
136 switch (rotation) {
137 case 0:
138 case 2:
141 break;
142 case 1:
143 case 3:
146 break;
147 }
148 }
149
150protected:
151
156 uint8_t rotation = 0;
157
158 uint16_t DISPLAY_WIDTH = 240;
159 uint16_t DISPLAY_HEIGHT = 320;
160
163
164};
165
166
167#endif
A lightweight abstract Abstract class for touch screen panels.
Definition: TouchScreenAdapter.h:19
virtual TouchScreenAdapter::TouchPoint getTouchPointRaw(void)=0
Get a TouchPoint struct containing raw values from the underlying library.
void setRotation(uint8_t r)
Set the rotation touch screen.
Definition: TouchScreenAdapter.h:134
uint16_t displayHeight
The (optionally rotated) height of the display in pixels.
Definition: TouchScreenAdapter.h:162
virtual bool begin(void)=0
For compatibility with the Arduino library convention.
uint16_t displayWidth
The (optionally rotated) width of the display in pixels.
Definition: TouchScreenAdapter.h:161
uint8_t rotation
The current rotation of the touch panel. Default is 0 (native orientation).
Definition: TouchScreenAdapter.h:156
uint16_t DISPLAY_HEIGHT
The non-rotated height of the display in pixels.
Definition: TouchScreenAdapter.h:159
void setDisplayHeight(uint16_t heightPx)
Set the native (non-rotated) display height (Y) in pixels.
Definition: TouchScreenAdapter.h:89
void setDisplayWidth(uint16_t widthPx)
Set the native (non-rotated) display width (X) in pixels.
Definition: TouchScreenAdapter.h:76
virtual TouchScreenAdapter::TouchPoint getTouchPoint(void)=0
Get the TouchPoint object.
uint16_t DISPLAY_WIDTH
The non-rotated width of the display in pixels.
Definition: TouchScreenAdapter.h:158
A consistent struct containing points X & Y plus Z as pressure.
Definition: TouchScreenAdapter.h:27
TouchPoint(void)
Construct a new Touch Point object.
Definition: TouchScreenAdapter.h:33
uint16_t x
Mapped 0 to screen width -1.
Definition: TouchScreenAdapter.h:47
uint16_t y
Mapped 0 to screen height -1.
Definition: TouchScreenAdapter.h:48
uint16_t z
Mapped 0-255 representing pressure (0 = not touched). is uint16_t because raw is odten > 255.
Definition: TouchScreenAdapter.h:49
TouchPoint & operator=(const TouchPoint &tp)
Assignment operator.
Definition: TouchScreenAdapter.h:57
TouchPoint(int16_t _x, int16_t _y, int16_t _z)
Construct a new Touch Point object.
Definition: TouchScreenAdapter.h:42