Parcourir la source

⚡️ Improve LVGL touch driver (#22817)

Sola il y a 2 ans
Parent
révision
9c208a008d
Aucun compte lié à l'adresse e-mail de l'auteur

+ 18
- 28
Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp Voir le fichier

264
 }
264
 }
265
 
265
 
266
 static bool get_point(int16_t *x, int16_t *y) {
266
 static bool get_point(int16_t *x, int16_t *y) {
267
-  bool is_touched = touch.getRawPoint(x, y);
268
-
269
-  if (!is_touched) return false;
267
+  if (!touch.getRawPoint(x, y)) return false;
270
 
268
 
271
   #if ENABLED(TOUCH_SCREEN_CALIBRATION)
269
   #if ENABLED(TOUCH_SCREEN_CALIBRATION)
272
     const calibrationState state = touch_calibration.get_calibration_state();
270
     const calibrationState state = touch_calibration.get_calibration_state();
286
 
284
 
287
 bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
285
 bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
288
   static int16_t last_x = 0, last_y = 0;
286
   static int16_t last_x = 0, last_y = 0;
289
-  static uint8_t last_touch_state = LV_INDEV_STATE_REL;
290
-  static int32_t touch_time1 = 0;
291
-  uint32_t tmpTime, diffTime = 0;
292
-
293
-  tmpTime = millis();
294
-  diffTime = getTickDiff(tmpTime, touch_time1);
295
-  if (diffTime > 20) {
296
-    if (get_point(&last_x, &last_y)) {
297
-
298
-      if (last_touch_state == LV_INDEV_STATE_PR) return false;
299
-      data->state = LV_INDEV_STATE_PR;
300
-
301
-      // Set the coordinates (if released use the last-pressed coordinates)
287
+  if (get_point(&last_x, &last_y)) {
288
+    #if TFT_ROTATION == TFT_ROTATE_180
289
+      data->point.x = TFT_WIDTH - last_x;
290
+      data->point.y = TFT_HEIGHT - last_y;
291
+    #else
302
       data->point.x = last_x;
292
       data->point.x = last_x;
303
       data->point.y = last_y;
293
       data->point.y = last_y;
304
-
305
-      last_x = last_y = 0;
306
-      last_touch_state = LV_INDEV_STATE_PR;
307
-    }
308
-    else {
309
-      if (last_touch_state == LV_INDEV_STATE_PR)
310
-        data->state = LV_INDEV_STATE_REL;
311
-      last_touch_state = LV_INDEV_STATE_REL;
312
-    }
313
-
314
-    touch_time1 = tmpTime;
294
+    #endif
295
+    data->state = LV_INDEV_STATE_PR;
296
+  }
297
+  else {
298
+    #if TFT_ROTATION == TFT_ROTATE_180
299
+      data->point.x = TFT_WIDTH - last_x;
300
+      data->point.y = TFT_HEIGHT - last_y;
301
+    #else
302
+      data->point.x = last_x;
303
+      data->point.y = last_y;
304
+    #endif
305
+    data->state = LV_INDEV_STATE_REL;
315
   }
306
   }
316
-
317
   return false; // Return `false` since no data is buffering or left to read
307
   return false; // Return `false` since no data is buffering or left to read
318
 }
308
 }
319
 
309
 

+ 1
- 0
buildroot/tests/mks_robin_maple Voir le fichier

16
 use_example_configs Mks/Robin
16
 use_example_configs Mks/Robin
17
 opt_disable TFT_CLASSIC_UI TFT_COLOR_UI TOUCH_SCREEN TFT_RES_320x240
17
 opt_disable TFT_CLASSIC_UI TFT_COLOR_UI TOUCH_SCREEN TFT_RES_320x240
18
 opt_enable TFT_LVGL_UI TFT_RES_480x320
18
 opt_enable TFT_LVGL_UI TFT_RES_480x320
19
+opt_set TFT_ROTATION TFT_ROTATE_180
19
 exec_test $1 $2 "MKS Robin nano v1.2 LVGL FSMC" "$3"
20
 exec_test $1 $2 "MKS Robin nano v1.2 LVGL FSMC" "$3"
20
 
21
 
21
 # cleanup
22
 # cleanup

Chargement…
Annuler
Enregistrer