|
9 | 9 | #include "esp_check.h" |
10 | 10 | #include "esp_lcd_touch.h" |
11 | 11 | #include "esp_lvgl_port.h" |
| 12 | +#include "esp_timer.h" |
| 13 | +#include "sdkconfig.h" |
12 | 14 |
|
13 | 15 | static const char *TAG = "LVGL"; |
14 | 16 |
|
@@ -117,19 +119,39 @@ static void lvgl_port_touchpad_read(lv_indev_t *indev_drv, lv_indev_data_t *data |
117 | 119 | assert(touch_ctx); |
118 | 120 | assert(touch_ctx->handle); |
119 | 121 |
|
120 | | - uint16_t touchpad_x[1] = {0}; |
121 | | - uint16_t touchpad_y[1] = {0}; |
122 | | - uint8_t touchpad_cnt = 0; |
| 122 | + uint8_t touch_cnt = 0; |
| 123 | + esp_lcd_touch_point_data_t touch_data[CONFIG_ESP_LCD_TOUCH_MAX_POINTS] = {0}; |
123 | 124 |
|
124 | 125 | /* Read data from touch controller into memory */ |
125 | | - esp_lcd_touch_read_data(touch_ctx->handle); |
| 126 | + ESP_ERROR_CHECK(esp_lcd_touch_read_data(touch_ctx->handle)); |
126 | 127 |
|
127 | 128 | /* Read data from touch controller */ |
128 | | - bool touchpad_pressed = esp_lcd_touch_get_coordinates(touch_ctx->handle, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1); |
| 129 | + ESP_ERROR_CHECK(esp_lcd_touch_get_data(touch_ctx->handle, touch_data, &touch_cnt, CONFIG_ESP_LCD_TOUCH_MAX_POINTS)); |
129 | 130 |
|
130 | | - if (touchpad_pressed && touchpad_cnt > 0) { |
131 | | - data->point.x = touch_ctx->scale.x * touchpad_x[0]; |
132 | | - data->point.y = touch_ctx->scale.y * touchpad_y[0]; |
| 131 | +#if (CONFIG_ESP_LCD_TOUCH_MAX_POINTS > 1 && CONFIG_LV_USE_GESTURE_RECOGNITION) |
| 132 | + // Number of touch points which need to be constantly updated inside gesture recognizers |
| 133 | +#define GESTURE_TOUCH_POINTS 2 |
| 134 | + |
| 135 | + /* Initialize LVGL touch data for each activated touch point */ |
| 136 | + lv_indev_touch_data_t touches[GESTURE_TOUCH_POINTS] = {0}; |
| 137 | + |
| 138 | + for (int i = 0; i < touch_cnt && i < GESTURE_TOUCH_POINTS; i++) { |
| 139 | + touches[i].state = LV_INDEV_STATE_PRESSED; |
| 140 | + touches[i].point.x = touch_ctx->scale.x * touch_data[i].x; |
| 141 | + touches[i].point.y = touch_ctx->scale.y * touch_data[i].y; |
| 142 | + touches[i].id = touch_data[i].track_id; |
| 143 | + touches[i].timestamp = esp_timer_get_time() / 1000; |
| 144 | + } |
| 145 | + |
| 146 | + /* Pass touch data to LVGL gesture recognizers */ |
| 147 | + lv_indev_gesture_recognizers_update(indev_drv, touches, GESTURE_TOUCH_POINTS); |
| 148 | + lv_indev_gesture_recognizers_set_data(indev_drv, data); |
| 149 | + |
| 150 | +#endif |
| 151 | + |
| 152 | + if (touch_cnt > 0) { |
| 153 | + data->point.x = touch_ctx->scale.x * touch_data[0].x; |
| 154 | + data->point.y = touch_ctx->scale.y * touch_data[0].y; |
133 | 155 | data->state = LV_INDEV_STATE_PRESSED; |
134 | 156 | } else { |
135 | 157 | data->state = LV_INDEV_STATE_RELEASED; |
|
0 commit comments