From 1096cdc505b0110dfb1bfa3e086affee8c22ba70 Mon Sep 17 00:00:00 2001 From: Martin Turski Date: Fri, 3 Feb 2023 21:56:15 +0100 Subject: [PATCH 1/2] - fixed a bug in touch calibration where if the user went through the calibration and it determined a fail, then the user was stuck unable to retry calibration --- Marlin/src/lcd/tft/ui_common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index 705438e95be5..e14a34301ac6 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -230,7 +230,7 @@ void MarlinUI::clear_lcd() { calibrationState calibration_stage = touch_calibration.get_calibration_state(); - if (calibration_stage == CALIBRATION_NONE) { + if (calibration_stage == CALIBRATION_NONE || calibration_stage == CALIBRATION_TOP_LEFT) { defer_status_screen(true); clear_lcd(); calibration_stage = touch_calibration.calibration_start(); From 300e56e935cb30b3e322409223b463fbc09b8dc3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 23 Mar 2023 17:14:17 -0500 Subject: [PATCH 2/2] Reset to CALIBRATION_NONE on failure --- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 22 +++++++++---------- .../extui/mks_ui/draw_touch_calibration.cpp | 20 ++++++++--------- Marlin/src/lcd/tft/ui_common.cpp | 20 ++++++++--------- Marlin/src/lcd/tft_io/touch_calibration.cpp | 2 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index f1bf9d032ec8..efc010ca8960 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -501,26 +501,26 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, void MarlinUI::touch_calibration_screen() { uint16_t x, y; - calibrationState calibration_stage = touch_calibration.get_calibration_state(); + calibrationState stage = touch_calibration.get_calibration_state(); - if (calibration_stage == CALIBRATION_NONE) { + if (stage == CALIBRATION_NONE) { // start and clear screen defer_status_screen(true); - calibration_stage = touch_calibration.calibration_start(); + stage = touch_calibration.calibration_start(); tftio.set_window(0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1); tftio.WriteMultiple(TFT_MARLINBG_COLOR, uint32_t(TFT_WIDTH) * (TFT_HEIGHT)); } else { // clear last cross - x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; - y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; + x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; + y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; drawCross(x, y, TFT_MARLINBG_COLOR); } FSTR_P str = nullptr; - if (calibration_stage < CALIBRATION_SUCCESS) { + if (stage < CALIBRATION_SUCCESS) { // handle current state - switch (calibration_stage) { + switch (stage) { case CALIBRATION_TOP_LEFT: str = GET_TEXT_F(MSG_TOP_LEFT); break; case CALIBRATION_BOTTOM_LEFT: str = GET_TEXT_F(MSG_BOTTOM_LEFT); break; case CALIBRATION_TOP_RIGHT: str = GET_TEXT_F(MSG_TOP_RIGHT); break; @@ -528,13 +528,13 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, default: break; } - x = touch_calibration.calibration_points[calibration_stage].x; - y = touch_calibration.calibration_points[calibration_stage].y; + x = touch_calibration.calibration_points[stage].x; + y = touch_calibration.calibration_points[stage].y; drawCross(x, y, TFT_MARLINUI_COLOR); } else { // end calibration - str = calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT_F(MSG_CALIBRATION_COMPLETED) : GET_TEXT_F(MSG_CALIBRATION_FAILED); + str = stage == CALIBRATION_SUCCESS ? GET_TEXT_F(MSG_CALIBRATION_COMPLETED) : GET_TEXT_F(MSG_CALIBRATION_FAILED); defer_status_screen(false); touch_calibration.calibration_end(); TERN_(HAS_TOUCH_BUTTONS, redrawTouchButtons = true); @@ -548,7 +548,7 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, } while (u8g.nextPage()); drawing_screen = false; safe_delay(250); - if (calibration_stage == CALIBRATION_SUCCESS) { + if (stage == CALIBRATION_SUCCESS) { safe_delay(500); ui.goto_previous_screen(); } diff --git a/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp b/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp index e0c663e282e3..a9a25db11822 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp @@ -55,22 +55,22 @@ static void drawCross(uint16_t x, uint16_t y, uint16_t color) { void lv_update_touch_calibration_screen() { uint16_t x, y; - calibrationState calibration_stage = touch_calibration.get_calibration_state(); - if (calibration_stage == CALIBRATION_NONE) { + calibrationState stage = touch_calibration.get_calibration_state(); + if (stage == CALIBRATION_NONE) { // start and clear screen - calibration_stage = touch_calibration.calibration_start(); + stage = touch_calibration.calibration_start(); } else { // clear last cross - x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; - y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; + x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; + y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; drawCross(x, y, LV_COLOR_BACKGROUND.full); } const char *str = nullptr; - if (calibration_stage < CALIBRATION_SUCCESS) { + if (stage < CALIBRATION_SUCCESS) { // handle current state - switch (calibration_stage) { + switch (stage) { case CALIBRATION_TOP_LEFT: str = GET_TEXT(MSG_TOP_LEFT); break; case CALIBRATION_BOTTOM_LEFT: str = GET_TEXT(MSG_BOTTOM_LEFT); break; case CALIBRATION_TOP_RIGHT: str = GET_TEXT(MSG_TOP_RIGHT); break; @@ -78,13 +78,13 @@ void lv_update_touch_calibration_screen() { default: break; } - x = touch_calibration.calibration_points[calibration_stage].x; - y = touch_calibration.calibration_points[calibration_stage].y; + x = touch_calibration.calibration_points[stage].x; + y = touch_calibration.calibration_points[stage].y; drawCross(x, y, LV_COLOR_WHITE.full); } else { // end calibration - str = calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED); + str = stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED); touch_calibration.calibration_end(); lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_TC_RETURN); } diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index e14a34301ac6..6fbde791548d 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -228,24 +228,24 @@ void MarlinUI::clear_lcd() { void MarlinUI::touch_calibration_screen() { uint16_t x, y; - calibrationState calibration_stage = touch_calibration.get_calibration_state(); + calibrationState stage = touch_calibration.get_calibration_state(); - if (calibration_stage == CALIBRATION_NONE || calibration_stage == CALIBRATION_TOP_LEFT) { + if (stage == CALIBRATION_NONE) { defer_status_screen(true); clear_lcd(); - calibration_stage = touch_calibration.calibration_start(); + stage = touch_calibration.calibration_start(); } else { - x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; - y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; + x = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; + y = touch_calibration.calibration_points[_MIN(stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; tft.canvas(x - 15, y - 15, 31, 31); tft.set_background(COLOR_BACKGROUND); } touch.clear(); - if (calibration_stage < CALIBRATION_SUCCESS) { - switch (calibration_stage) { + if (stage < CALIBRATION_SUCCESS) { + switch (stage) { case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break; case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break; case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break; @@ -253,8 +253,8 @@ void MarlinUI::clear_lcd() { default: break; } - x = touch_calibration.calibration_points[calibration_stage].x; - y = touch_calibration.calibration_points[calibration_stage].y; + x = touch_calibration.calibration_points[stage].x; + y = touch_calibration.calibration_points[stage].y; tft.canvas(x - 15, y - 15, 31, 31); tft.set_background(COLOR_BACKGROUND); @@ -264,7 +264,7 @@ void MarlinUI::clear_lcd() { touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y)); } else { - tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); + tft_string.set(stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); defer_status_screen(false); touch_calibration.calibration_end(); touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); diff --git a/Marlin/src/lcd/tft_io/touch_calibration.cpp b/Marlin/src/lcd/tft_io/touch_calibration.cpp index 44ebc73d71a2..b1ef17df17c1 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.cpp +++ b/Marlin/src/lcd/tft_io/touch_calibration.cpp @@ -74,7 +74,7 @@ void TouchCalibration::validate_calibration() { else { calibration_state = CALIBRATION_FAIL; calibration_reset(); - if (need_calibration() && failed_count++ < TOUCH_CALIBRATION_MAX_RETRIES) calibration_state = CALIBRATION_TOP_LEFT; + if (need_calibration() && failed_count++ < TOUCH_CALIBRATION_MAX_RETRIES) calibration_state = CALIBRATION_NONE; } #undef CAL_PTS