36
36
/* Private variables ---------------------------------------------------------*/
37
37
rtos::Thread t;
38
38
events::EventQueue queue (32 * EVENTS_EVENT_SIZE);
39
-
40
- #if __has_include ("lvgl.h")
41
- bool lvgl_touch_pressed = false ;
42
- uint16_t lvgl_touch_x_coord = 0 ;
43
- uint16_t lvgl_touch_y_coord = 0 ;
44
- #endif
39
+ Arduino_GigaDisplayTouch * gThis ;
45
40
46
41
/* Private function prototypes -----------------------------------------------*/
47
42
#if __has_include ("lvgl.h")
@@ -83,8 +78,6 @@ bool Arduino_GigaDisplayTouch::begin() {
83
78
pinMode (_intPin, INPUT);
84
79
85
80
_gt911TouchHandler = nullptr ;
86
- t.start (callback (&queue, &events::EventQueue::dispatch_forever));
87
- _irqInt.rise (queue.event (mbed::callback (this , &Arduino_GigaDisplayTouch::_gt911onIrq)));
88
81
89
82
/* GT911 test communication */
90
83
uint8_t testByte;
@@ -96,21 +89,27 @@ bool Arduino_GigaDisplayTouch::begin() {
96
89
indev_drv.type = LV_INDEV_TYPE_POINTER; /* Touch pad is a pointer-like device */
97
90
indev_drv.read_cb = _lvglTouchCb; /* Set your driver function */
98
91
lv_indev_t * my_indev = lv_indev_drv_register (&indev_drv); /* Register the driver in LVGL and save the created input device object */
92
+
93
+ gThis = this ;
99
94
#endif
100
95
101
96
return (error == 0 );
102
97
}
103
98
104
99
#if __has_include ("lvgl.h")
105
100
void _lvglTouchCb (lv_indev_drv_t * indev, lv_indev_data_t * data) {
106
- data->state = (lvgl_touch_pressed) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
107
- if (data->state == LV_INDEV_STATE_PR) {
108
- data->point .x = lvgl_touch_x_coord;
109
- data->point .y = lvgl_touch_y_coord;
110
- lvgl_touch_pressed = false ;
111
- }
112
-
113
- return ;
101
+ uint8_t contacts;
102
+ GDTpoint_t points[5 ];
103
+
104
+ if (gThis ->detect (contacts, points)) {
105
+ data->state = LV_INDEV_STATE_PR;
106
+ data->point .x = points[0 ].x ;
107
+ data->point .y = points[0 ].y ;
108
+ } else {
109
+ data->state = LV_INDEV_STATE_REL;
110
+ }
111
+
112
+ return ;
114
113
}
115
114
#endif
116
115
@@ -142,6 +141,8 @@ bool Arduino_GigaDisplayTouch::detect(uint8_t& contacts, GDTpoint_t* points) {
142
141
143
142
void Arduino_GigaDisplayTouch::attach (void (*handler)(uint8_t , GDTpoint_t*)) {
144
143
_gt911TouchHandler = handler;
144
+ t.start (callback (&queue, &events::EventQueue::dispatch_forever));
145
+ _irqInt.rise (queue.event (mbed::callback (this , &Arduino_GigaDisplayTouch::_gt911onIrq)));
145
146
}
146
147
147
148
uint8_t Arduino_GigaDisplayTouch::_gt911WriteOp (uint16_t reg, uint8_t data) {
@@ -208,14 +209,6 @@ void Arduino_GigaDisplayTouch::_gt911onIrq() {
208
209
}
209
210
210
211
if (contacts > 0 && _gt911TouchHandler != nullptr ) _gt911TouchHandler (contacts, _points);
211
-
212
- #if __has_include ("lvgl.h")
213
- if (contacts > 0 ) {
214
- lvgl_touch_pressed = true ;
215
- lvgl_touch_x_coord = _points[0 ].x ;
216
- lvgl_touch_y_coord = _points[0 ].y ;
217
- }
218
- #endif
219
212
220
213
_gt911WriteOp (GT911_REG_GESTURE_START_POINT, 0 ); /* Reset buffer status to finish the reading */
221
214
}
0 commit comments