touch calibratio screen for classic ui
This commit is contained in:
parent
3c8fdbe026
commit
e6e936d41a
5 changed files with 105 additions and 25 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
void touch_screen_calibration() {
|
||||
|
||||
ui.touch_calibration();
|
||||
ui.touch_calibration_screen();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue