SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
TouchPoints.cpp
Go to the documentation of this file.
1
29#include "../SensorBuildOpt.h"
30#if !SENSORLIB_EXCLUDE_TOUCH_COMMON
31
32#include "TouchPoints.hpp"
33
34TouchPoint TouchPoints::emptyPoint = {};
36TouchPoints::TouchPoints() : pointCount(0), gestureValid(false), gesture(Gesture::NONE) {}
37
39{
40 pointCount = 0;
41 gestureValid = false;
42 gesture = Gesture::NONE;
43}
44
45bool TouchPoints::addPoint(uint16_t x, uint16_t y, uint16_t pressure, uint8_t id, uint8_t event)
46{
47 if (pointCount >= MAX_POINTS) return false;
48 points[pointCount].x = x;
49 points[pointCount].y = y;
50 points[pointCount].pressure = pressure;
51 points[pointCount].id = id;
52 points[pointCount].event = event;
53 pointCount++;
54 return true;
55}
56
58{
59 gesture = g;
60 gestureValid = true;
61}
62
64{
65 return pointCount;
66}
67
69{
70 if (index < pointCount) return points[index];
71 SENSORLIB_LOG_E("Invalid touch point index: %u", index);
72 return emptyPoint;
73}
74
75const TouchPoint &TouchPoints::getPoint(uint8_t index) const
76{
77 if (index < pointCount) return points[index];
78 SENSORLIB_LOG_E("Invalid touch point index: %u", index);
79 return emptyPoint;
80}
81
83{
84 return pointCount > 0;
85}
86
87
89{
90 return gestureValid;
91}
92
94{
95 return gesture;
96}
97
98#endif
#define SENSORLIB_LOG_E(...)
@license MIT License
Gesture
Gesture types recognized by the touch controller.
@ NONE
No gesture detected.
SensorPressure pressure(bhy)
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.
static constexpr uint8_t MAX_POINTS
Maximum number of touch points supported.
uint8_t getPointCount() const
Returns the number of stored touch points.
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.
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]