Browse Source

Improve Touch Calibration screen (#20524)

X-Ryl669 3 years ago
parent
commit
91730d71ff
No account linked to committer's email address

+ 16
- 4
Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp View File

55
   #include "../../../../feature/pause.h"
55
   #include "../../../../feature/pause.h"
56
 #endif
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
 extern lv_group_t *g;
63
 extern lv_group_t *g;
59
 static lv_obj_t *scr, *tempText1, *filament_bar;
64
 static lv_obj_t *scr, *tempText1, *filament_bar;
60
 
65
 
161
   else if (DIALOG_IS(REVERT_EEPROM_TIPS)) {
166
   else if (DIALOG_IS(REVERT_EEPROM_TIPS)) {
162
     TERN_(EEPROM_SETTINGS, (void)settings.reset());
167
     TERN_(EEPROM_SETTINGS, (void)settings.reset());
163
     clear_cur_ui();
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
   else if (DIALOG_IS(WIFI_CONFIG_TIPS)) {
180
   else if (DIALOG_IS(WIFI_CONFIG_TIPS)) {
167
     uiCfg.configWifi = 1;
181
     uiCfg.configWifi = 1;
181
 static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) {
195
 static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) {
182
   if (event != LV_EVENT_RELEASED) return;
196
   if (event != LV_EVENT_RELEASED) return;
183
   if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) {
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
   else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT, TYPE_FILAMENT_HEAT_LOAD_COMPLETED, TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) {
200
   else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT, TYPE_FILAMENT_HEAT_LOAD_COMPLETED, TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) {
189
     thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak;
201
     thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak;

+ 13
- 0
Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp View File

39
 #include "../../../../module/temperature.h"
39
 #include "../../../../module/temperature.h"
40
 #include "../../../../inc/MarlinConfig.h"
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
 #include <stdio.h>
47
 #include <stdio.h>
43
 
48
 
44
 //static lv_obj_t *buttonPrint, *buttonTool, *buttonSet;
49
 //static lv_obj_t *buttonPrint, *buttonTool, *buttonSet;
215
     lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET);
220
     lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET);
216
     lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT);
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
 void lv_clear_ready_print() {
233
 void lv_clear_ready_print() {

+ 1
- 3
Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp View File

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

+ 1
- 6
Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp View File

217
   #endif
217
   #endif
218
 
218
 
219
   if (ready) {
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
   if (mks_test_flag == 0x1E)
223
   if (mks_test_flag == 0x1E)

+ 3
- 0
Marlin/src/lcd/tft_io/touch_calibration.cpp View File

28
 touch_calibration_t TouchCalibration::calibration;
28
 touch_calibration_t TouchCalibration::calibration;
29
 calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
29
 calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
30
 touch_calibration_point_t TouchCalibration::calibration_points[4];
30
 touch_calibration_point_t TouchCalibration::calibration_points[4];
31
+uint8_t TouchCalibration::failed_count;
31
 
32
 
32
 void TouchCalibration::validate_calibration() {
33
 void TouchCalibration::validate_calibration() {
33
   const bool landscape = validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3);
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
   else {
45
   else {
45
     calibration_state = CALIBRATION_FAIL;
46
     calibration_state = CALIBRATION_FAIL;
46
     calibration_reset();
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
   if (calibration_state == CALIBRATION_SUCCESS) {
52
   if (calibration_state == CALIBRATION_SUCCESS) {

+ 6
- 0
Marlin/src/lcd/tft_io/touch_calibration.h View File

61
   static void validate_calibration();
61
   static void validate_calibration();
62
 
62
 
63
   static touch_calibration_t calibration;
63
   static touch_calibration_t calibration;
64
+  static uint8_t             failed_count;
64
   static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
65
   static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
65
   static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
66
   static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
66
 
67
 
75
     calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
76
     calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
76
     calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
77
     calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
77
     calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
78
     calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
79
+    failed_count = 0;
78
     return calibration_state;
80
     return calibration_state;
79
   }
81
   }
80
   static void calibration_end() { calibration_state = CALIBRATION_NONE; }
82
   static void calibration_end() { calibration_state = CALIBRATION_NONE; }
81
   static calibrationState get_calibration_state() { return calibration_state; }
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
   static bool handleTouch(uint16_t x, uint16_t y);
89
   static bool handleTouch(uint16_t x, uint16_t y);
84
 };
90
 };

Loading…
Cancel
Save