SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
gt911_get_point.ino
Go to the documentation of this file.
1
30#include <TouchDrv.hpp>
31
32#ifndef TOUCH_SDA
33#define TOUCH_SDA 18
34#endif
35
36#ifndef TOUCH_SCL
37#define TOUCH_SCL 8
38#endif
39
40#ifndef TOUCH_IRQ
41#define TOUCH_IRQ 16
42#endif
43
44#ifndef TOUCH_RST
45#define TOUCH_RST -1
46#endif
47
49
50void setup()
51{
52 Serial.begin(115200);
53 while (!Serial);
54
55 // If the reset pin and interrupt pin can be controlled by GPIO, the device address can be set arbitrarily
56 // If the interrupt and reset pins are not connected, you can pass in the -1 parameter and the library will automatically determine the address.
58 if (!touch.begin(Wire, GT911_SLAVE_ADDRESS_UNKNOWN, TOUCH_SDA, TOUCH_SCL)) {
59 while (1) {
60 Serial.println("Failed to find GT911 - check your wiring!");
61 delay(1000);
62 }
63 }
64
65 Serial.println("Init GT911 Sensor success!");
66
67 // Set the center button to trigger the callback , Only for specific devices, e.g LilyGo-EPD47 S3 GT911
68 touch.setHomeButtonCallback([](void *user_data) {
69 Serial.println("Home button pressed!");
70 }, NULL);
71
72
73 /*
74 * GT911 Interrupt mode ,It is not recommended to modify any touch settings
75 * Please do not modify the touch interrupt mode without a touch screen configuration file,
76 * otherwise the touch screen may become unusable.
77 * * */
78 // Low level when idle, converts to high level when touched
79 // touch.setInterruptMode(HIGH_LEVEL_QUERY);
80
81 // Keep low level when idle, and trigger on the falling edge after touching, trigger once at a frequency of 100HZ, and keep high level for 10ms
82 // touch.setInterruptMode(RISING);
83
84 // Keep high level when idle, and switch to low level when touched
85 // touch.setInterruptMode(LOW_LEVEL_QUERY);
86
87 // Maintains high level when idle, and is triggered by the falling edge after being touched. The frequency is 100HZ and is triggered once. Maintains 10ms in the low level interval
88 // touch.setInterruptMode(FALLING);
89
90 Serial.println("Touch Info:");
91 Serial.print("Model: "); Serial.println(touch.getModelName());
92 Serial.print("ID: 0x"); Serial.println(touch.getChipID(), HEX);
93 Serial.print("Max Touch Points: "); Serial.println(touch.getSupportTouchPoint());
94 uint16_t resX = touch.getResolutionX();
95 uint16_t resY = touch.getResolutionY();
96 if (resX == 0 || resY == 0) {
97 Serial.println("The touch driver not support get touch resolution,please use setResolution() to set touch resolution.");
98 // touch.setResolution(480, 320);
99 } else {
100 Serial.print("Resolution: "); Serial.print(resX); Serial.print(" x "); Serial.println(resY);
101 }
102 delay(3000);
103}
104
105
106void loop()
107{
108 if (touch.isPressed()) {
109 TouchPoints touch_points = touch.getTouchPoints();
110 if (touch_points.hasPoints()) {
111 for (int i = 0; i < touch_points.getPointCount(); ++i) {
112 const TouchPoint &point = touch_points.getPoint(i);
113 Serial.print("X[");
114 Serial.print(i);
115 Serial.print("]:");
116 Serial.print(point.x);
117 Serial.print(" ");
118 Serial.print(" Y[");
119 Serial.print(i);
120 Serial.print("]:");
121 Serial.print(point.y);
122 Serial.print(" ");
123 }
124 Serial.println();
125 }
126 }
127 delay(100);
128}
@license MIT License
uint32_t getChipID() override
Get the chip ID.
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 void setPins(int rst, int irq)
Set the hardware reset and interrupt pin numbers.
virtual bool isPressed(uint32_t filter_ms=0)
Check if any touch point is currently pressed.
virtual void setHomeButtonCallback(HomeButtonCallback cb, void *user_data)
Register a callback for home button events.
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
#define TOUCH_RST
TouchDrvGT911 touch
void setup()
#define TOUCH_SCL
#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.