Add Touch Calibration screen (#20049)

This commit is contained in:
Victor Oliveira 2020-11-15 19:39:58 -03:00 committed by GitHub
parent cab83ba840
commit ea371618da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 845 additions and 904 deletions

View file

@ -2358,10 +2358,10 @@
#define TOUCH_SCREEN_CALIBRATION #define TOUCH_SCREEN_CALIBRATION
//#define XPT2046_X_CALIBRATION 12316 //#define TOUCH_CALIBRATION_X 12316
//#define XPT2046_Y_CALIBRATION -8981 //#define TOUCH_CALIBRATION_Y -8981
//#define XPT2046_X_OFFSET -43 //#define TOUCH_OFFSET_X -43
//#define XPT2046_Y_OFFSET 257 //#define TOUCH_OFFSET_Y 257
#if ENABLED(TFT_COLOR_UI) #if ENABLED(TFT_COLOR_UI)
//#define SINGLE_TOUCH_NAVIGATION //#define SINGLE_TOUCH_NAVIGATION

View file

@ -22,7 +22,7 @@
#include "../../../inc/MarlinConfig.h" #include "../../../inc/MarlinConfig.h"
#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046 #if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS
#include "xpt2046.h" #include "xpt2046.h"
#include <SPI.h> #include <SPI.h>

View file

@ -147,15 +147,15 @@ SPIClass::SPIClass(uint32_t spi_num) {
_currentSetting->state = SPI_STATE_IDLE; _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 BOARD_NR_SPI >= 1
if (mosi == BOARD_SPI1_MOSI_PIN) SPIClass(1); if (mosi == BOARD_SPI1_MOSI_PIN) setModule(1);
#endif #endif
#if BOARD_NR_SPI >= 2 #if BOARD_NR_SPI >= 2
if (mosi == BOARD_SPI2_MOSI_PIN) SPIClass(2); if (mosi == BOARD_SPI2_MOSI_PIN) setModule(2);
#endif #endif
#if BOARD_NR_SPI >= 3 #if BOARD_NR_SPI >= 3
if (mosi == BOARD_SPI3_MOSI_PIN) SPIClass(3); if (mosi == BOARD_SPI3_MOSI_PIN) setModule(3);
#endif #endif
} }

View file

@ -22,7 +22,7 @@
#include "../../../inc/MarlinConfig.h" #include "../../../inc/MarlinConfig.h"
#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046 #if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS
#include "xpt2046.h" #include "xpt2046.h"
#include <SPI.h> #include <SPI.h>

View file

@ -60,7 +60,7 @@
#include "sd/cardreader.h" #include "sd/cardreader.h"
#include "lcd/marlinui.h" #include "lcd/marlinui.h"
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
#include "lcd/touch/touch_buttons.h" #include "lcd/touch/touch_buttons.h"
#endif #endif
@ -1109,7 +1109,7 @@ void setup() {
SETUP_RUN(ethernet.init()); SETUP_RUN(ethernet.init());
#endif #endif
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
SETUP_RUN(touch.init()); SETUP_RUN(touch.init());
#endif #endif
@ -1307,6 +1307,10 @@ void setup() {
SETUP_RUN(password.lock_machine()); // Will not proceed until correct password provided SETUP_RUN(password.lock_machine()); // Will not proceed until correct password provided
#endif #endif
#if BOTH(HAS_LCD_MENU, TOUCH_SCREEN_CALIBRATION) && EITHER(TFT_CLASSIC_UI, TFT_COLOR_UI)
ui.check_touch_calibration();
#endif
marlin_state = MF_RUNNING; marlin_state = MF_RUNNING;
SETUP_LOG("setup() completed."); SETUP_LOG("setup() completed.");

View file

@ -405,7 +405,7 @@ inline bool turn_on_heaters() {
inline bool prime_nozzle() { inline bool prime_nozzle() {
const feedRate_t fr_slow_e = planner.settings.max_feedrate_mm_s[E_AXIS] / 15.0f; 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) #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
float Total_Prime = 0.0; float Total_Prime = 0.0;
#endif #endif

View file

@ -25,14 +25,23 @@
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../gcode.h" #include "../gcode.h"
#include "../../lcd/menu/menu.h"
#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 * M995: Touch screen calibration for TFT display
*/ */
void GcodeSuite::M995() { void GcodeSuite::M995() {
ui.goto_screen(touch_screen_calibration); #if ENABLED(TFT_LVGL_UI)
lv_draw_touch_calibration_screen();
#else
ui.goto_screen(touch_screen_calibration);
#endif
} }

View file

@ -1073,8 +1073,24 @@
// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT #if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT
#undef TOUCH_SCREEN #undef TOUCH_SCREEN
#undef TOUCH_SCREEN_CALIBRATION
#if !HAS_TFT_LVGL_UI #if !HAS_TFT_LVGL_UI
#define HAS_TOUCH_XPT2046 1 #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
#endif #endif

View file

@ -364,7 +364,7 @@
// Touch Screen or "Touch Buttons" need XPT2046 pins // Touch Screen or "Touch Buttons" need XPT2046 pins
// but they use different components // 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 #define NEED_TOUCH_PINS 1
#endif #endif

View file

@ -3172,17 +3172,17 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
* Touch Buttons * Touch Buttons
*/ */
#if ENABLED(TOUCH_SCREEN) #if ENABLED(TOUCH_SCREEN)
#ifndef XPT2046_X_CALIBRATION #ifndef TOUCH_CALIBRATION_X
#error "XPT2046_X_CALIBRATION must be defined with TOUCH_SCREEN." #error "TOUCH_CALIBRATION_X must be defined with TOUCH_SCREEN."
#endif #endif
#ifndef XPT2046_Y_CALIBRATION #ifndef TOUCH_CALIBRATION_Y
#error "XPT2046_Y_CALIBRATION must be defined with TOUCH_SCREEN." #error "TOUCH_CALIBRATION_Y must be defined with TOUCH_SCREEN."
#endif #endif
#ifndef XPT2046_X_OFFSET #ifndef TOUCH_OFFSET_X
#error "XPT2046_X_OFFSET must be defined with TOUCH_SCREEN." #error "TOUCH_OFFSET_X must be defined with TOUCH_SCREEN."
#endif #endif
#ifndef XPT2046_Y_OFFSET #ifndef TOUCH_OFFSET_Y
#error "XPT2046_Y_OFFSET must be defined with TOUCH_SCREEN." #error "TOUCH_OFFSET_Y must be defined with TOUCH_SCREEN."
#endif #endif
#endif #endif

View file

@ -75,6 +75,11 @@ TFT_IO tftio;
#include "../touch/touch_buttons.h" #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 X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
#define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1) #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
@ -129,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); tftio.set_window(Xmin, Ymin, Xmax, Ymax);
} }
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
static const uint8_t buttonD[] = { static const uint8_t buttonD[] = {
B01111111,B11111111,B11111111,B11111110, B01111111,B11111111,B11111111,B11111110,
@ -302,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 // Used to fill RGB565 (16bits) background
inline void memset2(const void *ptr, uint16_t fill, size_t cnt) { inline void memset2(const void *ptr, uint16_t fill, size_t cnt) {
@ -313,6 +318,27 @@ inline void memset2(const void *ptr, uint16_t fill, size_t cnt) {
static bool preinit = true; static bool preinit = true;
static uint8_t page; 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;
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_BUTTONS
uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 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); u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
@ -328,6 +354,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); dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr);
tftio.Init(); tftio.Init();
tftio.InitTFT(); tftio.InitTFT();
TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
if (preinit) { if (preinit) {
preinit = false; preinit = false;
@ -343,28 +370,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++) for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++)
u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer); u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer);
#endif #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; return 0;
case U8G_DEV_MSG_STOP: preinit = true; break; case U8G_DEV_MSG_STOP: preinit = true; break;
case U8G_DEV_MSG_PAGE_FIRST: case U8G_DEV_MSG_PAGE_FIRST:
page = 0; page = 0;
TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev));
setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI); setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
break; break;
@ -456,4 +468,65 @@ 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); 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 = 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;
}
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 ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED);
defer_status_screen(false);
touch_calibration.calibration_end();
TERN_(HAS_TOUCH_BUTTONS, 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) #endif // HAS_MARLINUI_U8GLIB && (FSMC_CS_PIN || HAS_SPI_GRAPHICAL_TFT)

View file

@ -0,0 +1,120 @@
/**
* 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 <https://www.gnu.org/licenses/>.
*
*/
#include "../../../../inc/MarlinConfigPre.h"
#if BOTH(HAS_TFT_LVGL_UI, TOUCH_SCREEN_CALIBRATION)
#include "draw_ui.h"
#include "draw_touch_calibration.h"
#include <lv_conf.h>
#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 = 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;
}
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 ? 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);
}
// 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() {
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, "");
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 && TOUCH_SCREEN_CALIBRATION

View file

@ -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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#ifdef __cplusplus
extern "C" { /* C-declarations for C++ */
#endif
extern void lv_draw_touch_calibration_screen();
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

View file

@ -48,6 +48,10 @@
#include "../../../../feature/pause.h" #include "../../../../feature/pause.h"
#endif #endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "draw_touch_calibration.h"
#endif
CFG_ITMES gCfgItems; CFG_ITMES gCfgItems;
UI_CFG uiCfg; UI_CFG uiCfg;
DISP_STATE_STACK disp_state_stack; DISP_STATE_STACK disp_state_stack;
@ -1138,227 +1142,94 @@ void clear_cur_ui() {
last_disp_state = disp_state_stack._disp_state[disp_state_stack._disp_index]; last_disp_state = disp_state_stack._disp_state[disp_state_stack._disp_index];
switch (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: case PRINT_READY_UI: //Get_Temperature_Flg = 0;
//Get_Temperature_Flg = 0; lv_clear_ready_print(); break;
lv_clear_ready_print(); case PRINT_FILE_UI: lv_clear_print_file(); break;
break; case PRINTING_UI: lv_clear_printing(); break;
case PRINT_FILE_UI: case MOVE_MOTOR_UI: lv_clear_move_motor(); break;
lv_clear_print_file(); case OPERATE_UI: lv_clear_operation(); break;
break; case PAUSE_UI: /* Clear_pause(); */ break;
case PRINTING_UI: case EXTRUSION_UI: lv_clear_extrusion(); break;
lv_clear_printing(); case PRE_HEAT_UI: lv_clear_preHeat(); break;
break; case CHANGE_SPEED_UI: lv_clear_change_speed(); break;
case MOVE_MOTOR_UI: case FAN_UI: lv_clear_fan(); break;
lv_clear_move_motor(); case SET_UI: lv_clear_set(); break;
break; case ZERO_UI: lv_clear_home(); break;
case OPERATE_UI: case SPRAYER_UI: /* Clear_Sprayer(); */ break;
lv_clear_operation(); case MACHINE_UI: /* Clear_Machine(); */ break;
break; case LANGUAGE_UI: lv_clear_language(); break;
case PAUSE_UI: case ABOUT_UI: lv_clear_about(); break;
//Clear_pause(); case LOG_UI: /* Clear_Connect(); */ break;
break; case DISK_UI: /* Clear_Disk(); */ 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) #if ENABLED(USE_WIFI_FUNCTION)
case WIFI_UI: case WIFI_UI: lv_clear_wifi(); break;
lv_clear_wifi();
break;
#endif #endif
case MORE_UI: case MORE_UI: /* Clear_more(); */ break;
//Clear_more(); case FILETRANSFER_UI: /* Clear_fileTransfer(); */ break;
break; case DIALOG_UI: lv_clear_dialog(); break;
case FILETRANSFER_UI: case FILETRANSFERSTATE_UI: /* Clear_WifiFileTransferdialog(); */ break;
//Clear_fileTransfer(); case PRINT_MORE_UI: /* Clear_Printmore(); */ break;
break; case FILAMENTCHANGE_UI: lv_clear_filament_change(); break;
case DIALOG_UI: case LEVELING_UI: lv_clear_manualLevel(); break;
lv_clear_dialog(); case BIND_UI: /* Clear_Bind(); */ break;
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 #if HAS_BED_PROBE
case NOZZLE_PROBE_OFFSET_UI: case NOZZLE_PROBE_OFFSET_UI: lv_clear_auto_level_offset_settings(); break;
lv_clear_auto_level_offset_settings();
break;
#endif #endif
case TOOL_UI: case TOOL_UI: lv_clear_tool(); break;
lv_clear_tool(); case MESHLEVELING_UI: /* Clear_MeshLeveling(); */ break;
break; case HARDWARE_TEST_UI: /* Clear_Hardwaretest(); */ break;
case MESHLEVELING_UI:
//Clear_MeshLeveling();
break;
case HARDWARE_TEST_UI:
//Clear_Hardwaretest();
break;
#if ENABLED(USE_WIFI_FUNCTION) #if ENABLED(USE_WIFI_FUNCTION)
case WIFI_LIST_UI: case WIFI_LIST_UI: lv_clear_wifi_list(); break;
lv_clear_wifi_list();
break;
#endif #endif
case KEY_BOARD_UI: case KEY_BOARD_UI: lv_clear_keyboard(); break;
lv_clear_keyboard();
break;
#if ENABLED(USE_WIFI_FUNCTION) #if ENABLED(USE_WIFI_FUNCTION)
case WIFI_TIPS_UI: case WIFI_TIPS_UI: lv_clear_wifi_tips(); break;
lv_clear_wifi_tips();
break;
#endif #endif
case MACHINE_PARA_UI: case MACHINE_PARA_UI: lv_clear_machine_para(); break;
lv_clear_machine_para(); case MACHINE_SETTINGS_UI: lv_clear_machine_settings(); break;
break; case TEMPERATURE_SETTINGS_UI: /* Clear_TemperatureSettings(); */ break;
case MACHINE_SETTINGS_UI: case MOTOR_SETTINGS_UI: lv_clear_motor_settings(); break;
lv_clear_machine_settings(); case MACHINETYPE_UI: /* Clear_MachineType(); */ break;
break; case STROKE_UI: /* Clear_Stroke(); */ break;
case TEMPERATURE_SETTINGS_UI: case HOME_DIR_UI: /* Clear_HomeDir(); */ break;
//Clear_TemperatureSettings(); case ENDSTOP_TYPE_UI: /* Clear_EndstopType(); */ break;
break; case FILAMENT_SETTINGS_UI: lv_clear_filament_settings(); break;
case MOTOR_SETTINGS_UI: case LEVELING_SETTIGNS_UI: /* Clear_LevelingSettings(); */ break;
lv_clear_motor_settings(); case LEVELING_PARA_UI: lv_clear_level_settings(); break;
break; case DELTA_LEVELING_PARA_UI: /* Clear_DeltaLevelPara(); */ break;
case MACHINETYPE_UI: case MANUAL_LEVELING_POSIGION_UI: lv_clear_manual_level_pos_settings(); break;
//Clear_MachineType(); case MAXFEEDRATE_UI: lv_clear_max_feedrate_settings(); break;
break; case STEPS_UI: lv_clear_step_settings(); break;
case STROKE_UI: case ACCELERATION_UI: lv_clear_acceleration_settings(); break;
//Clear_Stroke(); case JERK_UI: TERN_(HAS_CLASSIC_JERK, lv_clear_jerk_settings()); break;
break; case MOTORDIR_UI: /* Clear_MotorDir(); */ break;
case HOME_DIR_UI: case HOMESPEED_UI: /* Clear_HomeSpeed(); */ break;
//Clear_HomeDir(); case NOZZLE_CONFIG_UI: /* Clear_NozzleConfig(); */ break;
break; case HOTBED_CONFIG_UI: /* Clear_HotbedConfig(); */ break;
case ENDSTOP_TYPE_UI: case ADVANCED_UI: lv_clear_advance_settings(); break;
//Clear_EndstopType(); case DOUBLE_Z_UI: /* Clear_DoubleZ(); */ break;
break; case ENABLE_INVERT_UI: /* Clear_EnableInvert(); */ break;
case FILAMENT_SETTINGS_UI: case NUMBER_KEY_UI: lv_clear_number_key(); break;
lv_clear_filament_settings(); case BABY_STEP_UI: lv_clear_baby_stepping(); break;
break; case PAUSE_POS_UI: lv_clear_pause_position(); 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;
#if HAS_TRINAMIC_CONFIG #if HAS_TRINAMIC_CONFIG
case TMC_CURRENT_UI: case TMC_CURRENT_UI: lv_clear_tmc_current_settings(); break;
lv_clear_tmc_current_settings();
break;
#endif #endif
case EEPROM_SETTINGS_UI: case EEPROM_SETTINGS_UI: lv_clear_eeprom_settings(); break;
lv_clear_eeprom_settings();
break;
#if HAS_STEALTHCHOP #if HAS_STEALTHCHOP
case TMC_MODE_UI: case TMC_MODE_UI: lv_clear_tmc_step_mode_settings(); break;
lv_clear_tmc_step_mode_settings();
break;
#endif #endif
#if ENABLED(USE_WIFI_FUNCTION) #if ENABLED(USE_WIFI_FUNCTION)
case WIFI_SETTINGS_UI: case WIFI_SETTINGS_UI: lv_clear_wifi_settings(); break;
lv_clear_wifi_settings();
break;
#endif #endif
#if USE_SENSORLESS #if USE_SENSORLESS
case HOMING_SENSITIVITY_UI: case HOMING_SENSITIVITY_UI: lv_clear_homing_sensitivity_settings(); break;
lv_clear_homing_sensitivity_settings();
break;
#endif #endif
#if HAS_ROTARY_ENCODER #if HAS_ROTARY_ENCODER
case ENCODER_SETTINGS_UI: case ENCODER_SETTINGS_UI: lv_clear_encoder_settings(); break;
lv_clear_encoder_settings(); #endif
break; #if ENABLED(TOUCH_SCREEN_CALIBRATION)
case TOUCH_CALIBRATION_UI: lv_clear_touch_calibration_screen(); break;
#endif #endif
default: break; default: break;
} }
@ -1370,227 +1241,98 @@ void draw_return_ui() {
disp_state_stack._disp_index--; disp_state_stack._disp_index--;
switch (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: case PRINT_READY_UI: lv_draw_ready_print(); break;
lv_draw_ready_print(); case PRINT_FILE_UI: lv_draw_print_file(); break;
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;
#if 1 case PRINTING_UI: if (gCfgItems.from_flash_pic)
case PAUSE_UI: flash_preview_begin = true;
//draw_pause(); else
break; default_preview_flg = true;
#endif lv_draw_printing();
break;
case EXTRUSION_UI: case MOVE_MOTOR_UI: lv_draw_move_motor(); break;
lv_draw_extrusion(); case OPERATE_UI: lv_draw_operation(); break;
break; case PAUSE_UI: /* draw_pause(); */ break;
case PRE_HEAT_UI: case EXTRUSION_UI: lv_draw_extrusion(); break;
lv_draw_preHeat(); case PRE_HEAT_UI: lv_draw_preHeat(); break;
break; case CHANGE_SPEED_UI: lv_draw_change_speed(); break;
case CHANGE_SPEED_UI: case FAN_UI: lv_draw_fan(); break;
lv_draw_change_speed(); case SET_UI: lv_draw_set(); break;
break; case ZERO_UI: lv_draw_home(); break;
case FAN_UI: case SPRAYER_UI: /* draw_Sprayer(); */ break;
lv_draw_fan(); case MACHINE_UI: /* draw_Machine(); */ break;
break; case LANGUAGE_UI: lv_draw_language(); break;
case SET_UI: case ABOUT_UI: lv_draw_about(); break;
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: case CALIBRATE_UI: /* draw_calibrate(); */ break;
//draw_calibrate(); case DISK_UI: /* draw_Disk(); */ break;
break;
case DISK_UI:
//draw_Disk();
break;
#if ENABLED(USE_WIFI_FUNCTION) #if ENABLED(USE_WIFI_FUNCTION)
case WIFI_UI: case WIFI_UI: lv_draw_wifi(); break;
lv_draw_wifi();
break;
#endif #endif
case MORE_UI: case MORE_UI: /* draw_More(); */ break;
//draw_More(); case PRINT_MORE_UI: /* draw_printmore(); */ break;
break; case FILAMENTCHANGE_UI: lv_draw_filament_change(); break;
case PRINT_MORE_UI: case LEVELING_UI: lv_draw_manualLevel(); break;
//draw_printmore(); case BIND_UI: /* draw_bind(); */ break;
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 #if HAS_BED_PROBE
case NOZZLE_PROBE_OFFSET_UI: case NOZZLE_PROBE_OFFSET_UI: lv_draw_auto_level_offset_settings(); break;
lv_draw_auto_level_offset_settings();
break;
#endif #endif
case TOOL_UI: case TOOL_UI: lv_draw_tool(); break;
lv_draw_tool(); case MESHLEVELING_UI: /* draw_meshleveling(); */ break;
break; case HARDWARE_TEST_UI: /* draw_Hardwaretest(); */ break;
case MESHLEVELING_UI: #if ENABLED(USE_WIFI_FUNCTION)
//draw_meshleveling(); case WIFI_LIST_UI: lv_draw_wifi_list(); break;
break; #endif
case HARDWARE_TEST_UI: case KEY_BOARD_UI: lv_draw_keyboard(); break;
//draw_Hardwaretest(); #if ENABLED(USE_WIFI_FUNCTION)
break; case WIFI_TIPS_UI: lv_draw_wifi_tips(); break;
case WIFI_LIST_UI: #endif
#if ENABLED(USE_WIFI_FUNCTION) case MACHINE_PARA_UI: lv_draw_machine_para(); break;
lv_draw_wifi_list(); case MACHINE_SETTINGS_UI: lv_draw_machine_settings(); break;
#endif case TEMPERATURE_SETTINGS_UI: /* draw_TemperatureSettings(); */ break;
break; case MOTOR_SETTINGS_UI: lv_draw_motor_settings(); break;
case KEY_BOARD_UI: case MACHINETYPE_UI: /* draw_MachineType(); */ break;
lv_draw_keyboard(); case STROKE_UI: /* draw_Stroke(); */ break;
break; case HOME_DIR_UI: /* draw_HomeDir(); */ break;
case WIFI_TIPS_UI: case ENDSTOP_TYPE_UI: /* draw_EndstopType(); */ break;
#if ENABLED(USE_WIFI_FUNCTION) case FILAMENT_SETTINGS_UI: lv_draw_filament_settings(); break;
lv_draw_wifi_tips(); case LEVELING_SETTIGNS_UI: /* draw_LevelingSettings(); */ break;
#endif case LEVELING_PARA_UI: lv_draw_level_settings(); break;
break; case DELTA_LEVELING_PARA_UI: /* draw_DeltaLevelPara(); */ break;
case MACHINE_PARA_UI: case MANUAL_LEVELING_POSIGION_UI: lv_draw_manual_level_pos_settings(); break;
lv_draw_machine_para(); case MAXFEEDRATE_UI: lv_draw_max_feedrate_settings(); break;
break; case STEPS_UI: lv_draw_step_settings(); break;
case MACHINE_SETTINGS_UI: case ACCELERATION_UI: lv_draw_acceleration_settings(); break;
lv_draw_machine_settings(); #if HAS_CLASSIC_JERK
break; case JERK_UI: lv_draw_jerk_settings(); break;
case TEMPERATURE_SETTINGS_UI: #endif
//draw_TemperatureSettings(); case MOTORDIR_UI: /* draw_MotorDir(); */ break;
break; case HOMESPEED_UI: /* draw_HomeSpeed(); */ break;
case MOTOR_SETTINGS_UI: case NOZZLE_CONFIG_UI: /* draw_NozzleConfig(); */ break;
lv_draw_motor_settings(); case HOTBED_CONFIG_UI: /* draw_HotbedConfig(); */ break;
break; case ADVANCED_UI: lv_draw_advance_settings(); break;
case MACHINETYPE_UI: case DOUBLE_Z_UI: /* draw_DoubleZ(); */ break;
//draw_MachineType(); case ENABLE_INVERT_UI: /* draw_EnableInvert(); */ break;
break; case NUMBER_KEY_UI: lv_draw_number_key(); break;
case STROKE_UI: case DIALOG_UI: /* draw_dialog(uiCfg.dialogType); */ break;
//draw_Stroke(); case BABY_STEP_UI: lv_draw_baby_stepping(); break;
break; case PAUSE_POS_UI: lv_draw_pause_position(); break;
case HOME_DIR_UI: #if HAS_TRINAMIC_CONFIG
//draw_HomeDir(); case TMC_CURRENT_UI: lv_draw_tmc_current_settings(); break;
break; #endif
case ENDSTOP_TYPE_UI: case EEPROM_SETTINGS_UI: lv_draw_eeprom_settings(); break;
//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;
#if HAS_STEALTHCHOP #if HAS_STEALTHCHOP
case TMC_MODE_UI: case TMC_MODE_UI: lv_draw_tmc_step_mode_settings(); break;
lv_draw_tmc_step_mode_settings();
break;
#endif #endif
#if ENABLED(USE_WIFI_FUNCTION) #if ENABLED(USE_WIFI_FUNCTION)
case WIFI_SETTINGS_UI: case WIFI_SETTINGS_UI: lv_draw_wifi_settings(); break;
lv_draw_wifi_settings();
break;
#endif #endif
#if USE_SENSORLESS #if USE_SENSORLESS
case HOMING_SENSITIVITY_UI: case HOMING_SENSITIVITY_UI: lv_draw_homing_sensitivity_settings(); break;
lv_draw_homing_sensitivity_settings();
break;
#endif #endif
#if HAS_ROTARY_ENCODER #if HAS_ROTARY_ENCODER
case ENCODER_SETTINGS_UI: case ENCODER_SETTINGS_UI: lv_draw_encoder_settings(); break;
lv_draw_encoder_settings();
break;
#endif #endif
default: break; default: break;
} }
@ -1879,15 +1621,11 @@ void LV_TASK_HANDLER() {
lv_task_handler(); lv_task_handler();
if (mks_test_flag == 0x1E) mks_hardware_test(); if (mks_test_flag == 0x1E) mks_hardware_test();
#if HAS_GCODE_PREVIEW TERN_(HAS_GCODE_PREVIEW, disp_pre_gcode(2, 36));
disp_pre_gcode(2, 36);
#endif
GUI_RefreshPage(); GUI_RefreshPage();
#if ENABLED(USE_WIFI_FUNCTION) TERN_(USE_WIFI_FUNCTION, get_wifi_commands());
get_wifi_commands();
#endif
//sd_detection(); //sd_detection();

View file

@ -313,7 +313,8 @@ typedef enum {
EEPROM_SETTINGS_UI, EEPROM_SETTINGS_UI,
WIFI_SETTINGS_UI, WIFI_SETTINGS_UI,
HOMING_SENSITIVITY_UI, HOMING_SENSITIVITY_UI,
ENCODER_SETTINGS_UI ENCODER_SETTINGS_UI,
TOUCH_CALIBRATION_UI
} DISP_STATE; } DISP_STATE;
typedef struct { typedef struct {

View file

@ -51,6 +51,11 @@ XPT2046 touch;
#include "../../../../feature/powerloss.h" #include "../../../../feature/powerloss.h"
#endif #endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../../../tft_io/touch_calibration.h"
#include "draw_touch_calibration.h"
#endif
#include <SPI.h> #include <SPI.h>
#ifndef TFT_WIDTH #ifndef TFT_WIDTH
@ -211,7 +216,14 @@ void tft_lvgl_init() {
} }
#endif #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) if (mks_test_flag == 0x1E)
mks_gpio_test(); mks_gpio_test();
@ -240,17 +252,22 @@ unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) {
static bool get_point(int16_t *x, int16_t *y) { static bool get_point(int16_t *x, int16_t *y) {
bool is_touched = touch.getRawPoint(x, y); bool is_touched = touch.getRawPoint(x, y);
if (is_touched) { if (!is_touched) return false;
*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;
}
#if (TFT_ROTATION & TFT_ROTATE_180) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
*x = int16_t((TFT_WIDTH) - (int)(*x)); const calibrationState state = touch_calibration.get_calibration_state();
*y = int16_t((TFT_HEIGHT) - (int)(*y)); 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;
#endif #endif
return is_touched; return true;
} }
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {

View file

@ -671,6 +671,15 @@ namespace Language_en {
PROGMEM Language_Str MSG_PROBE_WIZARD = _UxGT("Z Probe Wizard"); PROGMEM Language_Str MSG_PROBE_WIZARD = _UxGT("Z Probe Wizard");
PROGMEM Language_Str MSG_SOUND = _UxGT("Sound"); 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");
PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibration Completed");
PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Calibration Failed");
#endif
} }
#if FAN_COUNT == 1 #if FAN_COUNT == 1

View file

@ -570,4 +570,13 @@ namespace Language_fr {
PROGMEM Language_Str MSG_SERVICE_IN = _UxGT(" dans:"); PROGMEM Language_Str MSG_SERVICE_IN = _UxGT(" dans:");
PROGMEM Language_Str MSG_BACKLASH_CORRECTION = _UxGT("Correction"); PROGMEM Language_Str MSG_BACKLASH_CORRECTION = _UxGT("Correction");
PROGMEM Language_Str MSG_BACKLASH_SMOOTHING = _UxGT("Lissage"); 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");
PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibration Terminée");
PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Échec de l'étalonnage");
#endif
} }

View file

@ -160,4 +160,13 @@ namespace Language_pt {
PROGMEM Language_Str MSG_LCD_ENDSTOPS = _UxGT("Fim de curso"); PROGMEM Language_Str MSG_LCD_ENDSTOPS = _UxGT("Fim de curso");
PROGMEM Language_Str MSG_KILL_EXPECTED_PRINTER = _UxGT("Impressora Incorreta"); 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");
PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibração Completa");
PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Calibração Falhou");
#endif
} }

View file

@ -478,4 +478,13 @@ 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_CONT_PURGE = _UxGT(MSG_1_LINE("Clique p. finalizar"));
PROGMEM Language_Str MSG_FILAMENT_CHANGE_RESUME = _UxGT(MSG_1_LINE("Continuando...")); PROGMEM Language_Str MSG_FILAMENT_CHANGE_RESUME = _UxGT(MSG_1_LINE("Continuando..."));
#endif #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");
PROGMEM Language_Str MSG_CALIBRATION_COMPLETED = _UxGT("Calibração Completa");
PROGMEM Language_Str MSG_CALIBRATION_FAILED = _UxGT("Calibração Falhou");
#endif
} }

View file

@ -158,7 +158,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#if HAS_SLOW_BUTTONS #if HAS_SLOW_BUTTONS
volatile uint8_t MarlinUI::slow_buttons; volatile uint8_t MarlinUI::slow_buttons;
#endif #endif
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
#include "touch/touch_buttons.h" #include "touch/touch_buttons.h"
bool MarlinUI::on_edit_screen = false; bool MarlinUI::on_edit_screen = false;
#endif #endif
@ -241,7 +241,7 @@ millis_t MarlinUI::next_button_update_ms; // = 0
int8_t MarlinUI::encoderDirection = ENCODERBASE; int8_t MarlinUI::encoderDirection = ENCODERBASE;
#endif #endif
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
uint8_t MarlinUI::touch_buttons; uint8_t MarlinUI::touch_buttons;
uint8_t MarlinUI::repeat_delay; uint8_t MarlinUI::repeat_delay;
#endif #endif
@ -862,7 +862,7 @@ void MarlinUI::update() {
quick_feedback(); // - Always make a click sound quick_feedback(); // - Always make a click sound
}; };
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
if (touch_buttons) { if (touch_buttons) {
RESET_STATUS_TIMEOUT(); RESET_STATUS_TIMEOUT();
if (touch_buttons & (EN_A | EN_B)) { // Menu arrows, in priority if (touch_buttons & (EN_A | EN_B)) { // Menu arrows, in priority
@ -883,7 +883,7 @@ void MarlinUI::update() {
} }
else // keep wait_for_unclick value else // keep wait_for_unclick value
#endif // HAS_TOUCH_XPT2046 #endif // HAS_TOUCH_BUTTONS
{ {
// Integrated LCD click handling via button_pressed // Integrated LCD click handling via button_pressed
@ -905,7 +905,7 @@ void MarlinUI::update() {
next_lcd_update_ms = ms + LCD_UPDATE_INTERVAL; 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; if (on_status_screen()) next_lcd_update_ms += (LCD_UPDATE_INTERVAL) * 2;
@ -1250,7 +1250,7 @@ void MarlinUI::update() {
#if HAS_SLOW_BUTTONS #if HAS_SLOW_BUTTONS
| slow_buttons | slow_buttons
#endif #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)) | (touch_buttons & TERN(HAS_ENCODER_WHEEL, ~(EN_A | EN_B), 0xFF))
#endif #endif
); );
@ -1561,7 +1561,7 @@ void MarlinUI::update() {
#endif #endif
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
// //
// Screen Click // Screen Click

View file

@ -31,6 +31,10 @@
#include "../sd/cardreader.h" #include "../sd/cardreader.h"
#endif #endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "tft_io/touch_calibration.h"
#endif
#if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY) #if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY)
#define HAS_ENCODER_ACTION 1 #define HAS_ENCODER_ACTION 1
#endif #endif
@ -74,7 +78,7 @@
uint8_t get_ADC_keyValue(); uint8_t get_ADC_keyValue();
#endif #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 #if HAS_LCD_MENU
@ -146,7 +150,7 @@
#define BUTTON_PRESSED(BN) !READ(BTN_## BN) #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 BLEN_C 2
#define EN_C _BV(BLEN_C) #define EN_C _BV(BLEN_C)
#endif #endif
@ -212,7 +216,7 @@
#endif #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 BLEN_D 3
#define EN_D _BV(BLEN_D) #define EN_D _BV(BLEN_D)
#define LCD_BACK_CLICKED() (buttons & EN_D) #define LCD_BACK_CLICKED() (buttons & EN_D)
@ -311,6 +315,12 @@ public:
// LCD implementations // LCD implementations
static void clear_lcd(); static void clear_lcd();
#if BOTH(HAS_LCD_MENU, TOUCH_SCREEN_CALIBRATION)
static void check_touch_calibration() {
if (touch_calibration.need_calibration()) currentScreen = touch_calibration_screen;
}
#endif
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
static void media_changed(const uint8_t old_stat, const uint8_t stat); static void media_changed(const uint8_t old_stat, const uint8_t stat);
#endif #endif
@ -452,7 +462,7 @@ public:
static void draw_hotend_status(const uint8_t row, const uint8_t extruder); static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
#endif #endif
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
static bool on_edit_screen; 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); static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y);
#endif #endif
@ -512,7 +522,7 @@ public:
static millis_t return_to_status_ms; static millis_t return_to_status_ms;
#endif #endif
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
static uint8_t touch_buttons; static uint8_t touch_buttons;
static uint8_t repeat_delay; static uint8_t repeat_delay;
#endif #endif
@ -682,7 +692,7 @@ public:
#endif #endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
static void touch_calibration(); static void touch_calibration_screen();
#endif #endif
#if HAS_GRAPHICAL_TFT #if HAS_GRAPHICAL_TFT

View file

@ -82,7 +82,7 @@ void MarlinUI::save_previous_screen() {
void MarlinUI::_goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back/*=false*/)) { 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); 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) { if (screen_history_depth > 0) {
menuPosition &sh = screen_history[--screen_history_depth]; menuPosition &sh = screen_history[--screen_history_depth];
goto_screen(sh.menu_function, 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) * MenuItem_int3::draw(encoderLine == _thisItemNr, _lcdLineNr, plabel, &feedrate_percentage, 10, 999)
*/ */
void MenuEditItemBase::edit_screen(strfunc_t strfunc, loadfunc_t loadfunc) { 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) < 0) ui.encoderPosition = 0;
if (int32_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue; if (int32_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue;
if (ui.should_draw()) if (ui.should_draw())
@ -145,7 +145,7 @@ void MenuEditItemBase::goto_edit_screen(
const screenFunc_t cb, // Callback after edit const screenFunc_t cb, // Callback after edit
const bool le // Flag to call cb() during editing 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.screen_changed = true;
ui.save_previous_screen(); ui.save_previous_screen();
ui.refresh(); 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*/) { 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) { 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()); TERN_(LCD_SET_PROGRESS_MANUALLY, progress_reset());

View file

@ -37,8 +37,10 @@
#endif #endif
#if HAS_GRAPHICAL_TFT #if HAS_GRAPHICAL_TFT
#include "../tft/touch.h"
#include "../tft/tft.h" #include "../tft/tft.h"
#if ENABLED(TOUCH_SCREEN)
#include "../tft/touch.h"
#endif
#endif #endif
#if EITHER(PROBE_MANUALLY, MESH_BED_LEVELING) #if EITHER(PROBE_MANUALLY, MESH_BED_LEVELING)

View file

@ -29,7 +29,7 @@
void touch_screen_calibration() { void touch_screen_calibration() {
ui.touch_calibration(); ui.touch_calibration_screen();
} }

View file

@ -48,17 +48,12 @@ millis_t Touch::last_touch_ms = 0,
Touch::repeat_delay, Touch::repeat_delay,
Touch::touch_time; Touch::touch_time;
TouchControlType Touch::touch_control_type = NONE; 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 #if HAS_RESUME_CONTINUE
extern bool wait_for_user; extern bool wait_for_user;
#endif #endif
void Touch::init() { void Touch::init() {
calibration_reset(); TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
reset(); reset();
io.Init(); io.Init();
enable(); enable();
@ -155,52 +150,7 @@ void Touch::touch(touch_control_t *control) {
switch (control->type) { switch (control->type) {
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
case CALIBRATE: case CALIBRATE:
ui.refresh(); if (touch_calibration.handleTouch(x, y)) 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;
}
break; break;
#endif // TOUCH_SCREEN_CALIBRATION #endif // TOUCH_SCREEN_CALIBRATION
@ -298,12 +248,18 @@ void Touch::hold(touch_control_t *control, millis_t delay) {
} }
bool Touch::get_point(int16_t *x, int16_t *y) { 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)); #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 && calibration.orientation != TOUCH_ORIENTATION_NONE) { if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) {
*x = int16_t((int32_t(*x) * calibration.x) >> 16) + calibration.offset_x; *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
*y = int16_t((int32_t(*y) * calibration.y) >> 16) + calibration.offset_y; *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) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
*y = uint16_t((uint32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
#endif
return is_touched; return is_touched;
} }
Touch touch; Touch touch;

View file

@ -23,42 +23,16 @@
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#if ENABLED(TOUCH_SCREEN)
#include "tft_color.h" #include "tft_color.h"
#include "tft_image.h" #include "tft_image.h"
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../tft_io/touch_calibration.h"
#endif
#include HAL_PATH(../../HAL, tft/xpt2046.h) #include HAL_PATH(../../HAL, tft/xpt2046.h)
#define TOUCH_DRIVER XPT2046 #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 // Menu Navigation
extern int8_t encoderTopLine, encoderLine, screen_items; extern int8_t encoderTopLine, encoderLine, screen_items;
@ -101,31 +75,6 @@ typedef struct __attribute__((__packed__)) {
intptr_t data; intptr_t data;
} touch_control_t; } 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 MAX_CONTROLS 16
#define MINIMUM_HOLD_TIME 15 #define MINIMUM_HOLD_TIME 15
#define TOUCH_REPEAT_DELAY 75 #define TOUCH_REPEAT_DELAY 75
@ -150,15 +99,6 @@ class Touch {
static void touch(touch_control_t *control); static void touch(touch_control_t *control);
static void hold(touch_control_t *control, millis_t delay = 0); 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: public:
static void init(); static void init();
static void reset() { controls_count = 0; touch_time = 0; current_control = NULL; } static void reset() { controls_count = 0; touch_time = 0; current_control = NULL; }
@ -175,17 +115,6 @@ class Touch {
static void enable() { enabled = true; } 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 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; extern Touch touch;
#endif // TOUCH_SCREEN

View file

@ -584,33 +584,37 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
#endif // AUTO_BED_LEVELING_UBL #endif // AUTO_BED_LEVELING_UBL
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
void MarlinUI::touch_calibration() { void MarlinUI::touch_calibration_screen() {
static uint16_t x, y; uint16_t x, y;
calibrationState calibration_stage = touch.get_calibration_state(); calibrationState calibration_stage = touch_calibration.get_calibration_state();
if (calibration_stage == CALIBRATION_NONE) { if (calibration_stage == CALIBRATION_NONE) {
defer_status_screen(true); defer_status_screen(true);
clear_lcd(); clear_lcd();
calibration_stage = touch.calibration_start(); calibration_stage = touch_calibration.calibration_start();
} }
else { 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.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
} }
x = 20; y = 20;
touch.clear(); touch.clear();
if (calibration_stage < CALIBRATION_SUCCESS) { if (calibration_stage < CALIBRATION_SUCCESS) {
switch (calibration_stage) { switch (calibration_stage) {
case CALIBRATION_POINT_1: tft_string.set("Top Left"); break; case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
case CALIBRATION_POINT_2: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
case CALIBRATION_POINT_3: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
case CALIBRATION_POINT_4: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
default: 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.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
@ -619,9 +623,9 @@ 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)); touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
} }
else { 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); defer_status_screen(false);
touch.calibration_end(); touch_calibration.calibration_end();
touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
} }

View file

@ -589,33 +589,37 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
#endif // AUTO_BED_LEVELING_UBL #endif // AUTO_BED_LEVELING_UBL
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
void MarlinUI::touch_calibration() { void MarlinUI::touch_calibration_screen() {
static uint16_t x, y; uint16_t x, y;
calibrationState calibration_stage = touch.get_calibration_state(); calibrationState calibration_stage = touch_calibration.get_calibration_state();
if (calibration_stage == CALIBRATION_NONE) { if (calibration_stage == CALIBRATION_NONE) {
defer_status_screen(true); defer_status_screen(true);
clear_lcd(); clear_lcd();
calibration_stage = touch.calibration_start(); calibration_stage = touch_calibration.calibration_start();
} }
else { 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.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
} }
x = 20; y = 20;
touch.clear(); touch.clear();
if (calibration_stage < CALIBRATION_SUCCESS) { if (calibration_stage < CALIBRATION_SUCCESS) {
switch (calibration_stage) { switch (calibration_stage) {
case CALIBRATION_POINT_1: tft_string.set("Top Left"); break; case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
case CALIBRATION_POINT_2: y = TFT_HEIGHT - 21; tft_string.set("Bottom Left"); break; case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
case CALIBRATION_POINT_3: x = TFT_WIDTH - 21; tft_string.set("Top Right"); break; case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
case CALIBRATION_POINT_4: x = TFT_WIDTH - 21; y = TFT_HEIGHT - 21; tft_string.set("Bottom Right"); break; case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
default: 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.canvas(x - 15, y - 15, 31, 31);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
@ -624,9 +628,9 @@ 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)); touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
} }
else { 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); defer_status_screen(false);
touch.calibration_end(); touch_calibration.calibration_end();
touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
} }

View file

@ -0,0 +1,81 @@
/**
* 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 <https://www.gnu.org/licenses/>.
*
*/
#include "../../inc/MarlinConfig.h"
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "touch_calibration.h"
TouchCalibration touch_calibration;
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();
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: validate_calibration(); break;
default: break;
}
return true;
}
#endif // TOUCH_SCREEN_CALIBRATION

View file

@ -0,0 +1,93 @@
/**
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "../../inc/MarlinConfigPre.h"
#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
#ifndef TOUCH_ORIENTATION
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif
typedef struct __attribute__((__packed__)) {
int32_t x, y;
int16_t offset_x, offset_y;
uint8_t orientation;
} touch_calibration_t;
typedef struct __attribute__((__packed__)) {
uint16_t x, y;
int16_t raw_x, 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 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 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_state = CALIBRATION_TOP_LEFT;
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; }
static calibrationState get_calibration_state() { return calibration_state; }
static bool handleTouch(uint16_t x, uint16_t y);
};
extern TouchCalibration touch_calibration;

View file

@ -19,7 +19,7 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_BUTTONS
#include "touch_buttons.h" #include "touch_buttons.h"
#include "../scaled_tft.h" #include "../scaled_tft.h"
@ -27,7 +27,11 @@
#include HAL_PATH(../../HAL, tft/xpt2046.h) #include HAL_PATH(../../HAL, tft/xpt2046.h)
XPT2046 touchIO; XPT2046 touchIO;
#include "../../lcd/marlinui.h" // For EN_C bit mask #if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../tft_io/touch_calibration.h"
#endif
#include "../marlinui.h" // For EN_C bit mask
#define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X #define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X
#define DOGM_AREA_TOP TFT_PIXEL_OFFSET_Y #define DOGM_AREA_TOP TFT_PIXEL_OFFSET_Y
@ -47,14 +51,20 @@ uint8_t TouchButtons::read_buttons() {
if (!touchIO.getRawPoint(&x, &y)) return 0; if (!touchIO.getRawPoint(&x, &y)) return 0;
x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; #if ENABLED(TOUCH_SCREEN_CALIBRATION)
y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; const calibrationState state = touch_calibration.get_calibration_state();
if (state >= CALIBRATION_TOP_LEFT && state <= CALIBRATION_BOTTOM_RIGHT) {
#if (TFT_ROTATION & TFT_ROTATE_180) if (touch_calibration.handleTouch(x, y)) ui.refresh();
x = TFT_WIDTH - x; return 0;
y = TFT_HEIGHT - y; }
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) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
y = uint16_t((uint32_t(y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
#endif #endif
// Touch within the button area simulates an encoder button // Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT) if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D
@ -77,4 +87,4 @@ uint8_t TouchButtons::read_buttons() {
return 0; return 0;
} }
#endif // HAS_TOUCH_XPT2046 #endif // HAS_TOUCH_BUTTONS

View file

@ -146,7 +146,7 @@
#endif #endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../lcd/tft/touch.h" #include "../lcd/tft_io/touch_calibration.h"
#endif #endif
#if HAS_ETHERNET #if HAS_ETHERNET
@ -443,7 +443,7 @@ typedef struct SettingsDataStruct {
// TOUCH_SCREEN_CALIBRATION // TOUCH_SCREEN_CALIBRATION
// //
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
touch_calibration_t touch_calibration; touch_calibration_t touch_calibration_data;
#endif #endif
// Ethernet settings // Ethernet settings
@ -1410,7 +1410,7 @@ void MarlinSettings::postprocess() {
// TOUCH_SCREEN_CALIBRATION // TOUCH_SCREEN_CALIBRATION
// //
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
EEPROM_WRITE(touch.calibration); EEPROM_WRITE(touch_calibration.calibration);
#endif #endif
// //
@ -2293,8 +2293,8 @@ void MarlinSettings::postprocess() {
// TOUCH_SCREEN_CALIBRATION // TOUCH_SCREEN_CALIBRATION
// //
#if ENABLED(TOUCH_SCREEN_CALIBRATION) #if ENABLED(TOUCH_SCREEN_CALIBRATION)
_FIELD_TEST(touch.calibration); _FIELD_TEST(touch_calibration_data);
EEPROM_READ(touch.calibration); EEPROM_READ(touch_calibration.calibration);
#endif #endif
// //
@ -2626,7 +2626,7 @@ void MarlinSettings::reset() {
// //
// TOUCH_SCREEN_CALIBRATION // TOUCH_SCREEN_CALIBRATION
// //
TERN_(TOUCH_SCREEN_CALIBRATION, touch.calibration_reset()); TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
// //
// Buzzer enable/disable // Buzzer enable/disable

View file

@ -353,36 +353,7 @@
#define LCD_PINS_ENABLE -1 #define LCD_PINS_ENABLE -1
#define LCD_PINS_RS -1 #define LCD_PINS_RS -1
// XPT2046 Touch Screen calibration #define TFT_BUFFER_SIZE 2400
#if ENABLED(TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -11245
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 8629
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 685
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -285
#endif
#elif ENABLED(TFT_480x320_SPI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17232
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 11196
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 1047
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -358
#endif
#define TFT_BUFFER_SIZE 2400
#endif
#elif IS_TFTGLCD_PANEL #elif IS_TFTGLCD_PANEL

View file

@ -268,36 +268,7 @@
#define LCD_PINS_ENABLE -1 #define LCD_PINS_ENABLE -1
#define LCD_PINS_RS -1 #define LCD_PINS_RS -1
// XPT2046 Touch Screen calibration #define TFT_BUFFER_SIZE 2400
#if ENABLED(TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -11386
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 8684
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 689
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -273
#endif
#elif ENABLED(TFT_COLOR_UI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -16741
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 11258
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 1024
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -367
#endif
#define TFT_BUFFER_SIZE 2400
#endif
#define BTN_EN1 P3_25 #define BTN_EN1 P3_25
#define BTN_EN2 P3_26 #define BTN_EN2 P3_26

View file

@ -318,36 +318,7 @@
#define LCD_PINS_ENABLE -1 #define LCD_PINS_ENABLE -1
#define LCD_PINS_RS -1 #define LCD_PINS_RS -1
// XPT2046 Touch Screen calibration #define TFT_BUFFER_SIZE 2400
#if ENABLED(TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -11386
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 8684
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 689
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -273
#endif
#elif ENABLED(TFT_COLOR_UI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17089
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 11424
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 1044
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -365
#endif
#define TFT_BUFFER_SIZE 2400
#endif
#else // !MKS_12864OLED_SSD1306 #else // !MKS_12864OLED_SSD1306

View file

@ -158,17 +158,17 @@
// XPT2046 Touch Screen calibration // XPT2046 Touch Screen calibration
#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) #if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION #ifndef TOUCH_CALIBRATION_X
#define XPT2046_X_CALIBRATION -17181 #define TOUCH_CALIBRATION_X -17181
#endif #endif
#ifndef XPT2046_Y_CALIBRATION #ifndef TOUCH_CALIBRATION_Y
#define XPT2046_Y_CALIBRATION 11434 #define TOUCH_CALIBRATION_Y 11434
#endif #endif
#ifndef XPT2046_X_OFFSET #ifndef TOUCH_OFFSET_X
#define XPT2046_X_OFFSET 501 #define TOUCH_OFFSET_X 501
#endif #endif
#ifndef XPT2046_Y_OFFSET #ifndef TOUCH_OFFSET_Y
#define XPT2046_Y_OFFSET -9 #define TOUCH_OFFSET_Y -9
#endif #endif
#endif #endif

View file

@ -173,17 +173,17 @@
// XPT2046 Touch Screen calibration // XPT2046 Touch Screen calibration
#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) #if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION #ifndef TOUCH_CALIBRATION_X
#define XPT2046_X_CALIBRATION -17181 #define TOUCH_CALIBRATION_X -17181
#endif #endif
#ifndef XPT2046_Y_CALIBRATION #ifndef TOUCH_CALIBRATION_Y
#define XPT2046_Y_CALIBRATION 11434 #define TOUCH_CALIBRATION_Y 11434
#endif #endif
#ifndef XPT2046_X_OFFSET #ifndef TOUCH_OFFSET_X
#define XPT2046_X_OFFSET 501 #define TOUCH_OFFSET_X 501
#endif #endif
#ifndef XPT2046_Y_OFFSET #ifndef TOUCH_OFFSET_Y
#define XPT2046_Y_OFFSET -9 #define TOUCH_OFFSET_Y -9
#endif #endif
#endif #endif

View file

@ -286,22 +286,22 @@
// MKS Robin TFT v2.0 with ILI9341 // MKS Robin TFT v2.0 with ILI9341
// Read display identification information (0xD3 on ILI9341) // Read display identification information (0xD3 on ILI9341)
//#define XPT2046_X_CALIBRATION 12013 //#define TOUCH_CALIBRATION_X 12013
//#define XPT2046_Y_CALIBRATION -8711 //#define TOUCH_CALIBRATION_Y -8711
//#define XPT2046_X_OFFSET -32 //#define TOUCH_OFFSET_X -32
//#define XPT2046_Y_OFFSET 256 //#define TOUCH_OFFSET_Y 256
// MKS Robin TFT v1.1 with ILI9328 // MKS Robin TFT v1.1 with ILI9328
//#define XPT2046_X_CALIBRATION -11792 //#define TOUCH_CALIBRATION_X -11792
//#define XPT2046_Y_CALIBRATION 8947 //#define TOUCH_CALIBRATION_Y 8947
//#define XPT2046_X_OFFSET 342 //#define TOUCH_OFFSET_X 342
//#define XPT2046_Y_OFFSET -19 //#define TOUCH_OFFSET_Y -19
// MKS Robin TFT v1.1 with R61505 // MKS Robin TFT v1.1 with R61505
//#define XPT2046_X_CALIBRATION 12489 //#define TOUCH_CALIBRATION_X 12489
//#define XPT2046_Y_CALIBRATION 9210 //#define TOUCH_CALIBRATION_Y 9210
//#define XPT2046_X_OFFSET -52 //#define TOUCH_OFFSET_X -52
//#define XPT2046_Y_OFFSET -17 //#define TOUCH_OFFSET_Y -17
// QQS-Pro uses MKS Robin TFT v2.0 // QQS-Pro uses MKS Robin TFT v2.0
@ -324,42 +324,6 @@
#define TOUCH_BUTTONS_HW_SPI_DEVICE 2 #define TOUCH_BUTTONS_HW_SPI_DEVICE 2
#endif #endif
// XPT2046 Touch Screen calibration
#if EITHER(TFT_LVGL_UI_FSMC, TFT_COLOR_UI)
#define TFT_BUFFER_SIZE 14400
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION 12218
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION -8814
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET -35
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET 256
#endif
#elif ENABLED(TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION 12149
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION -8746
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET -35
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET 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 #if NEED_TOUCH_PINS
#define TOUCH_CS_PIN PC2 // SPI2_NSS #define TOUCH_CS_PIN PC2 // SPI2_NSS
#define TOUCH_SCK_PIN PB13 // SPI2_SCK #define TOUCH_SCK_PIN PB13 // SPI2_SCK

View file

@ -282,35 +282,6 @@
#define TFT_BUFFER_SIZE 14400 #define TFT_BUFFER_SIZE 14400
#endif #endif
// XPT2046 Touch Screen calibration
#if EITHER(HAS_TFT_LVGL_UI, TFT_480x320_SPI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17253
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 11579
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 514
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -24
#endif
#elif HAS_SPI_GRAPHICAL_TFT
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -11386
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 8684
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 339
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -18
#endif
#endif
#if HAS_WIRED_LCD && !HAS_SPI_TFT #if HAS_WIRED_LCD && !HAS_SPI_TFT
// NON TFT Displays // NON TFT Displays

View file

@ -171,17 +171,17 @@
#endif #endif
#if ENABLED(TOUCH_SCREEN) #if ENABLED(TOUCH_SCREEN)
#ifndef XPT2046_X_CALIBRATION #ifndef TOUCH_CALIBRATION_X
#define XPT2046_X_CALIBRATION 12033 #define TOUCH_CALIBRATION_X 12033
#endif #endif
#ifndef XPT2046_Y_CALIBRATION #ifndef TOUCH_CALIBRATION_Y
#define XPT2046_Y_CALIBRATION -9047 #define TOUCH_CALIBRATION_Y -9047
#endif #endif
#ifndef XPT2046_X_OFFSET #ifndef TOUCH_OFFSET_X
#define XPT2046_X_OFFSET -30 #define TOUCH_OFFSET_X -30
#endif #endif
#ifndef XPT2046_Y_OFFSET #ifndef TOUCH_OFFSET_Y
#define XPT2046_Y_OFFSET 254 #define TOUCH_OFFSET_Y 254
#endif #endif
#endif #endif

View file

@ -202,35 +202,6 @@
#define TFT_BUFFER_SIZE 14400 #define TFT_BUFFER_SIZE 14400
#endif #endif
// 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
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION -12234
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET -45
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET 349
#endif
#elif EITHER(TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_320x240)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -12246
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 9453
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 360
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -22
#endif
#endif
#define HAS_SPI_FLASH 1 #define HAS_SPI_FLASH 1
#if HAS_SPI_FLASH #if HAS_SPI_FLASH
#define SPI_FLASH_SIZE 0x1000000 // 16MB #define SPI_FLASH_SIZE 0x1000000 // 16MB

View file

@ -285,22 +285,6 @@
#define TFT_BUFFER_SIZE 14400 #define TFT_BUFFER_SIZE 14400
#endif #endif
// XPT2046 Touch Screen calibration
#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17253
#endif
#ifndef XPT2046_Y_CALIBRATION
#define XPT2046_Y_CALIBRATION 11579
#endif
#ifndef XPT2046_X_OFFSET
#define XPT2046_X_OFFSET 514
#endif
#ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -24
#endif
#endif
#if HAS_WIRED_LCD && !HAS_SPI_TFT #if HAS_WIRED_LCD && !HAS_SPI_TFT
// NON TFT Displays // NON TFT Displays

View file

@ -141,17 +141,17 @@
// XPT2046 Touch Screen calibration // XPT2046 Touch Screen calibration
#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) #if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI)
#ifndef XPT2046_X_CALIBRATION #ifndef TOUCH_CALIBRATION_X
#define XPT2046_X_CALIBRATION -17181 #define TOUCH_CALIBRATION_X -17181
#endif #endif
#ifndef XPT2046_Y_CALIBRATION #ifndef TOUCH_CALIBRATION_Y
#define XPT2046_Y_CALIBRATION 11434 #define TOUCH_CALIBRATION_Y 11434
#endif #endif
#ifndef XPT2046_X_OFFSET #ifndef TOUCH_OFFSET_X
#define XPT2046_X_OFFSET 501 #define TOUCH_OFFSET_X 501
#endif #endif
#ifndef XPT2046_Y_OFFSET #ifndef TOUCH_OFFSET_Y
#define XPT2046_Y_OFFSET -9 #define TOUCH_OFFSET_Y -9
#endif #endif
#endif #endif

View file

@ -236,7 +236,7 @@ HAS_SPI_TFT = src_filter=+<src/HAL/STM32/tft/tft_spi.cpp> +<src/HAL/
HAS_GRAPHICAL_TFT = src_filter=+<src/lcd/tft> HAS_GRAPHICAL_TFT = src_filter=+<src/lcd/tft>
DWIN_CREALITY_LCD = src_filter=+<src/lcd/dwin> DWIN_CREALITY_LCD = src_filter=+<src/lcd/dwin>
IS_TFTGLCD_PANEL = src_filter=+<src/lcd/TFTGLCD> IS_TFTGLCD_PANEL = src_filter=+<src/lcd/TFTGLCD>
HAS_TOUCH_XPT2046 = src_filter=+<src/lcd/touch/touch_buttons.cpp> HAS_TOUCH_BUTTONS = src_filter=+<src/lcd/touch/touch_buttons.cpp>
HAS_LCD_MENU = src_filter=+<src/lcd/menu> HAS_LCD_MENU = src_filter=+<src/lcd/menu>
HAS_GAMES = src_filter=+<src/lcd/menu/game/game.cpp> HAS_GAMES = src_filter=+<src/lcd/menu/game/game.cpp>
MARLIN_BRICKOUT = src_filter=+<src/lcd/menu/game/brickout.cpp> MARLIN_BRICKOUT = src_filter=+<src/lcd/menu/game/brickout.cpp>