SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
cst9217_get_point.ino
Go to the documentation of this file.
1
30#include <TouchDrv.hpp>
31#include <SensorWireHelper.h>
32
33#ifndef TOUCH_SDA
34#define TOUCH_SDA 8
35#endif
36
37#ifndef TOUCH_SCL
38#define TOUCH_SCL 10
39#endif
40
41#ifndef TOUCH_IRQ
42#define TOUCH_IRQ 5
43#endif
44
45#ifndef TOUCH_RST
46#define TOUCH_RST -1
47#endif
48
50volatile bool isPressed = false;
51
52void setup()
53{
54 Serial.begin(115200);
55 while (!Serial);
56
57#if TOUCH_RST != -1
58 pinMode(TOUCH_RST, OUTPUT);
59 digitalWrite(TOUCH_RST, LOW);
60 delay(30);
61 digitalWrite(TOUCH_RST, HIGH);
62 delay(50);
63 delay(1000);
64#endif
65
66#if (defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)) && !defined(ARDUINO_ARCH_MBED)
67 Wire.setSCL(TOUCH_SCL);
68 Wire.setSDA(TOUCH_SDA);
69 Wire.begin();
70#elif defined(ARDUINO_ARCH_NRF52)
71 Wire.setPins(TOUCH_SDA, TOUCH_SCL);
72 Wire.begin();
73#elif defined(ARDUINO_ARCH_ESP32)
74 Wire.begin(TOUCH_SDA, TOUCH_SCL);
75#else
76 Wire.begin();
77#endif
78
79 // Scan I2C devices
80 SensorWireHelper::dumpDevices(Wire);
81
82 // uint8_t touchAddress = 0x1A; // Other device addresses are determined by the touch firmware and are generally 0X5A by default.
83 uint8_t touchAddress = 0x5A; // The device address is determined according to the actual situation. Not all device addresses are 0X5A. There can also be other customized device addresses.
84
85
86 // Set to skip register check, used when the touch device address conflicts with other I2C device addresses [0x5A]
87 // touch.jumpCheck();
88
89
91 bool result = touch.begin(Wire, touchAddress, TOUCH_SDA, TOUCH_SCL);
92 if (result == false) {
93 Serial.println("touch is not online...");
94 while (1)delay(1000);
95 }
96 Serial.print("Model :"); Serial.println(touch.getModelName());
97
98 touch.setCoverScreenCallback([](void *ptr) {
99 Serial.print(millis());
100 Serial.println(" : The screen is covered");
101 }, NULL);
102
103
104 // Serial.println("Enter touch sleep mode.");
105 // Unable to obtain coordinates after turning on sleep
106 // CST9217 Work current ~= 1.3mA
107 // CST9217 sleep current = 3.4 uA
108 // touch.sleep();
109
110 // int i = 10;
111 // while (i--) {
112 // Serial.print("Wake up after ");
113 // Serial.print(i);
114 // Serial.println(" seconds");
115 // delay(1000);
116 // }
117
118
119 // Wakeup touch
120 // touch.reset();
121
122 // Set touch max xy
123 // touch.setMaxCoordinates(240, 296);
124
125 // Set swap xy
126 // touch.setSwapXY(true);
127
128 // Set mirror xy
129 // touch.setMirrorXY(true, true);
130
131}
132
133void loop()
134{
135 TouchPoints touch_points = touch.getTouchPoints();
136 if (touch_points.hasPoints()) {
137 for (int i = 0; i < touch_points.getPointCount(); ++i) {
138 const TouchPoint &point = touch_points.getPoint(i);
139 Serial.print("X[");
140 Serial.print(i);
141 Serial.print("]:");
142 Serial.print(point.x);
143 Serial.print(" ");
144 Serial.print(" Y[");
145 Serial.print(i);
146 Serial.print("]:");
147 Serial.print(point.y);
148 Serial.print(" ");
149 }
150 Serial.println();
151 }
152 delay(30);
153}
154
155
156
@license MIT License
@license MIT License
void setCoverScreenCallback(HomeButtonCallback cb, void *user_data=NULL)
Set the cover screen callback.
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 void setPins(int rst, int irq)
Set the hardware reset and interrupt pin numbers.
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
volatile bool isPressed
#define TOUCH_RST
void setup()
#define TOUCH_SCL
TouchDrvCST92xx touch
#define TOUCH_IRQ
void loop()
uint8_t i
Represents a single touch point with its properties.
uint16_t x
X coordinate of the touch point.
uint16_t y
Y coordinate of the touch point.