SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
ft6232_get_point.ino
Go to the documentation of this file.
1
30#include <TouchDrv.hpp>
31
32#ifndef TOUCH_SDA
33#define TOUCH_SDA 23
34#endif
35
36#ifndef TOUCH_SCL
37#define TOUCH_SCL 32
38#endif
39
40#ifndef TOUCH_IRQ
41#define TOUCH_IRQ 38
42#endif
43
45
46
47#ifdef ARDUINO_T_WATCH
48#include <XPowersAXP202.tpp> //PMU Library https://github.com/lewisxhe/XPowersLib.git
49XPowersAXP202 power;
50#endif
51
53{
54 // T_AMOLED_147 The PMU voltage needs to be turned on to use the sensor
55#if defined(ARDUINO_T_WATCH)
56 bool ret = power.begin(Wire1, AXP202_SLAVE_ADDRESS, 21, 22);
57 if (!ret) {
58 Serial.println("PMU NOT FOUND!\n");
59 }
60 power.disableLDO2();
61 power.setLDO2Voltage(3300); power.enableLDO2();
62#endif
63}
64
65
66void setup()
67{
68 Serial.begin(115200);
69 while (!Serial);
70
71 beginPower();
72
73 pinMode(TOUCH_IRQ, INPUT);
74
75 if (!touch.begin(Wire, FT6X36_SLAVE_ADDRESS, TOUCH_SDA, TOUCH_SCL)) {
76 Serial.println("Failed to find FT6X36 - check your wiring!");
77 while (1) {
78 delay(1000);
79 }
80 }
82
83 // Set swap xy coordinates
84 // touch.setSwapXY(true);
85
86 // Set max coordinates
87 // touch.setMaxCoordinates(320, 320);
88
89 // Set mirror xy coordinates
90 // touch.setMirrorXY(true, true);
91
92 Serial.println("Touch Info:");
93 Serial.print("Model: "); Serial.println(touch.getModelName());
94 Serial.print("ID: 0x"); Serial.println(touch.getChipID(), HEX);
95 /*
96 * The default maximum number of touch fingers is the number of touch
97 * fingers supported by the chip, not the maximum number of touch fingers
98 * supported by the current device. The actual maximum number of touch
99 * fingers is determined by the touch chip firmware and hardware.
100 * */
101 Serial.print("Max Touch Points: "); Serial.println(touch.getSupportTouchPoint());
102 uint16_t resX = touch.getResolutionX();
103 uint16_t resY = touch.getResolutionY();
104 if (resX == 0 || resY == 0) {
105 Serial.println("The touch driver not support get touch resolution,please use setResolution() to set touch resolution.");
106 // touch.setResolution(480, 320);
107 } else {
108 Serial.print("Resolution: "); Serial.print(resX); Serial.print(" x "); Serial.println(resY);
109 }
110 delay(3000);
111}
112
113
114void loop()
115{
116 if (digitalRead(TOUCH_IRQ) == LOW) {
117 TouchPoints touch_points = touch.getTouchPoints();
118 if (touch_points.hasPoints()) {
119 for (int i = 0; i < touch_points.getPointCount(); ++i) {
120 const TouchPoint &point = touch_points.getPoint(i);
121 Serial.print("ID: ");
122 Serial.print(point.id);
123 Serial.print(" ");
124 Serial.print("X: ");
125 Serial.print(point.x);
126 Serial.print(" ");
127 Serial.print("Y: ");
128 Serial.print(point.y);
129 Serial.print(" ");
130 Serial.print("Pressure: ");
131 Serial.print(point.pressure);
132 Serial.print(" ");
133 Serial.print("Event: ");
134 switch (point.event) {
135 case 0: Serial.print("Put Down"); break;
136 case 1: Serial.print("Put Up"); break;
137 case 2: Serial.print("Contact"); break;
138 default: Serial.print("Unknown"); break;
139 }
140 Serial.println();
141 }
142 Serial.println();
143 }
144 }
145 delay(50);
146}
@license MIT License
void interruptPolling(void)
Polling mode for touch interrupt.
const char * getModelName() override
Get the model name.
const TouchPoints & getTouchPoints() override
Get the touch points.
virtual bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr)
Initialize the touch driver with custom communication callbacks.
virtual uint16_t getResolutionX()
Get the raw maximum X coordinate of the touch panel.
virtual uint8_t getSupportTouchPoint()
Get the maximum number of touch points supported by the hardware.
virtual uint32_t getChipID()
Get the chip identifier (e.g., ID register value).
virtual uint16_t getResolutionY()
Get the raw maximum Y coordinate of the touch panel.
Container for touch point data and optional gesture information.
uint8_t getPointCount() const
Returns the number of stored touch points.
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.
#define TOUCH_SDA
void setup()
TouchDrvFT6X36 touch
#define TOUCH_SCL
void beginPower()
#define TOUCH_IRQ
void loop()
uint8_t i
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.