Browse Source

Improve Touch Calibration screen (#20524)

vanilla_fb_2.0.x
X-Ryl669 4 years ago
committed by GitHub
parent
commit
91730d71ff
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp
  2. 13
      Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp
  3. 4
      Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp
  4. 5
      Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp
  5. 3
      Marlin/src/lcd/tft_io/touch_calibration.cpp
  6. 6
      Marlin/src/lcd/tft_io/touch_calibration.h

20
Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp

@ -55,6 +55,11 @@
#include "../../../../feature/pause.h" #include "../../../../feature/pause.h"
#endif #endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../../../tft_io/touch_calibration.h"
#include "draw_touch_calibration.h"
#endif
extern lv_group_t *g; extern lv_group_t *g;
static lv_obj_t *scr, *tempText1, *filament_bar; static lv_obj_t *scr, *tempText1, *filament_bar;
@ -161,7 +166,16 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
else if (DIALOG_IS(REVERT_EEPROM_TIPS)) { else if (DIALOG_IS(REVERT_EEPROM_TIPS)) {
TERN_(EEPROM_SETTINGS, (void)settings.reset()); TERN_(EEPROM_SETTINGS, (void)settings.reset());
clear_cur_ui(); clear_cur_ui();
draw_return_ui(); #if ENABLED(TOUCH_SCREEN_CALIBRATION)
const bool do_draw_cal = touch_calibration.need_calibration();
if (do_draw_cal) {
disp_state_stack._disp_index--; // We are asynchronous from the dialog, so let's remove the dialog from the stack
lv_draw_touch_calibration_screen();
}
#else
constexpr bool do_draw_cal = false;
#endif
if (!do_draw_cal) draw_return_ui();
} }
else if (DIALOG_IS(WIFI_CONFIG_TIPS)) { else if (DIALOG_IS(WIFI_CONFIG_TIPS)) {
uiCfg.configWifi = 1; uiCfg.configWifi = 1;
@ -181,9 +195,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) {
static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) { static void btn_cancel_event_cb(lv_obj_t *btn, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return; if (event != LV_EVENT_RELEASED) return;
if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) { if (DIALOG_IS(PAUSE_MESSAGE_OPTION)) {
#if ENABLED(ADVANCED_PAUSE_FEATURE) TERN_(ADVANCED_PAUSE_FEATURE, pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT);
pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT;
#endif
} }
else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT, TYPE_FILAMENT_HEAT_LOAD_COMPLETED, TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) { else if (DIALOG_IS(TYPE_FILAMENT_LOAD_HEAT, TYPE_FILAMENT_UNLOAD_HEAT, TYPE_FILAMENT_HEAT_LOAD_COMPLETED, TYPE_FILAMENT_HEAT_UNLOAD_COMPLETED)) {
thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak; thermalManager.temp_hotend[uiCfg.curSprayerChoose].target= uiCfg.desireSprayerTempBak;

13
Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp

@ -39,6 +39,11 @@
#include "../../../../module/temperature.h" #include "../../../../module/temperature.h"
#include "../../../../inc/MarlinConfig.h" #include "../../../../inc/MarlinConfig.h"
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../../../tft_io/touch_calibration.h"
#include "draw_touch_calibration.h"
#endif
#include <stdio.h> #include <stdio.h>
//static lv_obj_t *buttonPrint, *buttonTool, *buttonSet; //static lv_obj_t *buttonPrint, *buttonTool, *buttonSet;
@ -215,6 +220,14 @@ void lv_draw_ready_print(void) {
lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET); lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 90, event_handler, ID_SET);
lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT); lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 90, event_handler, ID_PRINT);
} }
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
// If calibration is required, let's trigger it now, handles the case when there is default value in configuration files
if (!touch_calibration.calibration_loaded()) {
lv_clear_ready_print();
lv_draw_touch_calibration_screen();
}
#endif
} }
void lv_clear_ready_print() { void lv_clear_ready_print() {

4
Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp

@ -95,14 +95,12 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
case ID_TC_RETURN: case ID_TC_RETURN:
TERN_(MKS_TEST, curent_disp_ui = 1); TERN_(MKS_TEST, curent_disp_ui = 1);
lv_clear_touch_calibration_screen(); lv_clear_touch_calibration_screen();
lv_draw_ready_print(); draw_return_ui();
break; break;
} }
} }
void lv_draw_touch_calibration_screen() { void lv_draw_touch_calibration_screen() {
disp_state_stack._disp_index = 0;
ZERO(disp_state_stack._disp_state);
scr = lv_screen_create(TOUCH_CALIBRATION_UI, ""); scr = lv_screen_create(TOUCH_CALIBRATION_UI, "");
status_label = lv_label_create(scr, ""); status_label = lv_label_create(scr, "");

5
Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp

@ -217,12 +217,7 @@ void tft_lvgl_init() {
#endif #endif
if (ready) { if (ready) {
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
if (touch_calibration.need_calibration()) lv_draw_touch_calibration_screen();
else lv_draw_ready_print();
#else
lv_draw_ready_print(); lv_draw_ready_print();
#endif
} }
if (mks_test_flag == 0x1E) if (mks_test_flag == 0x1E)

3
Marlin/src/lcd/tft_io/touch_calibration.cpp

@ -28,6 +28,7 @@ TouchCalibration touch_calibration;
touch_calibration_t TouchCalibration::calibration; touch_calibration_t TouchCalibration::calibration;
calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE; calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE;
touch_calibration_point_t TouchCalibration::calibration_points[4]; touch_calibration_point_t TouchCalibration::calibration_points[4];
uint8_t TouchCalibration::failed_count;
void TouchCalibration::validate_calibration() { void TouchCalibration::validate_calibration() {
const bool landscape = validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3); 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() {
else { else {
calibration_state = CALIBRATION_FAIL; calibration_state = CALIBRATION_FAIL;
calibration_reset(); calibration_reset();
// Retry up to 5 times before reporting the failure
if (need_calibration() && failed_count++ < 5) calibration_state = CALIBRATION_TOP_LEFT;
} }
if (calibration_state == CALIBRATION_SUCCESS) { if (calibration_state == CALIBRATION_SUCCESS) {

6
Marlin/src/lcd/tft_io/touch_calibration.h

@ -61,6 +61,7 @@ public:
static void validate_calibration(); static void validate_calibration();
static touch_calibration_t calibration; static touch_calibration_t calibration;
static uint8_t failed_count;
static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; } static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; }
static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; } static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; }
@ -75,10 +76,15 @@ public:
calibration_points[CALIBRATION_TOP_RIGHT].y = 30; calibration_points[CALIBRATION_TOP_RIGHT].y = 30;
calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31; calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31;
calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31; calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31;
failed_count = 0;
return calibration_state; return calibration_state;
} }
static void calibration_end() { calibration_state = CALIBRATION_NONE; } static void calibration_end() { calibration_state = CALIBRATION_NONE; }
static calibrationState get_calibration_state() { return calibration_state; } static calibrationState get_calibration_state() { return calibration_state; }
static bool calibration_loaded() {
if (need_calibration()) calibration_reset();
return !need_calibration();
}
static bool handleTouch(uint16_t x, uint16_t y); static bool handleTouch(uint16_t x, uint16_t y);
}; };

Loading…
Cancel
Save