SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
TouchPoints.hpp
Go to the documentation of this file.
1
29#pragma once
30
31#include "../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_TOUCH_COMMON
33
34#include "SensorPlatform.hpp"
35
39struct TouchPoint {
40 uint16_t x;
41 uint16_t y;
42 uint16_t pressure;
43 uint8_t id;
44 uint8_t event;
45};
46
50enum class Gesture {
51 NONE,
52 TAP,
53 SWIPE_UP,
57 HOLD
58};
59
67{
68public:
70 static constexpr uint8_t MAX_POINTS = 5;
71
76
77 ~TouchPoints() = default;
78
84 void clear();
85
96 bool addPoint(uint16_t x, uint16_t y, uint16_t pressure = 0, uint8_t id = 0, uint8_t event = 0);
97
103 void setGesture(Gesture g);
104
110 uint8_t getPointCount() const;
111
118 TouchPoint &getPoint(uint8_t index);
119
126 const TouchPoint &getPoint(uint8_t index) const;
127
133 bool hasPoints() const;
134
140 bool hasGesture() const;
141
147 Gesture getGesture() const;
148
149 TouchPoint &operator[](uint8_t index)
150 {
151 return getPoint(index);
152 }
153 const TouchPoint &operator[](uint8_t index) const
154 {
155 return getPoint(index);
156 }
157
159 {
160 return points;
161 }
163 {
164 return points + pointCount;
165 }
166 const TouchPoint *begin() const
167 {
168 return points;
169 }
170 const TouchPoint *end() const
171 {
172 return points + pointCount;
173 }
174
175private:
176 TouchPoint points[MAX_POINTS];
177 uint8_t pointCount;
178 bool gestureValid;
179 Gesture gesture;
180 static TouchPoint emptyPoint;
181};
182
183#endif
@license MIT License
Gesture
Gesture types recognized by the touch controller.
@ HOLD
Hold (long press) gesture.
@ SWIPE_DOWN
Swipe downward gesture.
@ SWIPE_LEFT
Swipe leftward gesture.
@ NONE
No gesture detected.
@ SWIPE_UP
Swipe upward gesture.
@ SWIPE_RIGHT
Swipe rightward gesture.
@ TAP
Single tap gesture.
SensorPressure pressure(bhy)
Container for touch point data and optional gesture information.
Gesture getGesture() const
Returns the stored gesture.
bool hasGesture() const
Checks whether a gesture is stored.
bool addPoint(uint16_t x, uint16_t y, uint16_t pressure=0, uint8_t id=0, uint8_t event=0)
Adds a touch point to the container.
TouchPoint * begin()
const TouchPoint & operator[](uint8_t index) const
TouchPoint & operator[](uint8_t index)
static constexpr uint8_t MAX_POINTS
Maximum number of touch points supported.
TouchPoint * end()
uint8_t getPointCount() const
Returns the number of stored touch points.
const TouchPoint * end() const
const TouchPoint * begin() const
void setGesture(Gesture g)
Sets the gesture for this touch event.
void clear()
Clears all stored touch points and gesture.
TouchPoints()
Constructs an empty TouchPoints object.
~TouchPoints()=default
TouchPoint & getPoint(uint8_t index)
Gets a reference to a touch point at the specified index.
bool hasPoints() const
Checks whether any touch points are stored.
Represents a single touch point with its properties.
uint16_t pressure
Pressure value (0 if not supported by the chip).
uint8_t event
Event type based on actual hardware feedback, most touch devices do not support.
uint8_t id
Touch point ID for multi‑touch tracking.
uint16_t x
X coordinate of the touch point.
uint16_t y
Y coordinate of the touch point.
int16_t x[5]
int16_t y[5]