Bläddra i källkod

Improve Touch Calibration screen (#20524)

X-Ryl669 3 år sedan
förälder
incheckning
91730d71ff
Inget konto är kopplat till bidragsgivarens mejladress

+ 16
- 4
Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp Visa fil

@@ -55,6 +55,11 @@
55 55
   #include "../../../../feature/pause.h"
56 56
 #endif
57 57
 
58
+#if ENABLED(TOUCH_SCREEN_CALIBRATION)
59
+  #include "../../../tft_io/touch_calibration.h"
60
+  #include "draw_touch_calibration.h"
61
+#endif
62
+
58 63
 extern lv_group_t *g;
59 64
 static lv_obj_t *scr, *tempText1, *filament_bar;
60 65
 
@@ -161,7 +166,16 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
161 166
   else if (DIALOG_IS(REVERT_EEPROM_TIPS)) {
162 167
     TERN_(EEPROM_SETTINGS, (void)settings.reset());
163 168
     clear_cur_ui();
164
-    draw_return_ui();
169
+    #if ENABLED(TOUCH_SCREEN_CALIBRATION)
170
+      const bool do_draw_cal = touch_calibration.need_calibration();
171
+      if (do_draw_cal) {
172
+        disp_state_stack._disp_index--; // We are asynchronous from the dialog, so let's remove the dialog from the stack
173
+        lv_draw_touch_calibration_screen();
174
+      }
175
+    #else
176
+      constexpr bool do_draw_cal = false;
177
+    #endif
178
+    if (!do_draw_cal) draw_return_ui();
165 179
   }
166 180
   else if (DIALOG_IS(WIFI_CONFIG_TIPS)) {
167 181
     uiCfg.configWifi = 1;
@@ -181,9 +195,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
181 195
 static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) {
182 196
   if (event != LV_EVENT_RELEASED) return;
183 197
   if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) {
184
-    #if ENABLED(ADVANCED_PAUSE_FEATURE)
185
-      pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT;
186
-    #endif
198
+    TERN_(ADVANCED_PAUSE_FEATURE, pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT);
187 199
   }
188 200
   else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT, TYPE_FILAMENT_HEAT_LOAD_COMPLETED, TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) {
189 201
     thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak;

+ 13
- 0
Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp Visa fil

@@ -39,6 +39,11 @@
39 39
 #include "../../../../module/temperature.h"
40 40
 #include "../../../../inc/MarlinConfig.h"
41 41
 
42
+#if ENABLED(TOUCH_SCREEN_CALIBRATION)
43
+  #include "../../../tft_io/touch_calibration.h"
44
+  #include "draw_touch_calibration.h"
45
+#endif
46
+
42 47
 #include <stdio.h>
43 48
 
44 49
 //static lv_obj_t *buttonPrint, *buttonTool, *buttonSet;
@@ -215,6 +220,14 @@ void lv_draw_ready_print(void) {
215 220
     lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET);
216 221
     lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT);
217 222
   }
223
+
224
+  #if ENABLED(TOUCH_SCREEN_CALIBRATION)
225
+    // If calibration is required, let's trigger it now, handles the case when there is default value in configuration files
226
+    if (!touch_calibration.calibration_loaded()) {
227
+      lv_clear_ready_print();
228
+      lv_draw_touch_calibration_screen();
229
+    }
230
+  #endif
218 231
 }
219 232
 
220 233
 void lv_clear_ready_print() {

+ 1
- 3
Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp Visa fil

@@ -95,14 +95,12 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
95 95
     case ID_TC_RETURN:
96 96
       TERN_(MKS_TEST, curent_disp_ui = 1);
97 97
       lv_clear_touch_calibration_screen();
98
-      lv_draw_ready_print();
98
+      draw_return_ui();
99 99
       break;
100 100
   }
101 101
 }
102 102
 
103 103
 void lv_draw_touch_calibration_screen() {
104
-  disp_state_stack._disp_index = 0;
105
-  ZERO(disp_state_stack._disp_state);
106 104
   scr = lv_screen_create(TOUCH_CALIBRATION_UI, "");
107 105
 
108 106
   status_label = lv_label_create(scr, "");

+ 1
- 6
Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp Visa fil

@@ -217,12 +217,7 @@ void tft_lvgl_init() {
217 217
   #endif
218 218
 
219 219
   if (ready) {
220
-    #if ENABLED(TOUCH_SCREEN_CALIBRATION)
221
-      if (touch_calibration.need_calibration()) lv_draw_touch_calibration_screen();
222
-      else lv_draw_ready_print();
223
-    #else
224
-      lv_draw_ready_print();
225
-    #endif
220
+    lv_draw_ready_print();
226 221
   }
227 222
 
228 223
   if (mks_test_flag == 0x1E)

+ 3
- 0
Marlin/src/lcd/tft_io/touch_calibration.cpp Visa fil

@@ -28,6 +28,7 @@ TouchCalibration touch_calibration;
28 28
 touch_calibration_t TouchCalibration::calibration;
29 29
 calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
30 30
 touch_calibration_point_t TouchCalibration::calibration_points[4];
31
+uint8_t TouchCalibration::failed_count;
31 32
 
32 33
 void TouchCalibration::validate_calibration() {
33 34
   const bool landscape = validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3);
@@ -44,6 +45,8 @@ void TouchCalibration::validate_calibration() {
44 45
   else {
45 46
     calibration_state = CALIBRATION_FAIL;
46 47
     calibration_reset();
48
+    // Retry up to 5 times before reporting the failure
49
+    if (need_calibration() && failed_count++ < 5) calibration_state = CALIBRATION_TOP_LEFT;
47 50
   }
48 51
 
49 52
   if (calibration_state == CALIBRATION_SUCCESS) {

+ 6
- 0
Marlin/src/lcd/tft_io/touch_calibration.h Visa fil

@@ -61,6 +61,7 @@ public:
61 61
   static void validate_calibration();
62 62
 
63 63
   static touch_calibration_t calibration;
64
+  static uint8_t             failed_count;
64 65
   static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
65 66
   static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
66 67
 
@@ -75,10 +76,15 @@ public:
75 76
     calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
76 77
     calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
77 78
     calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
79
+    failed_count = 0;
78 80
     return calibration_state;
79 81
   }
80 82
   static void calibration_end() { calibration_state = CALIBRATION_NONE; }
81 83
   static calibrationState get_calibration_state() { return calibration_state; }
84
+  static bool calibration_loaded() {
85
+    if (need_calibration()) calibration_reset();
86
+    return !need_calibration();
87
+  }
82 88
 
83 89
   static bool handleTouch(uint16_t x, uint16_t y);
84 90
 };

Laddar…
Avbryt
Spara