From 3c8fdbe0268b6ff3c865342819ea012b6d1b3ed1 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 22:42:57 -0300 Subject: [PATCH 01/21] class to hold the touch calibration logic --- Marlin/src/lcd/tft_io/touch_calibration.cpp | 84 +++++++++++++++ Marlin/src/lcd/tft_io/touch_calibration.h | 111 ++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 Marlin/src/lcd/tft_io/touch_calibration.cpp create mode 100644 Marlin/src/lcd/tft_io/touch_calibration.h diff --git a/Marlin/src/lcd/tft_io/touch_calibration.cpp b/Marlin/src/lcd/tft_io/touch_calibration.cpp new file mode 100644 index 0000000000..aaac16c466 --- /dev/null +++ b/Marlin/src/lcd/tft_io/touch_calibration.cpp @@ -0,0 +1,84 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "touch_calibration.h" + +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + +#include "../../inc/MarlinConfig.h" + +TouchCalibration touch_calibration; + +touch_calibration_t TouchCalibration::calibration; +calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE; +touch_calibration_point_t TouchCalibration::calibration_points[4]; + +bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) { + static millis_t next_button_update_ms = 0; + const millis_t now = millis(); + if (PENDING(now, next_button_update_ms)) return false; + next_button_update_ms = now + BUTTON_DELAY_MENU; + + if (calibration_state < CALIBRATION_SUCCESS) { + calibration_points[calibration_state].raw_x = x; + calibration_points[calibration_state].raw_y = y; + } + + switch (calibration_state) { + case CALIBRATION_TOP_LEFT: calibration_state = CALIBRATION_BOTTOM_LEFT; break; + case CALIBRATION_BOTTOM_LEFT: calibration_state = CALIBRATION_TOP_RIGHT; break; + case CALIBRATION_TOP_RIGHT: calibration_state = CALIBRATION_BOTTOM_RIGHT; break; + case CALIBRATION_BOTTOM_RIGHT: + if (validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3)) { + calibration_state = CALIBRATION_SUCCESS; + calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_x + calibration_points[2].raw_x - calibration_points[1].raw_x - calibration_points[0].raw_x); + calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_y - calibration_points[2].raw_y + calibration_points[1].raw_y - calibration_points[0].raw_y); + calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_x + calibration_points[1].raw_x) * calibration.x) >> 17); + calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_y + calibration_points[2].raw_y) * calibration.y) >> 17); + calibration.orientation = TOUCH_LANDSCAPE; + } + else if (validate_precision_y(0, 1) && validate_precision_y(2, 3) && validate_precision_x(0, 2) && validate_precision_x(1, 3)) { + calibration_state = CALIBRATION_SUCCESS; + calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_y + calibration_points[2].raw_y - calibration_points[1].raw_y - calibration_points[0].raw_y); + calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_x - calibration_points[2].raw_x + calibration_points[1].raw_x - calibration_points[0].raw_x); + calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_y + calibration_points[1].raw_y) * calibration.x) >> 17); + calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_x + calibration_points[2].raw_x) * calibration.y) >> 17); + calibration.orientation = TOUCH_PORTRAIT; + } + else { + calibration_state = CALIBRATION_FAIL; + calibration_reset(); + } + + if (calibration_state == CALIBRATION_SUCCESS) { + SERIAL_ECHOLNPGM("Touch screen calibration completed"); + SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_X ", calibration.x); + SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y); + SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x); + SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y); + SERIAL_ECHOPGM("TOUCH_ORIENTATION "); if (calibration.orientation == TOUCH_LANDSCAPE) SERIAL_ECHOLNPGM("TOUCH_LANDSCAPE"); else SERIAL_ECHOLNPGM("TOUCH_PORTRAIT"); + } + break; + default: break; + } + + return true; +} + +#endif // ENABLED(TOUCH_SCREEN_CALIBRATION) diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h new file mode 100644 index 0000000000..472966cd2e --- /dev/null +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -0,0 +1,111 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + +#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION + #define TOUCH_SCREEN_CALIBRATION_PRECISION 80 +#endif + +#ifndef TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS + #define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500 +#endif + +#define TOUCH_ORIENTATION_NONE 0 +#define TOUCH_LANDSCAPE 1 +#define TOUCH_PORTRAIT 2 + +#if !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION)) + #if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET) + #define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION + #define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION + #define TOUCH_OFFSET_X XPT2046_X_OFFSET + #define TOUCH_OFFSET_Y XPT2046_Y_OFFSET + #define TOUCH_ORIENTATION TOUCH_LANDSCAPE + #else + #define TOUCH_CALIBRATION_X 0 + #define TOUCH_CALIBRATION_Y 0 + #define TOUCH_OFFSET_X 0 + #define TOUCH_OFFSET_Y 0 + #define TOUCH_ORIENTATION TOUCH_ORIENTATION_NONE + #endif +#endif + +typedef struct __attribute__((__packed__)) { + int32_t x; + int32_t y; + int16_t offset_x; + int16_t offset_y; + uint8_t orientation; +} touch_calibration_t; + +typedef struct __attribute__((__packed__)) { + uint16_t x; + uint16_t y; + int16_t raw_x; + int16_t raw_y; +} touch_calibration_point_t; + +enum calibrationState : uint8_t { + CALIBRATION_TOP_LEFT = 0x00, + CALIBRATION_BOTTOM_LEFT, + CALIBRATION_TOP_RIGHT, + CALIBRATION_BOTTOM_RIGHT, + CALIBRATION_SUCCESS, + CALIBRATION_FAIL, + CALIBRATION_NONE, +}; + +class TouchCalibration { +public: + static calibrationState calibration_state; + static touch_calibration_point_t calibration_points[4]; + + static bool validate_precision(int32_t a, int32_t b) { return (a > b ? (100 * b) / a : (100 * a) / b) > TOUCH_SCREEN_CALIBRATION_PRECISION; } + static bool validate_precision_x(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_x, calibration_points[b].raw_x); } + static bool validate_precision_y(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_y, calibration_points[b].raw_y); } + + static touch_calibration_t calibration; + static void calibration_reset() { calibration = {TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION}; } + + static calibrationState calibration_start() { + calibration = {0, 0, 0, 0, TOUCH_ORIENTATION_NONE}; + calibration_state = CALIBRATION_TOP_LEFT; + calibration_points[CALIBRATION_TOP_LEFT].x = 20; + calibration_points[CALIBRATION_TOP_LEFT].y = 20; + calibration_points[CALIBRATION_BOTTOM_LEFT].x = 20; + calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 21; + calibration_points[CALIBRATION_TOP_RIGHT].x = TFT_WIDTH - 21; + calibration_points[CALIBRATION_TOP_RIGHT].y = 20; + calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 21; + calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 21; + return calibration_state; + } + static void calibration_end() { calibration_state = CALIBRATION_NONE; } + static calibrationState get_calibration_state() { return calibration_state; } + + static bool handleTouch(uint16_t x, uint16_t y); +}; + +extern TouchCalibration touch_calibration; + +#endif From e6e936d41a36bb3be0abf2935dcb3fd09e18052f Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 22:44:17 -0300 Subject: [PATCH 02/21] touch calibratio screen for classic ui --- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 105 +++++++++++++++--- Marlin/src/lcd/marlinui.h | 2 +- Marlin/src/lcd/menu/menu_touch_screen.cpp | 2 +- Marlin/src/lcd/touch/touch_buttons.cpp | 17 ++- Marlin/src/module/settings.cpp | 4 +- 5 files changed, 105 insertions(+), 25 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 8698dbb017..554ba04083 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 @@ -75,6 +75,11 @@ TFT_IO tftio; #include "../touch/touch_buttons.h" +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + #include "../tft_io/touch_calibration.h" + #include "../marlinui.h" +#endif + #define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1) #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1) @@ -313,6 +318,29 @@ inline void memset2(const void *ptr, uint16_t fill, size_t cnt) { static bool preinit = true; static uint8_t page; +#if HAS_TOUCH_XPT2046 + static bool redrawTouchButtons = true; + static void drawTouchButtons(u8g_t *u8g, u8g_dev_t *dev) { + if (!redrawTouchButtons) { + return; + } + redrawTouchButtons = false; + // Bottom buttons + + setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI); + drawImage(buttonD, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTCANCEL_COLOR); + + setWindow(u8g, dev, BUTTONA_X_LO, BUTTON_Y_LO, BUTTONA_X_HI, BUTTON_Y_HI); + drawImage(buttonA, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR); + + setWindow(u8g, dev, BUTTONB_X_LO, BUTTON_Y_LO, BUTTONB_X_HI, BUTTON_Y_HI); + drawImage(buttonB, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR); + + setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI); + drawImage(buttonC, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTOKMENU_COLOR); + } +#endif // HAS_TOUCH_XPT2046 + uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); @@ -343,28 +371,13 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++) u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer); #endif - - // Bottom buttons - #if HAS_TOUCH_XPT2046 - setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI); - drawImage(buttonD, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTCANCEL_COLOR); - - setWindow(u8g, dev, BUTTONA_X_LO, BUTTON_Y_LO, BUTTONA_X_HI, BUTTON_Y_HI); - drawImage(buttonA, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR); - - setWindow(u8g, dev, BUTTONB_X_LO, BUTTON_Y_LO, BUTTONB_X_HI, BUTTON_Y_HI); - drawImage(buttonB, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR); - - setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI); - drawImage(buttonC, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTOKMENU_COLOR); - #endif // HAS_TOUCH_XPT2046 - return 0; case U8G_DEV_MSG_STOP: preinit = true; break; case U8G_DEV_MSG_PAGE_FIRST: page = 0; + TERN_(HAS_TOUCH_XPT2046, drawTouchButtons(u8g, dev)); setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI); break; @@ -456,4 +469,64 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_TFT_FN); +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + + static void drawCross(uint16_t x, uint16_t y, uint16_t color) { + tftio.set_window(x - 15, y, x + 15, y); + tftio.WriteMultiple(color, 31); + tftio.set_window(x, y - 15, x, y + 15); + tftio.WriteMultiple(color, 31); + } + + void MarlinUI::touch_calibration_screen() { + uint16_t x, y; + calibrationState calibration_stage = touch_calibration.get_calibration_state(); + + if (calibration_stage == CALIBRATION_NONE) { + // start and clear screen + defer_status_screen(true); + calibration_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; + drawCross(x, y, TFT_MARLINBG_COLOR); + } + + const char *str = nullptr; + if (calibration_stage < CALIBRATION_SUCCESS) { + // handle current state + switch (calibration_stage) { + case CALIBRATION_TOP_LEFT: str = "Top Left"; break; + case CALIBRATION_BOTTOM_LEFT: str = "Bottom Left"; break; + case CALIBRATION_TOP_RIGHT: str = "Top Right"; break; + case CALIBRATION_BOTTOM_RIGHT: str = "Bottom Right"; break; + default: break; + } + + x = touch_calibration.calibration_points[calibration_stage].x; + y = touch_calibration.calibration_points[calibration_stage].y; + drawCross(x, y, TFT_MARLINUI_COLOR); + } + else { + // end calibration + str = calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed"; + defer_status_screen(false); + touch_calibration.calibration_end(); + TERN_(HAS_TOUCH_XPT2046, redrawTouchButtons = true); + } + + // draw current message + tftio.set_window(TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI); + do { + set_font(FONT_MENU); + lcd_put_u8str(0, LCD_PIXEL_HEIGHT / 2, str); + } while (u8g.nextPage()); + drawing_screen = false; + } +#endif // TOUCH_SCREEN_CALIBRATION + #endif // HAS_MARLINUI_U8GLIB && (FSMC_CS_PIN || HAS_SPI_GRAPHICAL_TFT) diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index d0b66aee45..2cee5b5f67 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -684,7 +684,7 @@ public: #endif #if ENABLED(TOUCH_SCREEN_CALIBRATION) - static void touch_calibration(); + static void touch_calibration_screen(); #endif #if HAS_GRAPHICAL_TFT diff --git a/Marlin/src/lcd/menu/menu_touch_screen.cpp b/Marlin/src/lcd/menu/menu_touch_screen.cpp index ea610e0886..5fc4b584d5 100644 --- a/Marlin/src/lcd/menu/menu_touch_screen.cpp +++ b/Marlin/src/lcd/menu/menu_touch_screen.cpp @@ -29,7 +29,7 @@ void touch_screen_calibration() { - ui.touch_calibration(); + ui.touch_calibration_screen(); } diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 4e98486969..bc7b441362 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -27,6 +27,10 @@ #include HAL_PATH(../../HAL, tft/xpt2046.h) XPT2046 touchIO; +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + #include "../tft_io/touch_calibration.h" +#endif + #include "../../lcd/marlinui.h" // For EN_C bit mask #define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X @@ -47,14 +51,17 @@ uint8_t TouchButtons::read_buttons() { if (!touchIO.getRawPoint(&x, &y)) return 0; + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + const calibrationState state = touch_calibration.get_calibration_state(); + if (state >= CALIBRATION_TOP_LEFT && state <= CALIBRATION_BOTTOM_RIGHT) { + if (touch_calibration.handleTouch(x, y)) ui.refresh(); + return 0; + } + #endif + x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; - #if (TFT_ROTATION & TFT_ROTATE_180) - x = TFT_WIDTH - x; - y = TFT_HEIGHT - y; - #endif - // Touch within the button area simulates an encoder button if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT) return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index b1b9bb6e0a..c228561366 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -146,7 +146,7 @@ #endif #if ENABLED(TOUCH_SCREEN_CALIBRATION) - #include "../lcd/tft/touch.h" + #include "../lcd/tft_io/touch_calibration.h" #endif #if HAS_ETHERNET @@ -2626,7 +2626,7 @@ void MarlinSettings::reset() { // // TOUCH_SCREEN_CALIBRATION // - TERN_(TOUCH_SCREEN_CALIBRATION, touch.calibration_reset()); + TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset()); // // Buzzer enable/disable From be9bea9cd5e933eb92b564fccda9a7845e16125f Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 22:58:15 -0300 Subject: [PATCH 03/21] using saved calibration values --- Marlin/src/lcd/touch/touch_buttons.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index bc7b441362..5e666ac7c3 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -59,8 +59,8 @@ uint8_t TouchButtons::read_buttons() { } #endif - x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; - y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; + x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; + y = int16_t((int32_t(y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; // Touch within the button area simulates an encoder button if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT) From 314fa0ab9b1c5d2688cf54d10054ec334fa25395 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 22:58:47 -0300 Subject: [PATCH 04/21] touch calibration for color ui --- Marlin/src/lcd/tft/touch.cpp | 62 +++----------------------- Marlin/src/lcd/tft/touch.h | 72 +------------------------------ Marlin/src/lcd/tft/ui_320x240.cpp | 16 +++---- Marlin/src/lcd/tft/ui_480x320.cpp | 16 +++---- 4 files changed, 23 insertions(+), 143 deletions(-) diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index adbc2923a4..c4b931d2a4 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -48,17 +48,12 @@ millis_t Touch::last_touch_ms = 0, Touch::repeat_delay, Touch::touch_time; TouchControlType Touch::touch_control_type = NONE; -touch_calibration_t Touch::calibration; -#if ENABLED(TOUCH_SCREEN_CALIBRATION) - calibrationState Touch::calibration_state = CALIBRATION_NONE; - touch_calibration_point_t Touch::calibration_points[4]; -#endif #if HAS_RESUME_CONTINUE extern bool wait_for_user; #endif void Touch::init() { - calibration_reset(); + touch_calibration.calibration_reset(); reset(); io.Init(); enable(); @@ -155,52 +150,7 @@ void Touch::touch(touch_control_t *control) { switch (control->type) { #if ENABLED(TOUCH_SCREEN_CALIBRATION) case CALIBRATE: - ui.refresh(); - - if (calibration_state < CALIBRATION_SUCCESS) { - calibration_points[calibration_state].x = int16_t(control->data >> 16); - calibration_points[calibration_state].y = int16_t(control->data & 0xFFFF); - calibration_points[calibration_state].raw_x = x; - calibration_points[calibration_state].raw_y = y; - } - - switch (calibration_state) { - case CALIBRATION_POINT_1: calibration_state = CALIBRATION_POINT_2; break; - case CALIBRATION_POINT_2: calibration_state = CALIBRATION_POINT_3; break; - case CALIBRATION_POINT_3: calibration_state = CALIBRATION_POINT_4; break; - case CALIBRATION_POINT_4: - if (validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3)) { - calibration_state = CALIBRATION_SUCCESS; - calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_x + calibration_points[2].raw_x - calibration_points[1].raw_x - calibration_points[0].raw_x); - calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_y - calibration_points[2].raw_y + calibration_points[1].raw_y - calibration_points[0].raw_y); - calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_x + calibration_points[1].raw_x) * calibration.x) >> 17); - calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_y + calibration_points[2].raw_y) * calibration.y) >> 17); - calibration.orientation = TOUCH_LANDSCAPE; - } - else if (validate_precision_y(0, 1) && validate_precision_y(2, 3) && validate_precision_x(0, 2) && validate_precision_x(1, 3)) { - calibration_state = CALIBRATION_SUCCESS; - calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_y + calibration_points[2].raw_y - calibration_points[1].raw_y - calibration_points[0].raw_y); - calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_x - calibration_points[2].raw_x + calibration_points[1].raw_x - calibration_points[0].raw_x); - calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_y + calibration_points[1].raw_y) * calibration.x) >> 17); - calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_x + calibration_points[2].raw_x) * calibration.y) >> 17); - calibration.orientation = TOUCH_PORTRAIT; - } - else { - calibration_state = CALIBRATION_FAIL; - calibration_reset(); - } - - if (calibration_state == CALIBRATION_SUCCESS) { - SERIAL_ECHOLNPGM("Touch screen calibration completed"); - SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_X ", calibration.x); - SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y); - SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x); - SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y); - SERIAL_ECHOPGM("TOUCH_ORIENTATION "); if (calibration.orientation == TOUCH_LANDSCAPE) SERIAL_ECHOLNPGM("TOUCH_LANDSCAPE"); else SERIAL_ECHOLNPGM("TOUCH_PORTRAIT"); - } - break; - default: break; - } + if (touch_calibration.handleTouch(x, y)) ui.refresh(); break; #endif // TOUCH_SCREEN_CALIBRATION @@ -298,11 +248,11 @@ void Touch::hold(touch_control_t *control, millis_t delay) { } bool Touch::get_point(int16_t *x, int16_t *y) { - bool is_touched = (calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); + bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); - if (is_touched && calibration.orientation != TOUCH_ORIENTATION_NONE) { - *x = int16_t((int32_t(*x) * calibration.x) >> 16) + calibration.offset_x; - *y = int16_t((int32_t(*y) * calibration.y) >> 16) + calibration.offset_y; + if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) { + *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; + *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; } return is_touched; } diff --git a/Marlin/src/lcd/tft/touch.h b/Marlin/src/lcd/tft/touch.h index 7cb05891de..c632b10be0 100644 --- a/Marlin/src/lcd/tft/touch.h +++ b/Marlin/src/lcd/tft/touch.h @@ -27,38 +27,11 @@ #include "tft_color.h" #include "tft_image.h" +#include "../tft_io/touch_calibration.h" #include HAL_PATH(../../HAL, tft/xpt2046.h) #define TOUCH_DRIVER XPT2046 -#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION - #define TOUCH_SCREEN_CALIBRATION_PRECISION 80 -#endif - -#ifndef TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS - #define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500 -#endif - -#define TOUCH_ORIENTATION_NONE 0 -#define TOUCH_LANDSCAPE 1 -#define TOUCH_PORTRAIT 2 - -#if !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION)) - #if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET) - #define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION - #define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION - #define TOUCH_OFFSET_X XPT2046_X_OFFSET - #define TOUCH_OFFSET_Y XPT2046_Y_OFFSET - #define TOUCH_ORIENTATION TOUCH_LANDSCAPE - #else - #define TOUCH_CALIBRATION_X 0 - #define TOUCH_CALIBRATION_Y 0 - #define TOUCH_OFFSET_X 0 - #define TOUCH_OFFSET_Y 0 - #define TOUCH_ORIENTATION TOUCH_ORIENTATION_NONE - #endif -#endif - // Menu Navigation extern int8_t encoderTopLine, encoderLine, screen_items; @@ -101,31 +74,6 @@ typedef struct __attribute__((__packed__)) { intptr_t data; } touch_control_t; -typedef struct __attribute__((__packed__)) { - int32_t x; - int32_t y; - int16_t offset_x; - int16_t offset_y; - uint8_t orientation; -} touch_calibration_t; - -typedef struct __attribute__((__packed__)) { - uint16_t x; - uint16_t y; - int16_t raw_x; - int16_t raw_y; -} touch_calibration_point_t; - -enum calibrationState : uint8_t { - CALIBRATION_POINT_1 = 0x00, - CALIBRATION_POINT_2, - CALIBRATION_POINT_3, - CALIBRATION_POINT_4, - CALIBRATION_SUCCESS, - CALIBRATION_FAIL, - CALIBRATION_NONE, -}; - #define MAX_CONTROLS 16 #define MINIMUM_HOLD_TIME 15 #define TOUCH_REPEAT_DELAY 75 @@ -150,15 +98,6 @@ class Touch { static void touch(touch_control_t *control); static void hold(touch_control_t *control, millis_t delay = 0); - #if ENABLED(TOUCH_SCREEN_CALIBRATION) - static calibrationState calibration_state; - static touch_calibration_point_t calibration_points[4]; - - static bool validate_precision(int32_t a, int32_t b) { return (a > b ? (100 * b) / a : (100 * a) / b) > TOUCH_SCREEN_CALIBRATION_PRECISION; } - static bool validate_precision_x(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_x, calibration_points[b].raw_x); } - static bool validate_precision_y(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_y, calibration_points[b].raw_y); } - #endif // TOUCH_SCREEN_CALIBRATION - public: static void init(); static void reset() { controls_count = 0; touch_time = 0; current_control = NULL; } @@ -175,15 +114,6 @@ class Touch { static void enable() { enabled = true; } static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data = 0); - - static touch_calibration_t calibration; - static void calibration_reset() { calibration = {TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION}; } - - #if ENABLED(TOUCH_SCREEN_CALIBRATION) - static calibrationState calibration_start() { calibration = {0, 0, 0, 0, TOUCH_ORIENTATION_NONE}; return calibration_state = CALIBRATION_POINT_1; } - static void calibration_end() { calibration_state = CALIBRATION_NONE; } - static calibrationState get_calibration_state() { return calibration_state; } - #endif // TOUCH_SCREEN_CALIBRATION }; extern Touch touch; diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index 999cec29ba..ecfa094787 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -584,15 +584,15 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #endif // AUTO_BED_LEVELING_UBL #if ENABLED(TOUCH_SCREEN_CALIBRATION) - void MarlinUI::touch_calibration() { + void MarlinUI::touch_calibration_screen() { static uint16_t x, y; - calibrationState calibration_stage = touch.get_calibration_state(); + calibrationState calibration_stage = touch_calibration.get_calibration_state(); if (calibration_stage == CALIBRATION_NONE) { defer_status_screen(true); clear_lcd(); - calibration_stage = touch.calibration_start(); + calibration_stage = touch_calibration.calibration_start(); } else { tft.canvas(x - 15, y - 15, 31, 31); @@ -604,10 +604,10 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const if (calibration_stage < CALIBRATION_SUCCESS) { switch (calibration_stage) { - case CALIBRATION_POINT_1: tft_string.set("Top Left"); break; - case CALIBRATION_POINT_2: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; - case CALIBRATION_POINT_3: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; - case CALIBRATION_POINT_4: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; + case CALIBRATION_TOP_LEFT: tft_string.set("Top Left"); break; + case CALIBRATION_BOTTOM_LEFT: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; + case CALIBRATION_TOP_RIGHT: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; + case CALIBRATION_BOTTOM_RIGHT: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; default: break; } @@ -621,7 +621,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const else { tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed"); defer_status_screen(false); - touch.calibration_end(); + touch_calibration.calibration_end(); touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); } diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index e2bbdcde7f..0e8ed4eb57 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -589,15 +589,15 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #endif // AUTO_BED_LEVELING_UBL #if ENABLED(TOUCH_SCREEN_CALIBRATION) - void MarlinUI::touch_calibration() { + void MarlinUI::touch_calibration_screen() { static uint16_t x, y; - calibrationState calibration_stage = touch.get_calibration_state(); + calibrationState calibration_stage = touch_calibration.get_calibration_state(); if (calibration_stage == CALIBRATION_NONE) { defer_status_screen(true); clear_lcd(); - calibration_stage = touch.calibration_start(); + calibration_stage = touch_calibration.calibration_start(); } else { tft.canvas(x - 15, y - 15, 31, 31); @@ -609,10 +609,10 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const if (calibration_stage < CALIBRATION_SUCCESS) { switch (calibration_stage) { - case CALIBRATION_POINT_1: tft_string.set("Top Left"); break; - case CALIBRATION_POINT_2: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; - case CALIBRATION_POINT_3: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; - case CALIBRATION_POINT_4: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; + case CALIBRATION_TOP_LEFT: tft_string.set("Top Left"); break; + case CALIBRATION_BOTTOM_LEFT: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; + case CALIBRATION_TOP_RIGHT: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; + case CALIBRATION_BOTTOM_RIGHT: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; default: break; } @@ -626,7 +626,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const else { tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed"); defer_status_screen(false); - touch.calibration_end(); + touch_calibration.calibration_end(); touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); } From 715502172f950f90ec860deb2fd4b96c73814696 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 22:59:23 -0300 Subject: [PATCH 05/21] calibration reset and enable it for all ui --- Marlin/src/inc/Conditionals_LCD.h | 1 - Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 98aa4afb8c..93c1974563 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1002,7 +1002,6 @@ // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' #if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT #undef TOUCH_SCREEN - #undef TOUCH_SCREEN_CALIBRATION #if !HAS_TFT_LVGL_UI #define HAS_TOUCH_XPT2046 1 #endif 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 554ba04083..3c2b49d7c4 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 @@ -356,6 +356,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr); tftio.Init(); tftio.InitTFT(); + TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset()); if (preinit) { preinit = false; @@ -470,7 +471,6 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_TFT_FN); #if ENABLED(TOUCH_SCREEN_CALIBRATION) - static void drawCross(uint16_t x, uint16_t y, uint16_t color) { tftio.set_window(x - 15, y, x + 15, y); tftio.WriteMultiple(color, 31); From 2f4b85568ab0a548db95d0fc94190f273f06d4e3 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 23:09:48 -0300 Subject: [PATCH 06/21] to use ui without TOUCH_SCREEN_CALIBRATION --- Marlin/src/lcd/tft/touch.cpp | 18 ++++++++++++------ Marlin/src/lcd/tft_io/touch_calibration.h | 4 ++-- Marlin/src/lcd/touch/touch_buttons.cpp | 7 +++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index c4b931d2a4..1239b31f2f 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -53,7 +53,7 @@ TouchControlType Touch::touch_control_type = NONE; #endif void Touch::init() { - touch_calibration.calibration_reset(); + TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset()); reset(); io.Init(); enable(); @@ -248,12 +248,18 @@ void Touch::hold(touch_control_t *control, millis_t delay) { } bool Touch::get_point(int16_t *x, int16_t *y) { - bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); - if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) { - *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; - *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; - } + if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) { + *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; + *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; + } + #else + bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); + *x = uint16_t((uint32_t(*x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; + *y = uint16_t((uint32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; + #endif return is_touched; } Touch touch; diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index 472966cd2e..f70d214a12 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -20,8 +20,6 @@ #include "../../inc/MarlinConfigPre.h" -#if ENABLED(TOUCH_SCREEN_CALIBRATION) - #ifndef TOUCH_SCREEN_CALIBRATION_PRECISION #define TOUCH_SCREEN_CALIBRATION_PRECISION 80 #endif @@ -50,6 +48,8 @@ #endif #endif +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + typedef struct __attribute__((__packed__)) { int32_t x; int32_t y; diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 5e666ac7c3..32aa7ced54 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -57,10 +57,13 @@ uint8_t TouchButtons::read_buttons() { if (touch_calibration.handleTouch(x, y)) ui.refresh(); return 0; } + x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; + y = int16_t((int32_t(y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; + #else + x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; + y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; #endif - x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; - y = int16_t((int32_t(y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; // Touch within the button area simulates an encoder button if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT) From 776ff26f6ad25833adb15a26a3960aeabfbb8ea9 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 23:16:27 -0300 Subject: [PATCH 07/21] rename XPT2046_** ==> TOUCH_** --- Marlin/Configuration.h | 8 +-- Marlin/src/inc/SanityCheck.h | 16 +++--- .../lib/mks_ui/tft_lvgl_configuration.cpp | 4 +- Marlin/src/lcd/tft/touch.cpp | 4 +- Marlin/src/lcd/tft_io/touch_calibration.h | 4 ++ Marlin/src/lcd/touch/touch_buttons.cpp | 4 +- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 32 +++++------ Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h | 32 +++++------ Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h | 32 +++++------ Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 16 +++--- Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 16 +++--- Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h | 56 +++++++++---------- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h | 32 +++++------ Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h | 16 +++--- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 32 +++++------ .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 16 +++--- Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h | 16 +++--- 17 files changed, 170 insertions(+), 166 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index ea77b4e429..93506e1920 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2340,10 +2340,10 @@ #define TOUCH_SCREEN_CALIBRATION - //#define XPT2046_X_CALIBRATION 12316 - //#define XPT2046_Y_CALIBRATION -8981 - //#define XPT2046_X_OFFSET -43 - //#define XPT2046_Y_OFFSET 257 + //#define TOUCH_CALIBRATION_X 12316 + //#define TOUCH_CALIBRATION_Y -8981 + //#define TOUCH_OFFSET_X -43 + //#define TOUCH_OFFSET_Y 257 #if ENABLED(TFT_COLOR_UI) //#define SINGLE_TOUCH_NAVIGATION diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 3762d40c53..5b42efeeef 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -3162,17 +3162,17 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) * Touch Buttons */ #if ENABLED(TOUCH_SCREEN) - #ifndef XPT2046_X_CALIBRATION - #error "XPT2046_X_CALIBRATION must be defined with TOUCH_SCREEN." + #ifndef TOUCH_CALIBRATION_X + #error "TOUCH_CALIBRATION_X must be defined with TOUCH_SCREEN." #endif - #ifndef XPT2046_Y_CALIBRATION - #error "XPT2046_Y_CALIBRATION must be defined with TOUCH_SCREEN." + #ifndef TOUCH_CALIBRATION_Y + #error "TOUCH_CALIBRATION_Y must be defined with TOUCH_SCREEN." #endif - #ifndef XPT2046_X_OFFSET - #error "XPT2046_X_OFFSET must be defined with TOUCH_SCREEN." + #ifndef TOUCH_OFFSET_X + #error "TOUCH_OFFSET_X must be defined with TOUCH_SCREEN." #endif - #ifndef XPT2046_Y_OFFSET - #error "XPT2046_Y_OFFSET must be defined with TOUCH_SCREEN." + #ifndef TOUCH_OFFSET_Y + #error "TOUCH_OFFSET_Y must be defined with TOUCH_SCREEN." #endif #endif diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index 21e3040c2e..48cadf8f4c 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -241,8 +241,8 @@ static bool get_point(int16_t *x, int16_t *y) { bool is_touched = touch.getRawPoint(x, y); if (is_touched) { - *x = int16_t((int32_t(*x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; - *y = int16_t((int32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; + *x = int16_t((int32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X; + *y = int16_t((int32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y; } #if (TFT_ROTATION & TFT_ROTATE_180) diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 1239b31f2f..112ff0b438 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -257,8 +257,8 @@ bool Touch::get_point(int16_t *x, int16_t *y) { } #else bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); - *x = uint16_t((uint32_t(*x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; - *y = uint16_t((uint32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; + *x = uint16_t((uint32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X; + *y = uint16_t((uint32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y; #endif return is_touched; } diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index f70d214a12..ff539d0edc 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -48,6 +48,10 @@ #endif #endif +#ifndef TOUCH_ORIENTATION + #define TOUCH_ORIENTATION TOUCH_LANDSCAPE +#endif + #if ENABLED(TOUCH_SCREEN_CALIBRATION) typedef struct __attribute__((__packed__)) { diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 32aa7ced54..f6b4c73bbc 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -60,8 +60,8 @@ uint8_t TouchButtons::read_buttons() { x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; y = int16_t((int32_t(y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; #else - x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; - y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; + x = uint16_t((uint32_t(x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X; + y = uint16_t((uint32_t(y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y; #endif diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h index 14bac7d723..f2edaf0ef6 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -329,30 +329,30 @@ // XPT2046 Touch Screen calibration #if ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -11245 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -11245 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8629 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 8629 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 685 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 685 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -285 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -285 #endif #elif ENABLED(TFT_480x320_SPI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -17232 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -17232 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11196 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11196 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 1047 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 1047 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -358 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -358 #endif #define TFT_BUFFER_SIZE 2400 diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h index f948c32f92..30f2df89a3 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h @@ -270,30 +270,30 @@ // XPT2046 Touch Screen calibration #if ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -11386 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -11386 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8684 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 8684 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 689 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 689 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -273 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -273 #endif #elif ENABLED(TFT_COLOR_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -16741 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -16741 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11258 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11258 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 1024 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 1024 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -367 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -367 #endif #define TFT_BUFFER_SIZE 2400 diff --git a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h index 0719752399..dee915026d 100644 --- a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h +++ b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h @@ -320,30 +320,30 @@ // XPT2046 Touch Screen calibration #if ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -11386 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -11386 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8684 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 8684 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 689 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 689 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -273 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -273 #endif #elif ENABLED(TFT_COLOR_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -17089 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -17089 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11424 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11424 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 1044 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 1044 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -365 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -365 #endif #define TFT_BUFFER_SIZE 2400 diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index b13fde026c..e3e84513af 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -158,17 +158,17 @@ // XPT2046 Touch Screen calibration #if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -17181 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -17181 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11434 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11434 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 501 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 501 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -9 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -9 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index a015fb2704..e4597772e3 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -173,17 +173,17 @@ // XPT2046 Touch Screen calibration #if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -17181 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -17181 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11434 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11434 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 501 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 501 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -9 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -9 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h index 5f91072440..e0de272d7f 100644 --- a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h +++ b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h @@ -286,22 +286,22 @@ // MKS Robin TFT v2.0 with ILI9341 // Read display identification information (0xD3 on ILI9341) -//#define XPT2046_X_CALIBRATION 12013 -//#define XPT2046_Y_CALIBRATION -8711 -//#define XPT2046_X_OFFSET -32 -//#define XPT2046_Y_OFFSET 256 +//#define TOUCH_CALIBRATION_X 12013 +//#define TOUCH_CALIBRATION_Y -8711 +//#define TOUCH_OFFSET_X -32 +//#define TOUCH_OFFSET_Y 256 // MKS Robin TFT v1.1 with ILI9328 -//#define XPT2046_X_CALIBRATION -11792 -//#define XPT2046_Y_CALIBRATION 8947 -//#define XPT2046_X_OFFSET 342 -//#define XPT2046_Y_OFFSET -19 +//#define TOUCH_CALIBRATION_X -11792 +//#define TOUCH_CALIBRATION_Y 8947 +//#define TOUCH_OFFSET_X 342 +//#define TOUCH_OFFSET_Y -19 // MKS Robin TFT v1.1 with R61505 -//#define XPT2046_X_CALIBRATION 12489 -//#define XPT2046_Y_CALIBRATION 9210 -//#define XPT2046_X_OFFSET -52 -//#define XPT2046_Y_OFFSET -17 +//#define TOUCH_CALIBRATION_X 12489 +//#define TOUCH_CALIBRATION_Y 9210 +//#define TOUCH_OFFSET_X -52 +//#define TOUCH_OFFSET_Y -17 // QQS-Pro uses MKS Robin TFT v2.0 @@ -328,31 +328,31 @@ #if EITHER(TFT_LVGL_UI_FSMC, TFT_COLOR_UI) #define TFT_BUFFER_SIZE 14400 - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION 12218 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X 12218 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION -8814 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y -8814 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET -35 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X -35 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET 256 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y 256 #endif #elif ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION 12149 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X 12149 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION -8746 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y -8746 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET -35 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X -35 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET 256 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y 256 #endif #define TFT_MARLINUI_COLOR 0xFFFF // White diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h index 9c0f2deeab..c98d532e34 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -284,30 +284,30 @@ // XPT2046 Touch Screen calibration #if EITHER(HAS_TFT_LVGL_UI, TFT_480x320_SPI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -17253 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -17253 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11579 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11579 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 514 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 514 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -24 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -24 #endif #elif HAS_SPI_GRAPHICAL_TFT - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -11386 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -11386 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8684 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 8684 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 339 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 339 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -18 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -18 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h index 2406c22d55..9be509ba47 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h @@ -171,17 +171,17 @@ #endif #if ENABLED(TOUCH_SCREEN) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION 12033 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X 12033 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION -9047 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y -9047 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET -30 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X -30 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET 254 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y 254 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 3c9b2f5b59..77fc7e8912 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -204,30 +204,30 @@ // XPT2046 Touch Screen calibration #if ANY(HAS_TFT_LVGL_UI_FSMC, TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_480x320) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION 17880 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X 17880 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION -12234 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y -12234 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET -45 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X -45 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET 349 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y 349 #endif #elif EITHER(TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_320x240) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -12246 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -12246 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 9453 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 9453 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 360 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 360 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -22 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -22 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index 9c1d073da6..07a04b413d 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -287,17 +287,17 @@ // XPT2046 Touch Screen calibration #if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -17253 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -17253 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11579 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11579 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 514 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 514 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -24 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -24 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h index 2fc34ce296..428469426e 100644 --- a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h @@ -141,17 +141,17 @@ // XPT2046 Touch Screen calibration #if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -17181 + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -17181 #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 11434 + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11434 #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 501 + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 501 #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -9 + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -9 #endif #endif From b54eac6173efd0bae0adec8cf2efa3e6d8bdbb6c Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 23:18:53 -0300 Subject: [PATCH 08/21] rename HAS_TOUCH_XPT2046 to HAS_TOUCH_BUTTONS --- Marlin/src/HAL/LPC1768/tft/xpt2046.cpp | 2 +- Marlin/src/HAL/STM32F1/tft/xpt2046.cpp | 2 +- Marlin/src/MarlinCore.cpp | 4 ++-- Marlin/src/gcode/bedlevel/G26.cpp | 2 +- Marlin/src/inc/Conditionals_LCD.h | 2 +- Marlin/src/inc/Conditionals_adv.h | 2 +- .../lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp | 12 ++++++------ Marlin/src/lcd/marlinui.cpp | 14 +++++++------- Marlin/src/lcd/marlinui.h | 10 +++++----- Marlin/src/lcd/menu/menu.cpp | 8 ++++---- Marlin/src/lcd/touch/touch_buttons.cpp | 4 ++-- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/tft/xpt2046.cpp b/Marlin/src/HAL/LPC1768/tft/xpt2046.cpp index e51256a708..cf14405484 100644 --- a/Marlin/src/HAL/LPC1768/tft/xpt2046.cpp +++ b/Marlin/src/HAL/LPC1768/tft/xpt2046.cpp @@ -22,7 +22,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046 +#if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS #include "xpt2046.h" #include diff --git a/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp index 4f5c4df375..98371c5ffb 100644 --- a/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp +++ b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp @@ -22,7 +22,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046 +#if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS #include "xpt2046.h" #include diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index be3dcdd109..d8f651b66a 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -60,7 +60,7 @@ #include "sd/cardreader.h" #include "lcd/marlinui.h" -#if HAS_TOUCH_XPT2046 +#if HAS_TOUCH_BUTTONS #include "lcd/touch/touch_buttons.h" #endif @@ -1101,7 +1101,7 @@ void setup() { SETUP_RUN(ethernet.init()); #endif - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS SETUP_RUN(touch.init()); #endif diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index 1c0d8cba8e..650b039b55 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -405,7 +405,7 @@ inline bool turn_on_heaters() { inline bool prime_nozzle() { const feedRate_t fr_slow_e = planner.settings.max_feedrate_mm_s[E_AXIS] / 15.0f; - #if HAS_LCD_MENU && !HAS_TOUCH_XPT2046 // ui.button_pressed issue with touchscreen + #if HAS_LCD_MENU && !HAS_TOUCH_BUTTONS // ui.button_pressed issue with touchscreen #if ENABLED(PREVENT_LENGTHY_EXTRUDE) float Total_Prime = 0.0; #endif diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 93c1974563..cc4b3f50b2 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1003,6 +1003,6 @@ #if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT #undef TOUCH_SCREEN #if !HAS_TFT_LVGL_UI - #define HAS_TOUCH_XPT2046 1 + #define HAS_TOUCH_BUTTONS 1 #endif #endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 2a898d6084..e49e146ae6 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -360,7 +360,7 @@ // Touch Screen or "Touch Buttons" need XPT2046 pins // but they use different components -#if EITHER(HAS_TFT_XPT2046, HAS_TOUCH_XPT2046) +#if EITHER(HAS_TFT_XPT2046, HAS_TOUCH_BUTTONS) #define NEED_TOUCH_PINS 1 #endif 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 3c2b49d7c4..ad17642605 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 @@ -134,7 +134,7 @@ static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, tftio.set_window(Xmin, Ymin, Xmax, Ymax); } -#if HAS_TOUCH_XPT2046 +#if HAS_TOUCH_BUTTONS static const uint8_t buttonD[] = { B01111111,B11111111,B11111111,B11111110, @@ -307,7 +307,7 @@ static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, } } -#endif // HAS_TOUCH_XPT2046 +#endif // HAS_TOUCH_BUTTONS // Used to fill RGB565 (16bits) background inline void memset2(const void *ptr, uint16_t fill, size_t cnt) { @@ -318,7 +318,7 @@ inline void memset2(const void *ptr, uint16_t fill, size_t cnt) { static bool preinit = true; static uint8_t page; -#if HAS_TOUCH_XPT2046 +#if HAS_TOUCH_BUTTONS static bool redrawTouchButtons = true; static void drawTouchButtons(u8g_t *u8g, u8g_dev_t *dev) { if (!redrawTouchButtons) { @@ -339,7 +339,7 @@ static uint8_t page; setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI); drawImage(buttonC, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTOKMENU_COLOR); } -#endif // HAS_TOUCH_XPT2046 +#endif // HAS_TOUCH_BUTTONS uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); @@ -378,7 +378,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u case U8G_DEV_MSG_PAGE_FIRST: page = 0; - TERN_(HAS_TOUCH_XPT2046, drawTouchButtons(u8g, dev)); + TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev)); setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI); break; @@ -516,7 +516,7 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, str = calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed"; defer_status_screen(false); touch_calibration.calibration_end(); - TERN_(HAS_TOUCH_XPT2046, redrawTouchButtons = true); + TERN_(HAS_TOUCH_BUTTONS, redrawTouchButtons = true); } // draw current message diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 1994e4094b..5ae7e057b1 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -158,7 +158,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; #if HAS_SLOW_BUTTONS volatile uint8_t MarlinUI::slow_buttons; #endif - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS #include "touch/touch_buttons.h" bool MarlinUI::on_edit_screen = false; #endif @@ -238,7 +238,7 @@ millis_t MarlinUI::next_button_update_ms; // = 0 int8_t MarlinUI::encoderDirection = ENCODERBASE; #endif - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS uint8_t MarlinUI::touch_buttons; uint8_t MarlinUI::repeat_delay; #endif @@ -855,7 +855,7 @@ void MarlinUI::update() { quick_feedback(); // - Always make a click sound }; - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS if (touch_buttons) { RESET_STATUS_TIMEOUT(); if (touch_buttons & (EN_A | EN_B)) { // Menu arrows, in priority @@ -876,7 +876,7 @@ void MarlinUI::update() { } else // keep wait_for_unclick value - #endif // HAS_TOUCH_XPT2046 + #endif // HAS_TOUCH_BUTTONS { // Integrated LCD click handling via button_pressed @@ -898,7 +898,7 @@ void MarlinUI::update() { next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL; - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS if (on_status_screen()) next_lcd_update_ms += (LCD_UPDATE_INTERVAL) * 2; @@ -1246,7 +1246,7 @@ void MarlinUI::update() { #if HAS_SLOW_BUTTONS | slow_buttons #endif - #if BOTH(HAS_TOUCH_XPT2046, HAS_ENCODER_ACTION) + #if BOTH(HAS_TOUCH_BUTTONS, HAS_ENCODER_ACTION) | (touch_buttons & TERN(HAS_ENCODER_WHEEL, ~(EN_A | EN_B), 0xFF)) #endif ); @@ -1557,7 +1557,7 @@ void MarlinUI::update() { #endif - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS // // Screen Click diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 2cee5b5f67..ce66ede86e 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -74,7 +74,7 @@ uint8_t get_ADC_keyValue(); #endif - #define LCD_UPDATE_INTERVAL TERN(HAS_TOUCH_XPT2046, 50, 100) + #define LCD_UPDATE_INTERVAL TERN(HAS_TOUCH_BUTTONS, 50, 100) #if HAS_LCD_MENU @@ -148,7 +148,7 @@ #define BUTTON_PRESSED(BN) !READ(BTN_## BN) - #if BUTTON_EXISTS(ENC) || HAS_TOUCH_XPT2046 + #if BUTTON_EXISTS(ENC) || HAS_TOUCH_BUTTONS #define BLEN_C 2 #define EN_C _BV(BLEN_C) #endif @@ -214,7 +214,7 @@ #endif -#if BUTTON_EXISTS(BACK) || EITHER(HAS_TOUCH_XPT2046, IS_TFTGLCD_PANEL) +#if BUTTON_EXISTS(BACK) || EITHER(HAS_TOUCH_BUTTONS, IS_TFTGLCD_PANEL) #define BLEN_D 3 #define EN_D _BV(BLEN_D) #define LCD_BACK_CLICKED() (buttons & EN_D) @@ -454,7 +454,7 @@ public: static void draw_hotend_status(const uint8_t row, const uint8_t extruder); #endif - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS static bool on_edit_screen; static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y); #endif @@ -514,7 +514,7 @@ public: static millis_t return_to_status_ms; #endif - #if HAS_TOUCH_XPT2046 + #if HAS_TOUCH_BUTTONS static uint8_t touch_buttons; static uint8_t repeat_delay; #endif diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 35c736c560..81ac32a60c 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -82,7 +82,7 @@ void MarlinUI::save_previous_screen() { void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) { IF_DISABLED(TURBO_BACK_MENU_ITEM, constexpr bool is_back = false); - TERN_(HAS_TOUCH_XPT2046, on_edit_screen = false); + TERN_(HAS_TOUCH_BUTTONS, on_edit_screen = false); if (screen_history_depth > 0) { menuPosition &sh = screen_history[--screen_history_depth]; goto_screen(sh.menu_function, @@ -123,7 +123,7 @@ void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_b * MenuItem_int3::draw(encoderLine == _thisItemNr, _lcdLineNr, plabel, &feedrate_percentage, 10, 999) */ void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) { - TERN_(HAS_TOUCH_XPT2046, ui.repeat_delay = BUTTON_DELAY_EDIT); + TERN_(HAS_TOUCH_BUTTONS, ui.repeat_delay = BUTTON_DELAY_EDIT); if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = 0; if (int32_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue; if (ui.should_draw()) @@ -145,7 +145,7 @@ void MenuEditItemBase::goto_edit_screen( const screenFunc_t cb, // Callback after edit const bool le // Flag to call cb() during editing ) { - TERN_(HAS_TOUCH_XPT2046, ui.on_edit_screen = true); + TERN_(HAS_TOUCH_BUTTONS, ui.on_edit_screen = true); ui.screen_changed = true; ui.save_previous_screen(); ui.refresh(); @@ -175,7 +175,7 @@ bool printer_busy() { void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) { if (currentScreen != screen) { - TERN_(HAS_TOUCH_XPT2046, repeat_delay = BUTTON_DELAY_MENU); + TERN_(HAS_TOUCH_BUTTONS, repeat_delay = BUTTON_DELAY_MENU); TERN_(LCD_SET_PROGRESS_MANUALLY, progress_reset()); diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index f6b4c73bbc..85bcff5bd3 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -19,7 +19,7 @@ #include "../../inc/MarlinConfig.h" -#if HAS_TOUCH_XPT2046 +#if HAS_TOUCH_BUTTONS #include "touch_buttons.h" #include "../scaled_tft.h" @@ -87,4 +87,4 @@ uint8_t TouchButtons::read_buttons() { return 0; } -#endif // HAS_TOUCH_XPT2046 +#endif // HAS_TOUCH_BUTTONS From d27b3b54fad5623b295527031c2e89285a91123b Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 23:23:35 -0300 Subject: [PATCH 09/21] fix error for lvgl --- Marlin/src/gcode/lcd/M995.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Marlin/src/gcode/lcd/M995.cpp b/Marlin/src/gcode/lcd/M995.cpp index 72d0d29f76..b35225614e 100644 --- a/Marlin/src/gcode/lcd/M995.cpp +++ b/Marlin/src/gcode/lcd/M995.cpp @@ -25,15 +25,19 @@ #if ENABLED(TOUCH_SCREEN_CALIBRATION) #include "../gcode.h" -#include "../../lcd/menu/menu.h" +#if DISABLED(TFT_LVGL_UI) + #include "../../lcd/menu/menu.h" +#endif /** * M995: Touch screen calibration for TFT display */ void GcodeSuite::M995() { - - ui.goto_screen(touch_screen_calibration); - + #if DISABLED(TFT_LVGL_UI) + ui.goto_screen(touch_screen_calibration); + #else + //TODO: show LVGL UI calibration screen + #endif } #endif // TOUCH_SCREEN_CALIBRATION From 03911ac738ed1cc82ba4331434900bca83992685 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 23:59:25 -0300 Subject: [PATCH 10/21] compatibility --- Marlin/src/inc/Conditionals_LCD.h | 17 +++++++++++++++++ Marlin/src/lcd/tft_io/touch_calibration.h | 16 ---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index cc4b3f50b2..d9dcdd1666 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1006,3 +1006,20 @@ #define HAS_TOUCH_BUTTONS 1 #endif #endif + +// XPT2046_** Compatibility +#if !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION)) + #if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET) + #define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION + #define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION + #define TOUCH_OFFSET_X XPT2046_X_OFFSET + #define TOUCH_OFFSET_Y XPT2046_Y_OFFSET + #define TOUCH_ORIENTATION TOUCH_LANDSCAPE + #else + #define TOUCH_CALIBRATION_X 0 + #define TOUCH_CALIBRATION_Y 0 + #define TOUCH_OFFSET_X 0 + #define TOUCH_OFFSET_Y 0 + #define TOUCH_ORIENTATION TOUCH_ORIENTATION_NONE + #endif +#endif diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index ff539d0edc..5d8b6c9951 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -32,22 +32,6 @@ #define TOUCH_LANDSCAPE 1 #define TOUCH_PORTRAIT 2 -#if !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION)) - #if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET) - #define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION - #define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION - #define TOUCH_OFFSET_X XPT2046_X_OFFSET - #define TOUCH_OFFSET_Y XPT2046_Y_OFFSET - #define TOUCH_ORIENTATION TOUCH_LANDSCAPE - #else - #define TOUCH_CALIBRATION_X 0 - #define TOUCH_CALIBRATION_Y 0 - #define TOUCH_OFFSET_X 0 - #define TOUCH_OFFSET_Y 0 - #define TOUCH_ORIENTATION TOUCH_ORIENTATION_NONE - #endif -#endif - #ifndef TOUCH_ORIENTATION #define TOUCH_ORIENTATION TOUCH_LANDSCAPE #endif From 914882849a8e47a76929fc2d3d8e2ce83a1c439e Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Fri, 6 Nov 2020 08:51:17 -0300 Subject: [PATCH 11/21] fix eeprom save --- Marlin/src/module/settings.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index c228561366..21997b4740 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -443,7 +443,7 @@ typedef struct SettingsDataStruct { // TOUCH_SCREEN_CALIBRATION // #if ENABLED(TOUCH_SCREEN_CALIBRATION) - touch_calibration_t touch_calibration; + touch_calibration_t touch_calibration_data; #endif // Ethernet settings @@ -1410,7 +1410,7 @@ void MarlinSettings::postprocess() { // TOUCH_SCREEN_CALIBRATION // #if ENABLED(TOUCH_SCREEN_CALIBRATION) - EEPROM_WRITE(touch.calibration); + EEPROM_WRITE(touch_calibration.calibration); #endif // @@ -2293,8 +2293,8 @@ void MarlinSettings::postprocess() { // TOUCH_SCREEN_CALIBRATION // #if ENABLED(TOUCH_SCREEN_CALIBRATION) - _FIELD_TEST(touch.calibration); - EEPROM_READ(touch.calibration); + _FIELD_TEST(touch_calibration_data); + EEPROM_READ(touch_calibration.calibration); #endif // From 8ca4ac15e090363e951b5fc922fb600b71f5a3f7 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Fri, 6 Nov 2020 12:18:36 -0300 Subject: [PATCH 12/21] touch validation --- Marlin/src/lcd/tft_io/touch_calibration.cpp | 59 ++++++++++----------- Marlin/src/lcd/tft_io/touch_calibration.h | 1 + 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/Marlin/src/lcd/tft_io/touch_calibration.cpp b/Marlin/src/lcd/tft_io/touch_calibration.cpp index aaac16c466..afed5dd7a5 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.cpp +++ b/Marlin/src/lcd/tft_io/touch_calibration.cpp @@ -29,6 +29,33 @@ touch_calibration_t TouchCalibration::calibration; calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE; touch_calibration_point_t TouchCalibration::calibration_points[4]; +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 portrait = validate_precision_y(0, 1) && validate_precision_y(2, 3) && validate_precision_x(0, 2) && validate_precision_x(1, 3); + + if (landscape || portrait) { + calibration_state = CALIBRATION_SUCCESS; + calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_x + calibration_points[2].raw_x - calibration_points[1].raw_x - calibration_points[0].raw_x); + calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_y - calibration_points[2].raw_y + calibration_points[1].raw_y - calibration_points[0].raw_y); + calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_x + calibration_points[1].raw_x) * calibration.x) >> 17); + calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_y + calibration_points[2].raw_y) * calibration.y) >> 17); + calibration.orientation = landscape ? TOUCH_LANDSCAPE : TOUCH_PORTRAIT; + } + else { + calibration_state = CALIBRATION_FAIL; + calibration_reset(); + } + + if (calibration_state == CALIBRATION_SUCCESS) { + SERIAL_ECHOLNPGM("Touch screen calibration completed"); + SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_X ", calibration.x); + SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y); + SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x); + SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y); + SERIAL_ECHOPGM("TOUCH_ORIENTATION "); if (calibration.orientation == TOUCH_LANDSCAPE) SERIAL_ECHOLNPGM("TOUCH_LANDSCAPE"); else SERIAL_ECHOLNPGM("TOUCH_PORTRAIT"); + } +} + bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) { static millis_t next_button_update_ms = 0; const millis_t now = millis(); @@ -44,37 +71,7 @@ bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) { case CALIBRATION_TOP_LEFT: calibration_state = CALIBRATION_BOTTOM_LEFT; break; case CALIBRATION_BOTTOM_LEFT: calibration_state = CALIBRATION_TOP_RIGHT; break; case CALIBRATION_TOP_RIGHT: calibration_state = CALIBRATION_BOTTOM_RIGHT; break; - case CALIBRATION_BOTTOM_RIGHT: - if (validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3)) { - calibration_state = CALIBRATION_SUCCESS; - calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_x + calibration_points[2].raw_x - calibration_points[1].raw_x - calibration_points[0].raw_x); - calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_y - calibration_points[2].raw_y + calibration_points[1].raw_y - calibration_points[0].raw_y); - calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_x + calibration_points[1].raw_x) * calibration.x) >> 17); - calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_y + calibration_points[2].raw_y) * calibration.y) >> 17); - calibration.orientation = TOUCH_LANDSCAPE; - } - else if (validate_precision_y(0, 1) && validate_precision_y(2, 3) && validate_precision_x(0, 2) && validate_precision_x(1, 3)) { - calibration_state = CALIBRATION_SUCCESS; - calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_y + calibration_points[2].raw_y - calibration_points[1].raw_y - calibration_points[0].raw_y); - calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_x - calibration_points[2].raw_x + calibration_points[1].raw_x - calibration_points[0].raw_x); - calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_y + calibration_points[1].raw_y) * calibration.x) >> 17); - calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_x + calibration_points[2].raw_x) * calibration.y) >> 17); - calibration.orientation = TOUCH_PORTRAIT; - } - else { - calibration_state = CALIBRATION_FAIL; - calibration_reset(); - } - - if (calibration_state == CALIBRATION_SUCCESS) { - SERIAL_ECHOLNPGM("Touch screen calibration completed"); - SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_X ", calibration.x); - SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y); - SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x); - SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y); - SERIAL_ECHOPGM("TOUCH_ORIENTATION "); if (calibration.orientation == TOUCH_LANDSCAPE) SERIAL_ECHOLNPGM("TOUCH_LANDSCAPE"); else SERIAL_ECHOLNPGM("TOUCH_PORTRAIT"); - } - break; + case CALIBRATION_BOTTOM_RIGHT: validate_calibration(); break; default: break; } diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index 5d8b6c9951..ce6625bef4 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -71,6 +71,7 @@ public: static bool validate_precision(int32_t a, int32_t b) { return (a > b ? (100 * b) / a : (100 * a) / b) > TOUCH_SCREEN_CALIBRATION_PRECISION; } static bool validate_precision_x(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_x, calibration_points[b].raw_x); } static bool validate_precision_y(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_y, calibration_points[b].raw_y); } + static void validate_calibration(); static touch_calibration_t calibration; static void calibration_reset() { calibration = {TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION}; } From 95c629a20eb47c6979289d1330201f33fb6dfb90 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Mon, 9 Nov 2020 22:56:00 -0300 Subject: [PATCH 13/21] touch calibration screen for LVGL --- Marlin/src/gcode/lcd/M995.cpp | 4 +- .../lib/mks_ui/draw_touch_calibration.cpp | 118 ++++++++++++++++++ .../extui/lib/mks_ui/draw_touch_calibration.h | 35 ++++++ Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 9 ++ Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h | 3 +- .../lib/mks_ui/tft_lvgl_configuration.cpp | 24 ++-- 6 files changed, 184 insertions(+), 9 deletions(-) create mode 100644 Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp create mode 100644 Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h diff --git a/Marlin/src/gcode/lcd/M995.cpp b/Marlin/src/gcode/lcd/M995.cpp index b35225614e..aca0401dc4 100644 --- a/Marlin/src/gcode/lcd/M995.cpp +++ b/Marlin/src/gcode/lcd/M995.cpp @@ -27,6 +27,8 @@ #include "../gcode.h" #if DISABLED(TFT_LVGL_UI) #include "../../lcd/menu/menu.h" +#else + #include "../../lcd/extui/lib/mks_ui/draw_touch_calibration.h" #endif /** @@ -36,7 +38,7 @@ void GcodeSuite::M995() { #if DISABLED(TFT_LVGL_UI) ui.goto_screen(touch_screen_calibration); #else - //TODO: show LVGL UI calibration screen + lv_draw_touch_calibration_screen(); #endif } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp new file mode 100644 index 0000000000..0780bcf17d --- /dev/null +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp @@ -0,0 +1,118 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#include "../../../../inc/MarlinConfigPre.h" + +#if HAS_TFT_LVGL_UI && ENABLED(TOUCH_SCREEN_CALIBRATION) + +#include "draw_ui.h" +#include "draw_touch_calibration.h" +#include + +#include "../../../../inc/MarlinConfig.h" +#include "../../../tft_io/touch_calibration.h" +#include "SPI_TFT.h" + +static lv_obj_t *scr; +static lv_obj_t *status_label; + +static void event_handler(lv_obj_t *obj, lv_event_t event); + +enum { + ID_TC_RETURN = 1 +}; + +static void drawCross(uint16_t x, uint16_t y, uint16_t color) { + SPI_TFT.tftio.set_window(x - 15, y, x + 15, y); + SPI_TFT.tftio.WriteMultiple(color, 31); + SPI_TFT.tftio.set_window(x, y - 15, x, y + 15); + SPI_TFT.tftio.WriteMultiple(color, 31); +} + +void lv_update_touch_calibration_screen() { + uint16_t x, y; + + calibrationState calibration_stage = touch_calibration.get_calibration_state(); + if (calibration_stage == CALIBRATION_NONE) { + // start and clear screen + calibration_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; + drawCross(x, y, LV_COLOR_BACKGROUND.full); + } + + const char *str = nullptr; + if (calibration_stage < CALIBRATION_SUCCESS) { + // handle current state + switch (calibration_stage) { + case CALIBRATION_TOP_LEFT: str = "Top Left"; break; + case CALIBRATION_BOTTOM_LEFT: str = "Bottom Left"; break; + case CALIBRATION_TOP_RIGHT: str = "Top Right"; break; + case CALIBRATION_BOTTOM_RIGHT: str = "Bottom Right"; break; + default: break; + } + + x = touch_calibration.calibration_points[calibration_stage].x; + y = touch_calibration.calibration_points[calibration_stage].y; + drawCross(x, y, LV_COLOR_WHITE.full); + } + else { + // end calibration + str = calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed, send M995 to try again"; + 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); + } + + // draw current message + lv_label_set_text(status_label, str); + lv_obj_align(status_label, nullptr, LV_ALIGN_CENTER, 0, 0); +} + +static void event_handler(lv_obj_t *obj, lv_event_t event) { + if (event != LV_EVENT_RELEASED) return; + switch (obj->mks_obj_id) { + case ID_TC_RETURN: + TERN_(MKS_TEST, curent_disp_ui = 1); + lv_clear_touch_calibration_screen(); + lv_draw_ready_print(); + break; + } +} + +void lv_draw_touch_calibration_screen(void) { + scr = lv_screen_create(TOUCH_CALIBRATION_UI, ""); + + status_label = lv_label_create(scr, ""); + lv_obj_align(status_label, nullptr, LV_ALIGN_CENTER, 0, 0); + + lv_refr_now(lv_refr_get_disp_refreshing()); + + lv_update_touch_calibration_screen(); +} + +void lv_clear_touch_calibration_screen() { + lv_obj_del(scr); +} + +#endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h new file mode 100644 index 0000000000..8d29be3734 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h @@ -0,0 +1,35 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#ifdef __cplusplus + extern "C" { /* C-declarations for C++ */ +#endif + +extern void lv_draw_touch_calibration_screen(void); +extern void lv_clear_touch_calibration_screen(); +extern void lv_update_touch_calibration_screen(); + +//extern void disp_temp_ready_print(); +#ifdef __cplusplus + } /* C-declarations for C++ */ +#endif diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp index c7f5f418f5..6f97bf130b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -48,6 +48,10 @@ #include "../../../../feature/pause.h" #endif +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + #include "draw_touch_calibration.h" +#endif + CFG_ITMES gCfgItems; UI_CFG uiCfg; DISP_STATE_STACK disp_state_stack; @@ -1360,6 +1364,11 @@ void clear_cur_ui() { lv_clear_encoder_settings(); break; #endif + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + case TOUCH_CALIBRATION_UI: + lv_clear_touch_calibration_screen(); + break; + #endif default: break; } //GUI_Clear(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h index eb54b3e4ea..6d162676e8 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.h @@ -313,7 +313,8 @@ typedef enum { EEPROM_SETTINGS_UI, WIFI_SETTINGS_UI, HOMING_SENSITIVITY_UI, - ENCODER_SETTINGS_UI + ENCODER_SETTINGS_UI, + TOUCH_CALIBRATION_UI } DISP_STATE; typedef struct { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index 48cadf8f4c..e35fb7521c 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -51,6 +51,11 @@ XPT2046 touch; #include "../../../../feature/powerloss.h" #endif +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + #include "../../../tft_io/touch_calibration.h" + #include "draw_touch_calibration.h" +#endif + #include #ifndef TFT_WIDTH @@ -240,17 +245,22 @@ unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) { static bool get_point(int16_t *x, int16_t *y) { bool is_touched = touch.getRawPoint(x, y); - if (is_touched) { + if (!is_touched) return false; + + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + const calibrationState state = touch_calibration.get_calibration_state(); + if (state >= CALIBRATION_TOP_LEFT && state <= CALIBRATION_BOTTOM_RIGHT) { + if (touch_calibration.handleTouch(*x, *y)) lv_update_touch_calibration_screen(); + return false; + } + *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; + *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; + #else *x = int16_t((int32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X; *y = int16_t((int32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y; - } - - #if (TFT_ROTATION & TFT_ROTATE_180) - *x = int16_t((TFT_WIDTH) - (int)(*x)); - *y = int16_t((TFT_HEIGHT) - (int)(*y)); #endif - return is_touched; + return true; } bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { From a9e41e5e810f24d75c4084ca4b2acad635f5289c Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Tue, 10 Nov 2020 00:07:21 -0300 Subject: [PATCH 14/21] start touch calibration on lvgl if no calibration is stored on settings --- Marlin/src/HAL/STM32F1/SPI.cpp | 8 ++++---- .../src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp | 2 ++ .../src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp | 9 ++++++++- Marlin/src/lcd/tft_io/touch_calibration.h | 1 + 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/SPI.cpp b/Marlin/src/HAL/STM32F1/SPI.cpp index 8995109238..c0a35b88d1 100644 --- a/Marlin/src/HAL/STM32F1/SPI.cpp +++ b/Marlin/src/HAL/STM32F1/SPI.cpp @@ -147,15 +147,15 @@ SPIClass::SPIClass(uint32_t spi_num) { _currentSetting->state = SPI_STATE_IDLE; } -SPIClass::SPIClass(int8_t mosi, int8_t miso, int8_t sclk, int8_t ssel) { +SPIClass::SPIClass(int8_t mosi, int8_t miso, int8_t sclk, int8_t ssel) : SPIClass(1) { #if BOARD_NR_SPI >= 1 - if (mosi == BOARD_SPI1_MOSI_PIN) SPIClass(1); + if (mosi == BOARD_SPI1_MOSI_PIN) setModule(1); #endif #if BOARD_NR_SPI >= 2 - if (mosi == BOARD_SPI2_MOSI_PIN) SPIClass(2); + if (mosi == BOARD_SPI2_MOSI_PIN) setModule(2); #endif #if BOARD_NR_SPI >= 3 - if (mosi == BOARD_SPI3_MOSI_PIN) SPIClass(3); + if (mosi == BOARD_SPI3_MOSI_PIN) setModule(3); #endif } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp index 0780bcf17d..ec2c817bce 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp @@ -101,6 +101,8 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { } void lv_draw_touch_calibration_screen(void) { + disp_state_stack._disp_index = 0; + ZERO(disp_state_stack._disp_state); scr = lv_screen_create(TOUCH_CALIBRATION_UI, ""); status_label = lv_label_create(scr, ""); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index e35fb7521c..9b8e3e1589 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -216,7 +216,14 @@ void tft_lvgl_init() { } #endif - if (ready) lv_draw_ready_print(); + 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(); + #endif + } if (mks_test_flag == 0x1E) mks_gpio_test(); diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index ce6625bef4..58d09fdf12 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -75,6 +75,7 @@ public: static touch_calibration_t calibration; 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 calibrationState calibration_start() { calibration = {0, 0, 0, 0, TOUCH_ORIENTATION_NONE}; From 4fba2dd7e4b4d822da160b37c8d91443aa33c8c7 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Tue, 10 Nov 2020 00:31:40 -0300 Subject: [PATCH 15/21] touch calibration on startup for marlin ui - classic and color --- Marlin/src/MarlinCore.cpp | 4 ++++ Marlin/src/lcd/marlinui.h | 10 ++++++++++ Marlin/src/lcd/touch/touch_buttons.cpp | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index d8f651b66a..fc127d22ce 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -1299,6 +1299,10 @@ void setup() { SETUP_RUN(password.lock_machine()); // Will not proceed until correct password provided #endif + #if HAS_LCD_MENU && ENABLED(TOUCH_SCREEN_CALIBRATION) && EITHER(TFT_CLASSIC_UI, TFT_COLOR_UI) + ui.check_touch_calibration(); + #endif + marlin_state = MF_RUNNING; SETUP_LOG("setup() completed."); diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index ce66ede86e..d7063d937c 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -31,6 +31,10 @@ #include "../sd/cardreader.h" #endif +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + #include "tft_io/touch_calibration.h" +#endif + #if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY) #define HAS_ENCODER_ACTION 1 #endif @@ -313,6 +317,12 @@ public: // LCD implementations static void clear_lcd(); + #if HAS_LCD_MENU && ENABLED(TOUCH_SCREEN_CALIBRATION) + static void check_touch_calibration() { + if (touch_calibration.need_calibration()) currentScreen = touch_calibration_screen; + } + #endif + #if ENABLED(SDSUPPORT) static void media_changed(const uint8_t old_stat, const uint8_t stat); #endif diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 85bcff5bd3..8e231ca9ab 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -31,7 +31,7 @@ XPT2046 touchIO; #include "../tft_io/touch_calibration.h" #endif -#include "../../lcd/marlinui.h" // For EN_C bit mask +#include "../marlinui.h" // For EN_C bit mask #define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X #define DOGM_AREA_TOP TFT_PIXEL_OFFSET_Y From dc335041d4e914530bc144c5d16a9d21c53a3054 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Tue, 10 Nov 2020 00:37:16 -0300 Subject: [PATCH 16/21] remove xpt values from pins files of boards that have more that one display --- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 31 +--------------- Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h | 31 +--------------- Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h | 31 +--------------- Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h | 36 ------------------- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h | 29 --------------- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 29 --------------- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 16 --------- 7 files changed, 3 insertions(+), 200 deletions(-) diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h index f2edaf0ef6..6e718e70a0 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -327,36 +327,7 @@ #define LCD_PINS_ENABLE -1 #define LCD_PINS_RS -1 - // XPT2046 Touch Screen calibration - #if ENABLED(TFT_CLASSIC_UI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -11245 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 8629 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 685 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -285 - #endif - #elif ENABLED(TFT_480x320_SPI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -17232 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11196 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 1047 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -358 - #endif - - #define TFT_BUFFER_SIZE 2400 - #endif + #define TFT_BUFFER_SIZE 2400 #elif IS_TFTGLCD_PANEL diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h index 30f2df89a3..ae96fb5d05 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h @@ -268,36 +268,7 @@ #define LCD_PINS_ENABLE -1 #define LCD_PINS_RS -1 - // XPT2046 Touch Screen calibration - #if ENABLED(TFT_CLASSIC_UI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -11386 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 8684 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 689 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -273 - #endif - #elif ENABLED(TFT_COLOR_UI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -16741 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11258 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 1024 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -367 - #endif - - #define TFT_BUFFER_SIZE 2400 - #endif + #define TFT_BUFFER_SIZE 2400 #define BTN_EN1 P3_25 #define BTN_EN2 P3_26 diff --git a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h index dee915026d..c84e5304b1 100644 --- a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h +++ b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h @@ -318,36 +318,7 @@ #define LCD_PINS_ENABLE -1 #define LCD_PINS_RS -1 - // XPT2046 Touch Screen calibration - #if ENABLED(TFT_CLASSIC_UI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -11386 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 8684 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 689 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -273 - #endif - #elif ENABLED(TFT_COLOR_UI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -17089 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11424 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 1044 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -365 - #endif - - #define TFT_BUFFER_SIZE 2400 - #endif + #define TFT_BUFFER_SIZE 2400 #else // !MKS_12864OLED_SSD1306 diff --git a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h index e0de272d7f..70bede3515 100644 --- a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h +++ b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h @@ -324,42 +324,6 @@ #define TOUCH_BUTTONS_HW_SPI_DEVICE 2 #endif -// XPT2046 Touch Screen calibration -#if EITHER(TFT_LVGL_UI_FSMC, TFT_COLOR_UI) - #define TFT_BUFFER_SIZE 14400 - - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X 12218 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y -8814 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X -35 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y 256 - #endif - -#elif ENABLED(TFT_CLASSIC_UI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X 12149 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y -8746 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X -35 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y 256 - #endif - - #define TFT_MARLINUI_COLOR 0xFFFF // White - #define TFT_BTARROWS_COLOR 0xDEE6 // 11011 110111 00110 Yellow - #define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan -#endif - #if NEED_TOUCH_PINS #define TOUCH_CS_PIN PC2 // SPI2_NSS #define TOUCH_SCK_PIN PB13 // SPI2_SCK diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h index c98d532e34..b1f41f9fa7 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -282,35 +282,6 @@ #define TFT_BUFFER_SIZE 14400 #endif -// XPT2046 Touch Screen calibration -#if EITHER(HAS_TFT_LVGL_UI, TFT_480x320_SPI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -17253 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11579 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 514 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -24 - #endif -#elif HAS_SPI_GRAPHICAL_TFT - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -11386 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 8684 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 339 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -18 - #endif -#endif - #if HAS_WIRED_LCD && !HAS_SPI_TFT // NON TFT Displays diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 77fc7e8912..760f27060e 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -202,35 +202,6 @@ #define TFT_BUFFER_SIZE 14400 #endif -// XPT2046 Touch Screen calibration -#if ANY(HAS_TFT_LVGL_UI_FSMC, TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_480x320) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X 17880 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y -12234 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X -45 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y 349 - #endif -#elif EITHER(TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_320x240) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -12246 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 9453 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 360 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -22 - #endif -#endif - #define HAS_SPI_FLASH 1 #if HAS_SPI_FLASH #define SPI_FLASH_SIZE 0x1000000 // 16MB diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index 07a04b413d..8b41296971 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -285,22 +285,6 @@ #define TFT_BUFFER_SIZE 14400 #endif -// XPT2046 Touch Screen calibration -#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) - #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -17253 - #endif - #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11579 - #endif - #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 514 - #endif - #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -24 - #endif -#endif - #if HAS_WIRED_LCD && !HAS_SPI_TFT // NON TFT Displays From 2806669fda0549d9be6e6c35e89cef021576bc39 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Tue, 10 Nov 2020 00:48:49 -0300 Subject: [PATCH 17/21] better offsets for touch calibration --- Marlin/src/lcd/tft/ui_320x240.cpp | 14 +++++++++----- Marlin/src/lcd/tft/ui_480x320.cpp | 14 +++++++++----- Marlin/src/lcd/tft_io/touch_calibration.h | 16 ++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index ecfa094787..eb08cb2704 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -585,7 +585,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #if ENABLED(TOUCH_SCREEN_CALIBRATION) void MarlinUI::touch_calibration_screen() { - static uint16_t x, y; + uint16_t x, y; calibrationState calibration_stage = touch_calibration.get_calibration_state(); @@ -595,22 +595,26 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const calibration_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; tft.canvas(x - 15, y - 15, 31, 31); tft.set_background(COLOR_BACKGROUND); } - x = 20; y = 20; touch.clear(); if (calibration_stage < CALIBRATION_SUCCESS) { switch (calibration_stage) { case CALIBRATION_TOP_LEFT: tft_string.set("Top Left"); break; - case CALIBRATION_BOTTOM_LEFT: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; - case CALIBRATION_TOP_RIGHT: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; - case CALIBRATION_BOTTOM_RIGHT: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; + case CALIBRATION_BOTTOM_LEFT: tft_string.set("Bottom Left"); break; + case CALIBRATION_TOP_RIGHT: tft_string.set("Top Right"); break; + case CALIBRATION_BOTTOM_RIGHT: tft_string.set("Bottom Right"); break; default: break; } + x = touch_calibration.calibration_points[calibration_stage].x; + y = touch_calibration.calibration_points[calibration_stage].y; + tft.canvas(x - 15, y - 15, 31, 31); tft.set_background(COLOR_BACKGROUND); tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 0e8ed4eb57..e0e0e01bb7 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -590,7 +590,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #if ENABLED(TOUCH_SCREEN_CALIBRATION) void MarlinUI::touch_calibration_screen() { - static uint16_t x, y; + uint16_t x, y; calibrationState calibration_stage = touch_calibration.get_calibration_state(); @@ -600,22 +600,26 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const calibration_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; tft.canvas(x - 15, y - 15, 31, 31); tft.set_background(COLOR_BACKGROUND); } - x = 20; y = 20; touch.clear(); if (calibration_stage < CALIBRATION_SUCCESS) { switch (calibration_stage) { case CALIBRATION_TOP_LEFT: tft_string.set("Top Left"); break; - case CALIBRATION_BOTTOM_LEFT: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; - case CALIBRATION_TOP_RIGHT: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; - case CALIBRATION_BOTTOM_RIGHT: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; + case CALIBRATION_BOTTOM_LEFT: tft_string.set("Bottom Left"); break; + case CALIBRATION_TOP_RIGHT: tft_string.set("Top Right"); break; + case CALIBRATION_BOTTOM_RIGHT: tft_string.set("Bottom Right"); break; default: break; } + x = touch_calibration.calibration_points[calibration_stage].x; + y = touch_calibration.calibration_points[calibration_stage].y; + tft.canvas(x - 15, y - 15, 31, 31); tft.set_background(COLOR_BACKGROUND); tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index 58d09fdf12..fdc03e3d18 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -80,14 +80,14 @@ public: static calibrationState calibration_start() { calibration = {0, 0, 0, 0, TOUCH_ORIENTATION_NONE}; calibration_state = CALIBRATION_TOP_LEFT; - calibration_points[CALIBRATION_TOP_LEFT].x = 20; - calibration_points[CALIBRATION_TOP_LEFT].y = 20; - calibration_points[CALIBRATION_BOTTOM_LEFT].x = 20; - calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 21; - calibration_points[CALIBRATION_TOP_RIGHT].x = TFT_WIDTH - 21; - calibration_points[CALIBRATION_TOP_RIGHT].y = 20; - calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 21; - calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 21; + calibration_points[CALIBRATION_TOP_LEFT].x = 30; + calibration_points[CALIBRATION_TOP_LEFT].y = 30; + calibration_points[CALIBRATION_BOTTOM_LEFT].x = 30; + calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 31; + calibration_points[CALIBRATION_TOP_RIGHT].x = TFT_WIDTH - 31; + calibration_points[CALIBRATION_TOP_RIGHT].y = 30; + calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31; + calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31; return calibration_state; } static void calibration_end() { calibration_state = CALIBRATION_NONE; } From 1312edac853fbddb3330ac9229560af180efc8ce Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 10 Nov 2020 04:34:28 -0600 Subject: [PATCH 18/21] Apply standards --- Marlin/src/MarlinCore.cpp | 2 +- Marlin/src/gcode/lcd/M995.cpp | 15 +- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 8 +- .../lib/mks_ui/draw_touch_calibration.cpp | 6 +- .../extui/lib/mks_ui/draw_touch_calibration.h | 2 +- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 569 +++++------------- Marlin/src/lcd/marlinui.h | 2 +- Marlin/src/lcd/menu/menu_bed_leveling.cpp | 4 +- Marlin/src/lcd/tft/touch.h | 9 +- Marlin/src/lcd/tft_io/touch_calibration.cpp | 6 +- Marlin/src/lcd/tft_io/touch_calibration.h | 20 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 8 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 8 +- Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h | 24 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h | 8 +- Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h | 8 +- 16 files changed, 212 insertions(+), 487 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 925fa2f631..d2a65447a4 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -1299,7 +1299,7 @@ void setup() { SETUP_RUN(password.lock_machine()); // Will not proceed until correct password provided #endif - #if HAS_LCD_MENU && ENABLED(TOUCH_SCREEN_CALIBRATION) && EITHER(TFT_CLASSIC_UI, TFT_COLOR_UI) + #if BOTH(HAS_LCD_MENU, TOUCH_SCREEN_CALIBRATION) && EITHER(TFT_CLASSIC_UI, TFT_COLOR_UI) ui.check_touch_calibration(); #endif diff --git a/Marlin/src/gcode/lcd/M995.cpp b/Marlin/src/gcode/lcd/M995.cpp index aca0401dc4..bc8dc35d4e 100644 --- a/Marlin/src/gcode/lcd/M995.cpp +++ b/Marlin/src/gcode/lcd/M995.cpp @@ -25,21 +25,24 @@ #if ENABLED(TOUCH_SCREEN_CALIBRATION) #include "../gcode.h" -#if DISABLED(TFT_LVGL_UI) - #include "../../lcd/menu/menu.h" -#else + +#if ENABLED(TFT_LVGL_UI) #include "../../lcd/extui/lib/mks_ui/draw_touch_calibration.h" +#else + #include "../../lcd/menu/menu.h" #endif /** * M995: Touch screen calibration for TFT display */ void GcodeSuite::M995() { - #if DISABLED(TFT_LVGL_UI) - ui.goto_screen(touch_screen_calibration); - #else + + #if ENABLED(TFT_LVGL_UI) lv_draw_touch_calibration_screen(); + #else + ui.goto_screen(touch_screen_calibration); #endif + } #endif // TOUCH_SCREEN_CALIBRATION 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 ad17642605..ca338ae9b2 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 @@ -321,12 +321,10 @@ static uint8_t page; #if HAS_TOUCH_BUTTONS static bool redrawTouchButtons = true; static void drawTouchButtons(u8g_t *u8g, u8g_dev_t *dev) { - if (!redrawTouchButtons) { - return; - } + if (!redrawTouchButtons) return; redrawTouchButtons = false; - // Bottom buttons + // Bottom buttons setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI); drawImage(buttonD, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTCANCEL_COLOR); @@ -471,6 +469,7 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_TFT_FN); #if ENABLED(TOUCH_SCREEN_CALIBRATION) + static void drawCross(uint16_t x, uint16_t y, uint16_t color) { tftio.set_window(x - 15, y, x + 15, y); tftio.WriteMultiple(color, 31); @@ -527,6 +526,7 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, } while (u8g.nextPage()); drawing_screen = false; } + #endif // TOUCH_SCREEN_CALIBRATION #endif // HAS_MARLINUI_U8GLIB && (FSMC_CS_PIN || HAS_SPI_GRAPHICAL_TFT) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp index ec2c817bce..9e7c22bd7e 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp @@ -21,7 +21,7 @@ */ #include "../../../../inc/MarlinConfigPre.h" -#if HAS_TFT_LVGL_UI && ENABLED(TOUCH_SCREEN_CALIBRATION) +#if BOTH(HAS_TFT_LVGL_UI, TOUCH_SCREEN_CALIBRATION) #include "draw_ui.h" #include "draw_touch_calibration.h" @@ -100,7 +100,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { } } -void lv_draw_touch_calibration_screen(void) { +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, ""); @@ -117,4 +117,4 @@ void lv_clear_touch_calibration_screen() { lv_obj_del(scr); } -#endif // HAS_TFT_LVGL_UI +#endif // HAS_TFT_LVGL_UI && TOUCH_SCREEN_CALIBRATION diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h index 8d29be3734..b14700dcf3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.h @@ -25,7 +25,7 @@ extern "C" { /* C-declarations for C++ */ #endif -extern void lv_draw_touch_calibration_screen(void); +extern void lv_draw_touch_calibration_screen(); extern void lv_clear_touch_calibration_screen(); extern void lv_update_touch_calibration_screen(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp index 6f97bf130b..a2617662f8 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -1142,232 +1142,94 @@ void clear_cur_ui() { last_disp_state = disp_state_stack._disp_state[disp_state_stack._disp_index]; switch (disp_state_stack._disp_state[disp_state_stack._disp_index]) { - case PRINT_READY_UI: - //Get_Temperature_Flg = 0; - lv_clear_ready_print(); - break; - case PRINT_FILE_UI: - lv_clear_print_file(); - break; - case PRINTING_UI: - lv_clear_printing(); - break; - case MOVE_MOTOR_UI: - lv_clear_move_motor(); - break; - case OPERATE_UI: - lv_clear_operation(); - break; - case PAUSE_UI: - //Clear_pause(); - break; - case EXTRUSION_UI: - lv_clear_extrusion(); - break; - case PRE_HEAT_UI: - lv_clear_preHeat(); - break; - case CHANGE_SPEED_UI: - lv_clear_change_speed(); - break; - case FAN_UI: - lv_clear_fan(); - break; - case SET_UI: - lv_clear_set(); - break; - case ZERO_UI: - lv_clear_home(); - break; - case SPRAYER_UI: - //Clear_Sprayer(); - break; - case MACHINE_UI: - //Clear_Machine(); - break; - case LANGUAGE_UI: - lv_clear_language(); - break; - case ABOUT_UI: - lv_clear_about(); - break; - case LOG_UI: - //Clear_Connect(); - break; - case DISK_UI: - //Clear_Disk(); - break; + case PRINT_READY_UI: //Get_Temperature_Flg = 0; + lv_clear_ready_print(); break; + case PRINT_FILE_UI: lv_clear_print_file(); break; + case PRINTING_UI: lv_clear_printing(); break; + case MOVE_MOTOR_UI: lv_clear_move_motor(); break; + case OPERATE_UI: lv_clear_operation(); break; + case PAUSE_UI: /* Clear_pause(); */ break; + case EXTRUSION_UI: lv_clear_extrusion(); break; + case PRE_HEAT_UI: lv_clear_preHeat(); break; + case CHANGE_SPEED_UI: lv_clear_change_speed(); break; + case FAN_UI: lv_clear_fan(); break; + case SET_UI: lv_clear_set(); break; + case ZERO_UI: lv_clear_home(); break; + case SPRAYER_UI: /* Clear_Sprayer(); */ break; + case MACHINE_UI: /* Clear_Machine(); */ break; + case LANGUAGE_UI: lv_clear_language(); break; + case ABOUT_UI: lv_clear_about(); break; + case LOG_UI: /* Clear_Connect(); */ break; + case DISK_UI: /* Clear_Disk(); */ break; #if ENABLED(USE_WIFI_FUNCTION) - case WIFI_UI: - lv_clear_wifi(); - break; + case WIFI_UI: lv_clear_wifi(); break; #endif - case MORE_UI: - //Clear_more(); - break; - case FILETRANSFER_UI: - //Clear_fileTransfer(); - break; - case DIALOG_UI: - lv_clear_dialog(); - break; - case FILETRANSFERSTATE_UI: - //Clear_WifiFileTransferdialog(); - break; - case PRINT_MORE_UI: - //Clear_Printmore(); - break; - case FILAMENTCHANGE_UI: - lv_clear_filament_change(); - break; - case LEVELING_UI: - lv_clear_manualLevel(); - break; - case BIND_UI: - //Clear_Bind(); - break; + case MORE_UI: /* Clear_more(); */ break; + case FILETRANSFER_UI: /* Clear_fileTransfer(); */ break; + case DIALOG_UI: lv_clear_dialog(); break; + case FILETRANSFERSTATE_UI: /* Clear_WifiFileTransferdialog(); */ break; + case PRINT_MORE_UI: /* Clear_Printmore(); */ break; + case FILAMENTCHANGE_UI: lv_clear_filament_change(); break; + case LEVELING_UI: lv_clear_manualLevel(); break; + case BIND_UI: /* Clear_Bind(); */ break; #if HAS_BED_PROBE - case NOZZLE_PROBE_OFFSET_UI: - lv_clear_auto_level_offset_settings(); - break; + case NOZZLE_PROBE_OFFSET_UI: lv_clear_auto_level_offset_settings(); break; #endif - case TOOL_UI: - lv_clear_tool(); - break; - case MESHLEVELING_UI: - //Clear_MeshLeveling(); - break; - case HARDWARE_TEST_UI: - //Clear_Hardwaretest(); - break; + case TOOL_UI: lv_clear_tool(); break; + case MESHLEVELING_UI: /* Clear_MeshLeveling(); */ break; + case HARDWARE_TEST_UI: /* Clear_Hardwaretest(); */ break; #if ENABLED(USE_WIFI_FUNCTION) - case WIFI_LIST_UI: - lv_clear_wifi_list(); - break; + case WIFI_LIST_UI: lv_clear_wifi_list(); break; #endif - case KEY_BOARD_UI: - lv_clear_keyboard(); - break; + case KEY_BOARD_UI: lv_clear_keyboard(); break; #if ENABLED(USE_WIFI_FUNCTION) - case WIFI_TIPS_UI: - lv_clear_wifi_tips(); - break; + case WIFI_TIPS_UI: lv_clear_wifi_tips(); break; #endif - case MACHINE_PARA_UI: - lv_clear_machine_para(); - break; - case MACHINE_SETTINGS_UI: - lv_clear_machine_settings(); - break; - case TEMPERATURE_SETTINGS_UI: - //Clear_TemperatureSettings(); - break; - case MOTOR_SETTINGS_UI: - lv_clear_motor_settings(); - break; - case MACHINETYPE_UI: - //Clear_MachineType(); - break; - case STROKE_UI: - //Clear_Stroke(); - break; - case HOME_DIR_UI: - //Clear_HomeDir(); - break; - case ENDSTOP_TYPE_UI: - //Clear_EndstopType(); - break; - case FILAMENT_SETTINGS_UI: - lv_clear_filament_settings(); - break; - case LEVELING_SETTIGNS_UI: - //Clear_LevelingSettings(); - break; - case LEVELING_PARA_UI: - lv_clear_level_settings(); - break; - case DELTA_LEVELING_PARA_UI: - //Clear_DeltaLevelPara(); - break; - case MANUAL_LEVELING_POSIGION_UI: - lv_clear_manual_level_pos_settings(); - break; - case MAXFEEDRATE_UI: - lv_clear_max_feedrate_settings(); - break; - case STEPS_UI: - lv_clear_step_settings(); - break; - case ACCELERATION_UI: - lv_clear_acceleration_settings(); - break; - case JERK_UI: - #if HAS_CLASSIC_JERK - lv_clear_jerk_settings(); - #endif - break; - case MOTORDIR_UI: - //Clear_MotorDir(); - break; - case HOMESPEED_UI: - //Clear_HomeSpeed(); - break; - case NOZZLE_CONFIG_UI: - //Clear_NozzleConfig(); - break; - case HOTBED_CONFIG_UI: - //Clear_HotbedConfig(); - break; - case ADVANCED_UI: - lv_clear_advance_settings(); - break; - case DOUBLE_Z_UI: - //Clear_DoubleZ(); - break; - case ENABLE_INVERT_UI: - //Clear_EnableInvert(); - break; - case NUMBER_KEY_UI: - lv_clear_number_key(); - break; - case BABY_STEP_UI: - lv_clear_baby_stepping(); - break; - case PAUSE_POS_UI: - lv_clear_pause_position(); - break; + case MACHINE_PARA_UI: lv_clear_machine_para(); break; + case MACHINE_SETTINGS_UI: lv_clear_machine_settings(); break; + case TEMPERATURE_SETTINGS_UI: /* Clear_TemperatureSettings(); */ break; + case MOTOR_SETTINGS_UI: lv_clear_motor_settings(); break; + case MACHINETYPE_UI: /* Clear_MachineType(); */ break; + case STROKE_UI: /* Clear_Stroke(); */ break; + case HOME_DIR_UI: /* Clear_HomeDir(); */ break; + case ENDSTOP_TYPE_UI: /* Clear_EndstopType(); */ break; + case FILAMENT_SETTINGS_UI: lv_clear_filament_settings(); break; + case LEVELING_SETTIGNS_UI: /* Clear_LevelingSettings(); */ break; + case LEVELING_PARA_UI: lv_clear_level_settings(); break; + case DELTA_LEVELING_PARA_UI: /* Clear_DeltaLevelPara(); */ break; + case MANUAL_LEVELING_POSIGION_UI: lv_clear_manual_level_pos_settings(); break; + case MAXFEEDRATE_UI: lv_clear_max_feedrate_settings(); break; + case STEPS_UI: lv_clear_step_settings(); break; + case ACCELERATION_UI: lv_clear_acceleration_settings(); break; + case JERK_UI: TERN_(HAS_CLASSIC_JERK, lv_clear_jerk_settings()); break; + case MOTORDIR_UI: /* Clear_MotorDir(); */ break; + case HOMESPEED_UI: /* Clear_HomeSpeed(); */ break; + case NOZZLE_CONFIG_UI: /* Clear_NozzleConfig(); */ break; + case HOTBED_CONFIG_UI: /* Clear_HotbedConfig(); */ break; + case ADVANCED_UI: lv_clear_advance_settings(); break; + case DOUBLE_Z_UI: /* Clear_DoubleZ(); */ break; + case ENABLE_INVERT_UI: /* Clear_EnableInvert(); */ break; + case NUMBER_KEY_UI: lv_clear_number_key(); break; + case BABY_STEP_UI: lv_clear_baby_stepping(); break; + case PAUSE_POS_UI: lv_clear_pause_position(); break; #if HAS_TRINAMIC_CONFIG - case TMC_CURRENT_UI: - lv_clear_tmc_current_settings(); - break; + case TMC_CURRENT_UI: lv_clear_tmc_current_settings(); break; #endif - case EEPROM_SETTINGS_UI: - lv_clear_eeprom_settings(); - break; + case EEPROM_SETTINGS_UI: lv_clear_eeprom_settings(); break; #if HAS_STEALTHCHOP - case TMC_MODE_UI: - lv_clear_tmc_step_mode_settings(); - break; + case TMC_MODE_UI: lv_clear_tmc_step_mode_settings(); break; #endif #if ENABLED(USE_WIFI_FUNCTION) - case WIFI_SETTINGS_UI: - lv_clear_wifi_settings(); - break; + case WIFI_SETTINGS_UI: lv_clear_wifi_settings(); break; #endif #if USE_SENSORLESS - case HOMING_SENSITIVITY_UI: - lv_clear_homing_sensitivity_settings(); - break; + case HOMING_SENSITIVITY_UI: lv_clear_homing_sensitivity_settings(); break; #endif #if HAS_ROTARY_ENCODER - case ENCODER_SETTINGS_UI: - lv_clear_encoder_settings(); - break; + case ENCODER_SETTINGS_UI: lv_clear_encoder_settings(); break; #endif #if ENABLED(TOUCH_SCREEN_CALIBRATION) - case TOUCH_CALIBRATION_UI: - lv_clear_touch_calibration_screen(); - break; + case TOUCH_CALIBRATION_UI: lv_clear_touch_calibration_screen(); break; #endif default: break; } @@ -1379,227 +1241,98 @@ void draw_return_ui() { disp_state_stack._disp_index--; switch (disp_state_stack._disp_state[disp_state_stack._disp_index]) { - case PRINT_READY_UI: - lv_draw_ready_print(); - break; - case PRINT_FILE_UI: - lv_draw_print_file(); - break; - case PRINTING_UI: - if (gCfgItems.from_flash_pic) flash_preview_begin = true; - else default_preview_flg = true; - lv_draw_printing(); - break; - case MOVE_MOTOR_UI: - lv_draw_move_motor(); - break; - case OPERATE_UI: - lv_draw_operation(); - break; + case PRINT_READY_UI: lv_draw_ready_print(); break; + case PRINT_FILE_UI: lv_draw_print_file(); break; - #if 1 - case PAUSE_UI: - //draw_pause(); - break; - #endif + case PRINTING_UI: if (gCfgItems.from_flash_pic) + flash_preview_begin = true; + else + default_preview_flg = true; + lv_draw_printing(); + break; - case EXTRUSION_UI: - lv_draw_extrusion(); - break; - case PRE_HEAT_UI: - lv_draw_preHeat(); - break; - case CHANGE_SPEED_UI: - lv_draw_change_speed(); - break; - case FAN_UI: - lv_draw_fan(); - break; - case SET_UI: - lv_draw_set(); - break; - case ZERO_UI: - lv_draw_home(); - break; - case SPRAYER_UI: - //draw_Sprayer(); - break; - case MACHINE_UI: - //draw_Machine(); - break; - case LANGUAGE_UI: - lv_draw_language(); - break; - case ABOUT_UI: - lv_draw_about(); - break; + case MOVE_MOTOR_UI: lv_draw_move_motor(); break; + case OPERATE_UI: lv_draw_operation(); break; + case PAUSE_UI: /* draw_pause(); */ break; + case EXTRUSION_UI: lv_draw_extrusion(); break; + case PRE_HEAT_UI: lv_draw_preHeat(); break; + case CHANGE_SPEED_UI: lv_draw_change_speed(); break; + case FAN_UI: lv_draw_fan(); break; + case SET_UI: lv_draw_set(); break; + case ZERO_UI: lv_draw_home(); break; + case SPRAYER_UI: /* draw_Sprayer(); */ break; + case MACHINE_UI: /* draw_Machine(); */ break; + case LANGUAGE_UI: lv_draw_language(); break; + case ABOUT_UI: lv_draw_about(); break; - case CALIBRATE_UI: - //draw_calibrate(); - break; - case DISK_UI: - //draw_Disk(); - break; + case CALIBRATE_UI: /* draw_calibrate(); */ break; + case DISK_UI: /* draw_Disk(); */ break; #if ENABLED(USE_WIFI_FUNCTION) - case WIFI_UI: - lv_draw_wifi(); - break; + case WIFI_UI: lv_draw_wifi(); break; #endif - case MORE_UI: - //draw_More(); - break; - case PRINT_MORE_UI: - //draw_printmore(); - break; - case FILAMENTCHANGE_UI: - lv_draw_filament_change(); - break; - case LEVELING_UI: - lv_draw_manualLevel(); - break; - case BIND_UI: - //draw_bind(); - break; + case MORE_UI: /* draw_More(); */ break; + case PRINT_MORE_UI: /* draw_printmore(); */ break; + case FILAMENTCHANGE_UI: lv_draw_filament_change(); break; + case LEVELING_UI: lv_draw_manualLevel(); break; + case BIND_UI: /* draw_bind(); */ break; #if HAS_BED_PROBE - case NOZZLE_PROBE_OFFSET_UI: - lv_draw_auto_level_offset_settings(); - break; + case NOZZLE_PROBE_OFFSET_UI: lv_draw_auto_level_offset_settings(); break; #endif - case TOOL_UI: - lv_draw_tool(); - break; - case MESHLEVELING_UI: - //draw_meshleveling(); - break; - case HARDWARE_TEST_UI: - //draw_Hardwaretest(); - break; - case WIFI_LIST_UI: - #if ENABLED(USE_WIFI_FUNCTION) - lv_draw_wifi_list(); - #endif - break; - case KEY_BOARD_UI: - lv_draw_keyboard(); - break; - case WIFI_TIPS_UI: - #if ENABLED(USE_WIFI_FUNCTION) - lv_draw_wifi_tips(); - #endif - break; - case MACHINE_PARA_UI: - lv_draw_machine_para(); - break; - case MACHINE_SETTINGS_UI: - lv_draw_machine_settings(); - break; - case TEMPERATURE_SETTINGS_UI: - //draw_TemperatureSettings(); - break; - case MOTOR_SETTINGS_UI: - lv_draw_motor_settings(); - break; - case MACHINETYPE_UI: - //draw_MachineType(); - break; - case STROKE_UI: - //draw_Stroke(); - break; - case HOME_DIR_UI: - //draw_HomeDir(); - break; - case ENDSTOP_TYPE_UI: - //draw_EndstopType(); - break; - case FILAMENT_SETTINGS_UI: - lv_draw_filament_settings(); - break; - case LEVELING_SETTIGNS_UI: - //draw_LevelingSettings(); - break; - case LEVELING_PARA_UI: - lv_draw_level_settings(); - break; - case DELTA_LEVELING_PARA_UI: - //draw_DeltaLevelPara(); - break; - case MANUAL_LEVELING_POSIGION_UI: - lv_draw_manual_level_pos_settings(); - break; - case MAXFEEDRATE_UI: - lv_draw_max_feedrate_settings(); - break; - case STEPS_UI: - lv_draw_step_settings(); - break; - case ACCELERATION_UI: - lv_draw_acceleration_settings(); - break; - case JERK_UI: - #if HAS_CLASSIC_JERK - lv_draw_jerk_settings(); - #endif - break; - case MOTORDIR_UI: - //draw_MotorDir(); - break; - case HOMESPEED_UI: - //draw_HomeSpeed(); - break; - case NOZZLE_CONFIG_UI: - //draw_NozzleConfig(); - break; - case HOTBED_CONFIG_UI: - //draw_HotbedConfig(); - break; - case ADVANCED_UI: - lv_draw_advance_settings(); - break; - case DOUBLE_Z_UI: - //draw_DoubleZ(); - break; - case ENABLE_INVERT_UI: - //draw_EnableInvert(); - break; - case NUMBER_KEY_UI: - lv_draw_number_key(); - break; - case DIALOG_UI: - //draw_dialog(uiCfg.dialogType); - break; - case BABY_STEP_UI: - lv_draw_baby_stepping(); - break; - case PAUSE_POS_UI: - lv_draw_pause_position(); - break; - #if HAS_TRINAMIC_CONFIG - case TMC_CURRENT_UI: - lv_draw_tmc_current_settings(); - break; - #endif - case EEPROM_SETTINGS_UI: - lv_draw_eeprom_settings(); - break; + case TOOL_UI: lv_draw_tool(); break; + case MESHLEVELING_UI: /* draw_meshleveling(); */ break; + case HARDWARE_TEST_UI: /* draw_Hardwaretest(); */ break; + #if ENABLED(USE_WIFI_FUNCTION) + case WIFI_LIST_UI: lv_draw_wifi_list(); break; + #endif + case KEY_BOARD_UI: lv_draw_keyboard(); break; + #if ENABLED(USE_WIFI_FUNCTION) + case WIFI_TIPS_UI: lv_draw_wifi_tips(); break; + #endif + case MACHINE_PARA_UI: lv_draw_machine_para(); break; + case MACHINE_SETTINGS_UI: lv_draw_machine_settings(); break; + case TEMPERATURE_SETTINGS_UI: /* draw_TemperatureSettings(); */ break; + case MOTOR_SETTINGS_UI: lv_draw_motor_settings(); break; + case MACHINETYPE_UI: /* draw_MachineType(); */ break; + case STROKE_UI: /* draw_Stroke(); */ break; + case HOME_DIR_UI: /* draw_HomeDir(); */ break; + case ENDSTOP_TYPE_UI: /* draw_EndstopType(); */ break; + case FILAMENT_SETTINGS_UI: lv_draw_filament_settings(); break; + case LEVELING_SETTIGNS_UI: /* draw_LevelingSettings(); */ break; + case LEVELING_PARA_UI: lv_draw_level_settings(); break; + case DELTA_LEVELING_PARA_UI: /* draw_DeltaLevelPara(); */ break; + case MANUAL_LEVELING_POSIGION_UI: lv_draw_manual_level_pos_settings(); break; + case MAXFEEDRATE_UI: lv_draw_max_feedrate_settings(); break; + case STEPS_UI: lv_draw_step_settings(); break; + case ACCELERATION_UI: lv_draw_acceleration_settings(); break; + #if HAS_CLASSIC_JERK + case JERK_UI: lv_draw_jerk_settings(); break; + #endif + case MOTORDIR_UI: /* draw_MotorDir(); */ break; + case HOMESPEED_UI: /* draw_HomeSpeed(); */ break; + case NOZZLE_CONFIG_UI: /* draw_NozzleConfig(); */ break; + case HOTBED_CONFIG_UI: /* draw_HotbedConfig(); */ break; + case ADVANCED_UI: lv_draw_advance_settings(); break; + case DOUBLE_Z_UI: /* draw_DoubleZ(); */ break; + case ENABLE_INVERT_UI: /* draw_EnableInvert(); */ break; + case NUMBER_KEY_UI: lv_draw_number_key(); break; + case DIALOG_UI: /* draw_dialog(uiCfg.dialogType); */ break; + case BABY_STEP_UI: lv_draw_baby_stepping(); break; + case PAUSE_POS_UI: lv_draw_pause_position(); break; + #if HAS_TRINAMIC_CONFIG + case TMC_CURRENT_UI: lv_draw_tmc_current_settings(); break; + #endif + case EEPROM_SETTINGS_UI: lv_draw_eeprom_settings(); break; #if HAS_STEALTHCHOP - case TMC_MODE_UI: - lv_draw_tmc_step_mode_settings(); - break; + case TMC_MODE_UI: lv_draw_tmc_step_mode_settings(); break; #endif #if ENABLED(USE_WIFI_FUNCTION) - case WIFI_SETTINGS_UI: - lv_draw_wifi_settings(); - break; + case WIFI_SETTINGS_UI: lv_draw_wifi_settings(); break; #endif #if USE_SENSORLESS - case HOMING_SENSITIVITY_UI: - lv_draw_homing_sensitivity_settings(); - break; + case HOMING_SENSITIVITY_UI: lv_draw_homing_sensitivity_settings(); break; #endif #if HAS_ROTARY_ENCODER - case ENCODER_SETTINGS_UI: - lv_draw_encoder_settings(); - break; + case ENCODER_SETTINGS_UI: lv_draw_encoder_settings(); break; #endif default: break; } @@ -1888,15 +1621,11 @@ void LV_TASK_HANDLER() { lv_task_handler(); if (mks_test_flag == 0x1E) mks_hardware_test(); - #if HAS_GCODE_PREVIEW - disp_pre_gcode(2, 36); - #endif + TERN_(HAS_GCODE_PREVIEW, disp_pre_gcode(2, 36)); GUI_RefreshPage(); - #if ENABLED(USE_WIFI_FUNCTION) - get_wifi_commands(); - #endif + TERN_(USE_WIFI_FUNCTION, get_wifi_commands()); //sd_detection(); diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index d7063d937c..ad253aad51 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -317,7 +317,7 @@ public: // LCD implementations static void clear_lcd(); - #if HAS_LCD_MENU && ENABLED(TOUCH_SCREEN_CALIBRATION) + #if BOTH(HAS_LCD_MENU, TOUCH_SCREEN_CALIBRATION) static void check_touch_calibration() { if (touch_calibration.need_calibration()) currentScreen = touch_calibration_screen; } diff --git a/Marlin/src/lcd/menu/menu_bed_leveling.cpp b/Marlin/src/lcd/menu/menu_bed_leveling.cpp index e19b04ccb5..905d7a07cd 100644 --- a/Marlin/src/lcd/menu/menu_bed_leveling.cpp +++ b/Marlin/src/lcd/menu/menu_bed_leveling.cpp @@ -37,8 +37,10 @@ #endif #if HAS_GRAPHICAL_TFT - #include "../tft/touch.h" #include "../tft/tft.h" + #if ENABLED(TOUCH_SCREEN) + #include "../tft/touch.h" + #endif #endif #if EITHER(PROBE_MANUALLY, MESH_BED_LEVELING) diff --git a/Marlin/src/lcd/tft/touch.h b/Marlin/src/lcd/tft/touch.h index c632b10be0..8023f649ce 100644 --- a/Marlin/src/lcd/tft/touch.h +++ b/Marlin/src/lcd/tft/touch.h @@ -23,11 +23,12 @@ #include "../../inc/MarlinConfigPre.h" -#if ENABLED(TOUCH_SCREEN) - #include "tft_color.h" #include "tft_image.h" -#include "../tft_io/touch_calibration.h" + +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + #include "../tft_io/touch_calibration.h" +#endif #include HAL_PATH(../../HAL, tft/xpt2046.h) #define TOUCH_DRIVER XPT2046 @@ -117,5 +118,3 @@ class Touch { }; extern Touch touch; - -#endif // TOUCH_SCREEN diff --git a/Marlin/src/lcd/tft_io/touch_calibration.cpp b/Marlin/src/lcd/tft_io/touch_calibration.cpp index afed5dd7a5..e4ad8f215b 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.cpp +++ b/Marlin/src/lcd/tft_io/touch_calibration.cpp @@ -17,11 +17,11 @@ * */ -#include "touch_calibration.h" +#include "../../inc/MarlinConfig.h" #if ENABLED(TOUCH_SCREEN_CALIBRATION) -#include "../../inc/MarlinConfig.h" +#include "touch_calibration.h" TouchCalibration touch_calibration; @@ -78,4 +78,4 @@ bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) { return true; } -#endif // ENABLED(TOUCH_SCREEN_CALIBRATION) +#endif // TOUCH_SCREEN_CALIBRATION diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index fdc03e3d18..5bebafffd2 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -36,21 +36,15 @@ #define TOUCH_ORIENTATION TOUCH_LANDSCAPE #endif -#if ENABLED(TOUCH_SCREEN_CALIBRATION) - typedef struct __attribute__((__packed__)) { - int32_t x; - int32_t y; - int16_t offset_x; - int16_t offset_y; + int32_t x, y; + int16_t offset_x, offset_y; uint8_t orientation; } touch_calibration_t; typedef struct __attribute__((__packed__)) { - uint16_t x; - uint16_t y; - int16_t raw_x; - int16_t raw_y; + uint16_t x, y; + int16_t raw_x, raw_y; } touch_calibration_point_t; enum calibrationState : uint8_t { @@ -74,11 +68,11 @@ public: static void validate_calibration(); static touch_calibration_t calibration; - 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 calibrationState calibration_start() { - calibration = {0, 0, 0, 0, TOUCH_ORIENTATION_NONE}; + calibration = { 0, 0, 0, 0, TOUCH_ORIENTATION_NONE }; calibration_state = CALIBRATION_TOP_LEFT; calibration_points[CALIBRATION_TOP_LEFT].x = 30; calibration_points[CALIBRATION_TOP_LEFT].y = 30; @@ -97,5 +91,3 @@ public: }; extern TouchCalibration touch_calibration; - -#endif diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index e3e84513af..32d4e0c9d4 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -159,16 +159,16 @@ // XPT2046 Touch Screen calibration #if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -17181 + #define TOUCH_CALIBRATION_X -17181 #endif #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11434 + #define TOUCH_CALIBRATION_Y 11434 #endif #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 501 + #define TOUCH_OFFSET_X 501 #endif #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -9 + #define TOUCH_OFFSET_Y -9 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index e4597772e3..066a6cc8aa 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -174,16 +174,16 @@ // XPT2046 Touch Screen calibration #if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -17181 + #define TOUCH_CALIBRATION_X -17181 #endif #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11434 + #define TOUCH_CALIBRATION_Y 11434 #endif #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 501 + #define TOUCH_OFFSET_X 501 #endif #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -9 + #define TOUCH_OFFSET_Y -9 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h index 70bede3515..a056aa96e5 100644 --- a/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h +++ b/Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h @@ -286,22 +286,22 @@ // MKS Robin TFT v2.0 with ILI9341 // Read display identification information (0xD3 on ILI9341) -//#define TOUCH_CALIBRATION_X 12013 -//#define TOUCH_CALIBRATION_Y -8711 -//#define TOUCH_OFFSET_X -32 -//#define TOUCH_OFFSET_Y 256 +//#define TOUCH_CALIBRATION_X 12013 +//#define TOUCH_CALIBRATION_Y -8711 +//#define TOUCH_OFFSET_X -32 +//#define TOUCH_OFFSET_Y 256 // MKS Robin TFT v1.1 with ILI9328 -//#define TOUCH_CALIBRATION_X -11792 -//#define TOUCH_CALIBRATION_Y 8947 -//#define TOUCH_OFFSET_X 342 -//#define TOUCH_OFFSET_Y -19 +//#define TOUCH_CALIBRATION_X -11792 +//#define TOUCH_CALIBRATION_Y 8947 +//#define TOUCH_OFFSET_X 342 +//#define TOUCH_OFFSET_Y -19 // MKS Robin TFT v1.1 with R61505 -//#define TOUCH_CALIBRATION_X 12489 -//#define TOUCH_CALIBRATION_Y 9210 -//#define TOUCH_OFFSET_X -52 -//#define TOUCH_OFFSET_Y -17 +//#define TOUCH_CALIBRATION_X 12489 +//#define TOUCH_CALIBRATION_Y 9210 +//#define TOUCH_OFFSET_X -52 +//#define TOUCH_OFFSET_Y -17 // QQS-Pro uses MKS Robin TFT v2.0 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h index 9be509ba47..ca4dd8d792 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h @@ -172,16 +172,16 @@ #if ENABLED(TOUCH_SCREEN) #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X 12033 + #define TOUCH_CALIBRATION_X 12033 #endif #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y -9047 + #define TOUCH_CALIBRATION_Y -9047 #endif #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X -30 + #define TOUCH_OFFSET_X -30 #endif #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y 254 + #define TOUCH_OFFSET_Y 254 #endif #endif diff --git a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h index 428469426e..543a90b66b 100644 --- a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h @@ -142,16 +142,16 @@ // XPT2046 Touch Screen calibration #if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -17181 + #define TOUCH_CALIBRATION_X -17181 #endif #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 11434 + #define TOUCH_CALIBRATION_Y 11434 #endif #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 501 + #define TOUCH_OFFSET_X 501 #endif #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -9 + #define TOUCH_OFFSET_Y -9 #endif #endif From 08bf5bd1ab2a2c9418c6261c62bc5299ba67dd06 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Tue, 10 Nov 2020 23:45:28 -0300 Subject: [PATCH 19/21] correct macro for touch buttons --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 15b8d4c23a..fb82140181 100644 --- a/platformio.ini +++ b/platformio.ini @@ -236,7 +236,7 @@ HAS_SPI_TFT = src_filter=+ + DWIN_CREALITY_LCD = src_filter=+ IS_TFTGLCD_PANEL = src_filter=+ -HAS_TOUCH_XPT2046 = src_filter=+ +HAS_TOUCH_BUTTONS = src_filter=+ HAS_LCD_MENU = src_filter=+ HAS_GAMES = src_filter=+ MARLIN_BRICKOUT = src_filter=+ From 38e5fe4d2c5ec26a97ddbaddbbdb199eff1a4a11 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Tue, 10 Nov 2020 23:49:27 -0300 Subject: [PATCH 20/21] i18n of touch calibration screen --- Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp | 8 ++++---- .../src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp | 8 ++++---- Marlin/src/lcd/language/language_en.h | 7 +++++++ Marlin/src/lcd/language/language_fr.h | 7 +++++++ Marlin/src/lcd/language/language_pt.h | 7 +++++++ Marlin/src/lcd/language/language_pt_br.h | 7 +++++++ Marlin/src/lcd/tft/ui_320x240.cpp | 8 ++++---- Marlin/src/lcd/tft/ui_480x320.cpp | 8 ++++---- 8 files changed, 44 insertions(+), 16 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 ca338ae9b2..3bbcc80a46 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 @@ -499,10 +499,10 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, if (calibration_stage < CALIBRATION_SUCCESS) { // handle current state switch (calibration_stage) { - case CALIBRATION_TOP_LEFT: str = "Top Left"; break; - case CALIBRATION_BOTTOM_LEFT: str = "Bottom Left"; break; - case CALIBRATION_TOP_RIGHT: str = "Top Right"; break; - case CALIBRATION_BOTTOM_RIGHT: str = "Bottom Right"; break; + 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; + case CALIBRATION_BOTTOM_RIGHT: str = GET_TEXT(MSG_BOTTOM_RIGHT); break; default: break; } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp index 9e7c22bd7e..b35296cf91 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp @@ -66,10 +66,10 @@ void lv_update_touch_calibration_screen() { if (calibration_stage < CALIBRATION_SUCCESS) { // handle current state switch (calibration_stage) { - case CALIBRATION_TOP_LEFT: str = "Top Left"; break; - case CALIBRATION_BOTTOM_LEFT: str = "Bottom Left"; break; - case CALIBRATION_TOP_RIGHT: str = "Top Right"; break; - case CALIBRATION_BOTTOM_RIGHT: str = "Bottom Right"; break; + 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; + case CALIBRATION_BOTTOM_RIGHT: str = GET_TEXT(MSG_BOTTOM_RIGHT); break; default: break; } diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index ffaaf2e02a..e7e628cd14 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -671,6 +671,13 @@ namespace Language_en { PROGMEM Language_Str MSG_PROBE_WIZARD = _UxGT("Z Probe Wizard"); PROGMEM Language_Str MSG_SOUND = _UxGT("Sound"); + + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + PROGMEM Language_Str MSG_TOP_LEFT = _UxGT("Top Left"); + PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Bottom Left"); + PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Top Right"); + PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Bottom Right"); + #endif } #if FAN_COUNT == 1 diff --git a/Marlin/src/lcd/language/language_fr.h b/Marlin/src/lcd/language/language_fr.h index 661d6b5cc3..a944f0a0b8 100644 --- a/Marlin/src/lcd/language/language_fr.h +++ b/Marlin/src/lcd/language/language_fr.h @@ -570,4 +570,11 @@ namespace Language_fr { PROGMEM Language_Str MSG_SERVICE_IN = _UxGT(" dans:"); PROGMEM Language_Str MSG_BACKLASH_CORRECTION = _UxGT("Correction"); PROGMEM Language_Str MSG_BACKLASH_SMOOTHING = _UxGT("Lissage"); + + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + PROGMEM Language_Str MSG_TOP_LEFT = _UxGT("Haut à Gauche"); + PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Bas à Gauche"); + PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Haut à Droite"); + PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Bas à Droite"); + #endif } diff --git a/Marlin/src/lcd/language/language_pt.h b/Marlin/src/lcd/language/language_pt.h index 37da621624..8a63c61749 100644 --- a/Marlin/src/lcd/language/language_pt.h +++ b/Marlin/src/lcd/language/language_pt.h @@ -160,4 +160,11 @@ namespace Language_pt { PROGMEM Language_Str MSG_LCD_ENDSTOPS = _UxGT("Fim de curso"); PROGMEM Language_Str MSG_KILL_EXPECTED_PRINTER = _UxGT("Impressora Incorreta"); + + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + PROGMEM Language_Str MSG_TOP_LEFT = _UxGT("Superior Esquerdo"); + PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Inferior Esquerdo"); + PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Superior Direto"); + PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Inferior Direto"); + #endif } diff --git a/Marlin/src/lcd/language/language_pt_br.h b/Marlin/src/lcd/language/language_pt_br.h index b52ae51c1c..a52f2106ae 100644 --- a/Marlin/src/lcd/language/language_pt_br.h +++ b/Marlin/src/lcd/language/language_pt_br.h @@ -478,4 +478,11 @@ namespace Language_pt_br { PROGMEM Language_Str MSG_FILAMENT_CHANGE_CONT_PURGE = _UxGT(MSG_1_LINE("Clique p. finalizar")); PROGMEM Language_Str MSG_FILAMENT_CHANGE_RESUME = _UxGT(MSG_1_LINE("Continuando...")); #endif + + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + PROGMEM Language_Str MSG_TOP_LEFT = _UxGT("Superior Esquerdo"); + PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Inferior Esquerdo"); + PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Superior Direto"); + PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Inferior Direto"); + #endif } diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index eb08cb2704..9382831659 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -605,10 +605,10 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const if (calibration_stage < CALIBRATION_SUCCESS) { switch (calibration_stage) { - case CALIBRATION_TOP_LEFT: tft_string.set("Top Left"); break; - case CALIBRATION_BOTTOM_LEFT: tft_string.set("Bottom Left"); break; - case CALIBRATION_TOP_RIGHT: tft_string.set("Top Right"); break; - case CALIBRATION_BOTTOM_RIGHT: tft_string.set("Bottom Right"); break; + 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; + case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; default: break; } diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index e0e0e01bb7..179405af47 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -610,10 +610,10 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const if (calibration_stage < CALIBRATION_SUCCESS) { switch (calibration_stage) { - case CALIBRATION_TOP_LEFT: tft_string.set("Top Left"); break; - case CALIBRATION_BOTTOM_LEFT: tft_string.set("Bottom Left"); break; - case CALIBRATION_TOP_RIGHT: tft_string.set("Top Right"); break; - case CALIBRATION_BOTTOM_RIGHT: tft_string.set("Bottom Right"); break; + 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; + case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; default: break; } From 5b713292d5c086ac63e872207a8c46cd48584b58 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Wed, 11 Nov 2020 11:19:58 -0300 Subject: [PATCH 21/21] more i18n --- Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp | 2 +- Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp | 2 +- Marlin/src/lcd/language/language_en.h | 2 ++ Marlin/src/lcd/language/language_fr.h | 2 ++ Marlin/src/lcd/language/language_pt.h | 2 ++ Marlin/src/lcd/language/language_pt_br.h | 2 ++ Marlin/src/lcd/tft/ui_320x240.cpp | 2 +- Marlin/src/lcd/tft/ui_480x320.cpp | 2 +- 8 files changed, 12 insertions(+), 4 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 3bbcc80a46..d7d09fda5b 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 @@ -512,7 +512,7 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, } else { // end calibration - str = calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed"; + str = calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED); defer_status_screen(false); touch_calibration.calibration_end(); TERN_(HAS_TOUCH_BUTTONS, redrawTouchButtons = true); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp index b35296cf91..69307a702b 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_touch_calibration.cpp @@ -79,7 +79,7 @@ void lv_update_touch_calibration_screen() { } else { // end calibration - str = calibration_stage == CALIBRATION_SUCCESS ? "Calibration Completed" : "Calibration Failed, send M995 to try again"; + str = calibration_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/language/language_en.h b/Marlin/src/lcd/language/language_en.h index e7e628cd14..d14880d977 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -677,6 +677,8 @@ namespace Language_en { PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Bottom Left"); PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Top Right"); PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Bottom Right"); + PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibration Completed"); + PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Calibration Failed"); #endif } diff --git a/Marlin/src/lcd/language/language_fr.h b/Marlin/src/lcd/language/language_fr.h index a944f0a0b8..90e57ab3fb 100644 --- a/Marlin/src/lcd/language/language_fr.h +++ b/Marlin/src/lcd/language/language_fr.h @@ -576,5 +576,7 @@ namespace Language_fr { PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Bas à Gauche"); PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Haut à Droite"); PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Bas à Droite"); + PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibration Terminée"); + PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Échec de l'étalonnage"); #endif } diff --git a/Marlin/src/lcd/language/language_pt.h b/Marlin/src/lcd/language/language_pt.h index 8a63c61749..3a002d657b 100644 --- a/Marlin/src/lcd/language/language_pt.h +++ b/Marlin/src/lcd/language/language_pt.h @@ -166,5 +166,7 @@ namespace Language_pt { PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Inferior Esquerdo"); PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Superior Direto"); PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Inferior Direto"); + PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibração Completa"); + PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Calibração Falhou"); #endif } diff --git a/Marlin/src/lcd/language/language_pt_br.h b/Marlin/src/lcd/language/language_pt_br.h index a52f2106ae..c210425ce8 100644 --- a/Marlin/src/lcd/language/language_pt_br.h +++ b/Marlin/src/lcd/language/language_pt_br.h @@ -484,5 +484,7 @@ namespace Language_pt_br { PROGMEM Language_Str MSG_BOTTOM_LEFT = _UxGT("Inferior Esquerdo"); PROGMEM Language_Str MSG_TOP_RIGHT = _UxGT("Superior Direto"); PROGMEM Language_Str MSG_BOTTOM_RIGHT = _UxGT("Inferior Direto"); + PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibração Completa"); + PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Calibração Falhou"); #endif } diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index 9382831659..04f175a6d5 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -623,7 +623,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const 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 ? "Calibration Completed" : "Calibration Failed"); + tft_string.set(calibration_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/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 179405af47..ac76e81c93 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -628,7 +628,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const 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 ? "Calibration Completed" : "Calibration Failed"); + tft_string.set(calibration_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);