SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
chsc5816_get_point.ino
Go to the documentation of this file.
1
30#include <TouchDrv.hpp>
31
32#ifndef TOUCH_SDA
33#define TOUCH_SDA 1
34#endif
35
36#ifndef TOUCH_SCL
37#define TOUCH_SCL 2
38#endif
39
40#ifndef TOUCH_IRQ
41#define TOUCH_IRQ 13
42#endif
43
44#ifndef TOUCH_RST
45#define TOUCH_RST 14
46#endif
47
49
50#ifdef ARDUINO_T_AMOLED_147
51#include <XPowersAXP2101.tpp> //PMU Library https://github.com/lewisxhe/XPowersLib.git
52XPowersAXP2101 power;
53#endif
54
56{
57 // T_AMOLED_147 The PMU voltage needs to be turned on to use the sensor
58#if defined(ARDUINO_T_AMOLED_147)
59 bool ret = power.begin(Wire, AXP2101_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
60 if (!ret) {
61 Serial.println("PMU NOT FOUND!\n");
62 }
63 power.setALDO1Voltage(1800); power.enableALDO1();
64 power.setALDO3Voltage(3300); power.enableALDO3();
65 power.setBLDO1Voltage(1800); power.enableBLDO1();
66#endif
67}
68
69void setup()
70{
71 Serial.begin(115200);
72 while (!Serial);
73
74 beginPower();
75
77 if (!touch.begin(Wire, CHSC5816_SLAVE_ADDRESS, TOUCH_SDA, TOUCH_SCL)) {
78 Serial.println("Failed to find CHSC5816 - check your wiring!");
79 while (1) {
80 delay(1000);
81 }
82 }
83
84 Serial.println("Init CHSC5816 Touch device success!");
85
86 Serial.println("Touch Info:");
87 Serial.print("Model: "); Serial.println(touch.getModelName());
88 Serial.print("ID: 0x"); Serial.println(touch.getChipID(), HEX);
89 Serial.print("Max Touch Points: "); Serial.println(touch.getSupportTouchPoint());
90 uint16_t resX = touch.getResolutionX();
91 uint16_t resY = touch.getResolutionY();
92 if (resX == 0 || resY == 0) {
93 Serial.println("The touch driver not support get touch resolution,please use setResolution() to set touch resolution.");
94 // touch.setResolution(480, 320);
95 } else {
96 Serial.print("Resolution: "); Serial.print(resX); Serial.print(" x "); Serial.println(resY);
97 }
98 delay(3000);
99}
100
101
102void loop()
103{
104 if (touch.isPressed()) {
105 TouchPoints touch_points = touch.getTouchPoints();
106 if (touch_points.hasPoints()) {
107 for (int i = 0; i < touch_points.getPointCount(); ++i) {
108 const TouchPoint &point = touch_points.getPoint(i);
109 Serial.print("X[");
110 Serial.print(i);
111 Serial.print("]:");
112 Serial.print(point.x);
113 Serial.print(" ");
114 Serial.print(" Y[");
115 Serial.print(i);
116 Serial.print("]:");
117 Serial.print(point.y);
118 Serial.print(" ");
119 }
120 Serial.println();
121 }
122 }
123}
@license MIT License
#define SENSOR_SCL
#define SENSOR_SDA
#define TOUCH_SDA
#define TOUCH_RST
void setup()
#define TOUCH_SCL
TouchDrvCHSC5816 touch
void beginPower()
#define TOUCH_IRQ
void loop()
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 uint32_t getChipID()
Get the chip identifier (e.g., ID register value).
virtual bool isPressed(uint32_t filter_ms=0)
Check if any touch point is currently pressed.
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.
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.