|
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" |
12 | 13 |
|
13 | 14 | static const char *TAG = "LVGL"; |
14 | 15 |
|
@@ -117,15 +118,42 @@ static void lvgl_port_touchpad_read(lv_indev_t *indev_drv, lv_indev_data_t *data |
117 | 118 | assert(touch_ctx); |
118 | 119 | assert(touch_ctx->handle); |
119 | 120 |
|
120 | | - uint16_t touchpad_x[1] = {0}; |
121 | | - uint16_t touchpad_y[1] = {0}; |
| 121 | + uint16_t touchpad_x[CONFIG_ESP_LCD_TOUCH_MAX_POINTS] = {0}; |
| 122 | + uint16_t touchpad_y[CONFIG_ESP_LCD_TOUCH_MAX_POINTS] = {0}; |
122 | 123 | uint8_t touchpad_cnt = 0; |
123 | 124 |
|
124 | 125 | /* Read data from touch controller into memory */ |
125 | 126 | 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 | + bool touchpad_pressed = esp_lcd_touch_get_coordinates(touch_ctx->handle, touchpad_x, touchpad_y, NULL, &touchpad_cnt, CONFIG_ESP_LCD_TOUCH_MAX_POINTS); |
| 130 | + |
| 131 | +#if (CONFIG_ESP_LCD_TOUCH_MAX_POINTS > 1 && CONFIG_LVGL_PORT_ENABLE_GESTURES) |
| 132 | + // Number of touch points which need to be constantly updated inside gesture recognizers |
| 133 | +#define GESTURE_TOUCH_POINTS 2 |
| 134 | + |
| 135 | + uint8_t touchpad_track_id[CONFIG_ESP_LCD_TOUCH_MAX_POINTS] = {0}; |
| 136 | + |
| 137 | + /* Read track IDs for TODO number of touch points*/ |
| 138 | + esp_err_t err = esp_lcd_touch_get_track_id(touch_ctx->handle, touchpad_track_id, GESTURE_TOUCH_POINTS); |
| 139 | + |
| 140 | + /* Initialize LVGL touch data for each activated touch point */ |
| 141 | + /* static */ lv_indev_touch_data_t touches[CONFIG_ESP_LCD_TOUCH_MAX_POINTS] = {0}; |
| 142 | + if (err != ESP_ERR_NOT_SUPPORTED) { |
| 143 | + for (int i = 0; i < touchpad_cnt; i++) { |
| 144 | + touches[i].state = LV_INDEV_STATE_PRESSED; |
| 145 | + touches[i].point.x = touchpad_x[i]; |
| 146 | + touches[i].point.y = touchpad_y[i]; |
| 147 | + touches[i].id = touchpad_track_id[i]; |
| 148 | + touches[i].timestamp = esp_timer_get_time() / 1000; |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + /* Pass touch data to LVGL gesture recognizers */ |
| 153 | + lv_indev_gesture_recognizers_update(indev_drv, touches, GESTURE_TOUCH_POINTS); |
| 154 | + lv_indev_gesture_recognizers_set_data(indev_drv, data); |
| 155 | + |
| 156 | +#endif |
129 | 157 |
|
130 | 158 | if (touchpad_pressed && touchpad_cnt > 0) { |
131 | 159 | data->point.x = touch_ctx->scale.x * touchpad_x[0]; |
|
0 commit comments