3
4
5
6
7
8
9
10
11
12
13
14
21
22
26
27
28
29
30
31
38 return x == other
.x &&
y == other
.y;
45
46
47
48
49
50
51
52
53
54
70
71
77
78
79
80
81
82
86
87
88
89
93
94
95
96
100
101
102
103
104
105
106
107
108
109
117
118
119
120
157
158
159 static int32_t
clamp32(int32_t value, int32_t minimum, int32_t maximum) {
160 if (value < minimum) {
164 if (value > maximum) {
172
173
174
175
176
177
178
179 static int32_t
mapRange(int32_t value, int32_t inMin, int32_t inMax,
180 int32_t outMin, int32_t outMax) {
181 if (inMin == inMax) {
185 const int64_t numerator =
static_cast<int64_t>(value - inMin) *
186 static_cast<int64_t>(outMax - outMin);
188 const int64_t denominator =
static_cast<int64_t>(inMax - inMin);
190 return static_cast<int32_t>(outMin + numerator / denominator);
194
195
196
197
198
199
200
201
202
203
204
205
206
207
209 uint16_t pressure = 255)
const {
211 return applyRotation(rawX, rawY, pressure,
false);
218
219
220
221
222
236
237
238
239
240
256
257
259 const int32_t tmp = mappedX;
264 return applyRotation(mappedX, mappedY, pressure,
true);
268 Point applyRotation(int32_t x, int32_t y, uint16_t pressure,
269 bool calibrated)
const {
271 return {
static_cast<int16_t>(x),
static_cast<int16_t>(y), pressure};
287
288
289
290
291
292
293
294
295 finalX = height - 1 - y;
300 finalX = width - 1 - x;
301 finalY = height - 1 - y;
306 finalY = width - 1 - x;
310 return {
static_cast<int16_t>(finalX),
static_cast<int16_t>(finalY),
Base class for touch controllers.
Definition: TouchDriverCommon.h:72
static bool validateCalibration(const CalibrationData &cal)
Definition: TouchDriverCommon.h:140
CalibrationData calibration_
Definition: TouchDriverCommon.h:137
virtual bool isTouched()=0
Return whether the panel currently appears touched.
static int32_t mapRange(int32_t value, int32_t inMin, int32_t inMax, int32_t outMin, int32_t outMax)
Map an integer from one range to another.
Definition: TouchDriverCommon.h:179
bool setCalibration(const CalibrationData &cal)
Set and validate calibration.
Definition: TouchDriverCommon.h:121
Point mapCoordinates(int16_t rawX, int16_t rawY, uint16_t pressure=255) const
Convert raw controller coordinates into logical display space.
Definition: TouchDriverCommon.h:208
bool hasCalibration_
Definition: TouchDriverCommon.h:138
virtual bool getPoint(Point &outPoint)=0
Read the current touch point.
Rotation getRotation() const
Definition: TouchDriverCommon.h:114
const CalibrationData & getCalibration() const
Definition: TouchDriverCommon.h:131
static int32_t clamp32(int32_t value, int32_t minimum, int32_t maximum)
Clamp an integer to an inclusive range.
Definition: TouchDriverCommon.h:159
virtual bool getSecondPoint(Point &outPoint)
Read a second, simultaneous touch point, for multi-touch gestures (pinch/rotate).
Definition: TouchDriverCommon.h:110
void setRotation(Rotation rotation)
Definition: TouchDriverCommon.h:112
virtual ~TouchDriver()=default
bool hasCalibration() const
Definition: TouchDriverCommon.h:133
virtual bool begin()=0
Initialize the controller.
Rotation rotation_
Definition: TouchDriverCommon.h:136
Definition: DSIBusESP32.h:19
Rotation
Logical display rotation.
Definition: TouchDriverCommon.h:23
Touch calibration configuration.
Definition: TouchDriverCommon.h:55
int16_t rawXMax
Definition: TouchDriverCommon.h:57
bool swapXY
Definition: TouchDriverCommon.h:66
bool invertY
Definition: TouchDriverCommon.h:65
int16_t rawYMin
Definition: TouchDriverCommon.h:58
uint16_t screenWidth
Definition: TouchDriverCommon.h:61
uint16_t screenHeight
Definition: TouchDriverCommon.h:62
int16_t rawYMax
Definition: TouchDriverCommon.h:59
int16_t rawXMin
Definition: TouchDriverCommon.h:56
bool invertX
Definition: TouchDriverCommon.h:64
Touch point.
Definition: TouchDriverCommon.h:32
bool operator!=(const Point &other) const
Definition: TouchDriverCommon.h:41
uint16_t pressure
Definition: TouchDriverCommon.h:35
int16_t x
Definition: TouchDriverCommon.h:33
bool operator==(const Point &other) const
Definition: TouchDriverCommon.h:37
int16_t y
Definition: TouchDriverCommon.h:34