Capacitive Touch Screen (GT911) for SKR SE BX (#21843)

Co-authored-by: Msq001 <alansayyeah@gmail.com>
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
BigTreeTech
2021-05-09 10:02:16 +08:00
committed by Scott Lahteine
parent f3e199fcd2
commit ac11c689f7
14 changed files with 425 additions and 62 deletions

View File

@ -257,18 +257,23 @@ void Touch::hold(touch_control_t *control, millis_t delay) {
}
bool Touch::get_point(int16_t *x, int16_t *y) {
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
#if ENABLED(TFT_TOUCH_DEVICE_XPT2046)
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) {
*x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
*y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
}
#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;
if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) {
*x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
*y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
}
#else
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
*x = uint16_t((uint32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
*y = uint16_t((uint32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
#endif
#elif ENABLED(TFT_TOUCH_DEVICE_GT911)
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
#endif
return is_touched;
}
Touch touch;

View File

@ -30,8 +30,15 @@
#include "../tft_io/touch_calibration.h"
#endif
#include HAL_PATH(../../HAL, tft/xpt2046.h)
#define TOUCH_DRIVER XPT2046
#if ENABLED(TFT_TOUCH_DEVICE_GT911)
#include HAL_PATH(../../HAL, tft/gt911.h)
#define TOUCH_DRIVER_CLASS GT911
#elif ENABLED(TFT_TOUCH_DEVICE_XPT2046)
#include HAL_PATH(../../HAL, tft/xpt2046.h)
#define TOUCH_DRIVER_CLASS XPT2046
#else
#error "Unknown Touch Screen Type."
#endif
// Menu Navigation
extern int8_t encoderTopLine, encoderLine, screen_items;
@ -85,7 +92,7 @@ typedef struct __attribute__((__packed__)) {
class Touch {
private:
static TOUCH_DRIVER io;
static TOUCH_DRIVER_CLASS io;
static int16_t x, y;
static bool enabled;

View File

@ -48,9 +48,9 @@
void MarlinUI::tft_idle() {
#if ENABLED(TOUCH_SCREEN)
if (draw_menu_navigation) {
add_control(104, TFT_HEIGHT - 34, PAGE_UP, imgPageUp, encoderTopLine > 0);
add_control(344, TFT_HEIGHT - 34, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
add_control(224, TFT_HEIGHT - 34, BACK, imgBack);
add_control(164, TFT_HEIGHT - 50, PAGE_UP, imgPageUp, encoderTopLine > 0);
add_control(796, TFT_HEIGHT - 50, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
add_control(480, TFT_HEIGHT - 50, BACK, imgBack);
draw_menu_navigation = false;
}
#endif
@ -60,6 +60,7 @@ void MarlinUI::tft_idle() {
}
#if ENABLED(SHOW_BOOTSCREEN)
void MarlinUI::show_bootscreen() {
tft.queue.reset();
@ -81,9 +82,13 @@ void MarlinUI::tft_idle() {
#endif
tft.queue.sync();
safe_delay(BOOTSCREEN_TIMEOUT);
}
void MarlinUI::bootscreen_completion(const millis_t sofar) {
if ((BOOTSCREEN_TIMEOUT) > sofar) safe_delay((BOOTSCREEN_TIMEOUT) - sofar);
clear_lcd();
}
#endif
void MarlinUI::draw_kill_screen() {
@ -289,7 +294,7 @@ void MarlinUI::draw_status_screen() {
tft_string.set(i16tostr3rj(feedrate_percentage));
tft_string.add('%');
tft.add_text(36, 1, color , tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 96, 176, 100, 32));
TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 274, y, 100, 32));
// flow rate
tft.canvas(650, y, 100, 32);
@ -299,10 +304,10 @@ void MarlinUI::draw_status_screen() {
tft_string.set(i16tostr3rj(planner.flow_percentage[active_extruder]));
tft_string.add('%');
tft.add_text(36, 1, color , tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 284, 176, 100, 32, active_extruder));
TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 650, y, 100, 32, active_extruder));
#if ENABLED(TOUCH_SCREEN)
add_control(404, y, menu_main, imgSettings);
add_control(900, y, menu_main, imgSettings);
TERN_(SDSUPPORT, add_control(12, y, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
#endif
@ -375,8 +380,8 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const val
extern screenFunc_t _manual_move_func_ptr;
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
#define SLIDER_LENGTH 336
#define SLIDER_Y_POSITION 186
#define SLIDER_LENGTH 600
#define SLIDER_Y_POSITION 200
tft.canvas((TFT_WIDTH - SLIDER_LENGTH) / 2, SLIDER_Y_POSITION, SLIDER_LENGTH, 16);
tft.set_background(COLOR_BACKGROUND);
@ -398,9 +403,9 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const val
void TFT::draw_edit_screen_buttons() {
#if ENABLED(TOUCH_SCREEN)
add_control(64, TFT_HEIGHT - 64, DECREASE, imgDecrease);
add_control(352, TFT_HEIGHT - 64, INCREASE, imgIncrease);
add_control(208, TFT_HEIGHT - 64, CLICK, imgConfirm);
add_control(164, TFT_HEIGHT - 64, DECREASE, imgDecrease);
add_control(796, TFT_HEIGHT - 64, INCREASE, imgIncrease);
add_control(480, TFT_HEIGHT - 64, CLICK, imgConfirm);
#endif
}
@ -755,7 +760,7 @@ static void z_minus() { moveAxis(Z_AXIS, -1); }
drawMessage(GET_TEXT(MSG_LEVEL_BED_HOMING));
queue.inject_P(G28_STR);
// Disable touch until home is done
TERN_(HAS_TFT_XPT2046, touch.disable());
TERN_(TOUCH_SCREEN, touch.disable());
drawAxisValue(E_AXIS);
drawAxisValue(X_AXIS);
drawAxisValue(Y_AXIS);
@ -804,14 +809,14 @@ static void drawBtn(int x, int y, const char *label, intptr_t data, MarlinImage
tft.add_image(0, 0, img, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY);
}
TERN_(HAS_TFT_XPT2046, if (enabled) touch.add_control(BUTTON, x, y, width, height, data));
TERN_(TOUCH_SCREEN, if (enabled) touch.add_control(BUTTON, x, y, width, height, data));
}
void MarlinUI::move_axis_screen() {
// Reset
defer_status_screen(true);
motionAxisState.blocked = false;
TERN_(HAS_TFT_XPT2046, touch.enable());
TERN_(TOUCH_SCREEN, touch.enable());
ui.clear_lcd();
@ -849,13 +854,13 @@ void MarlinUI::move_axis_screen() {
motionAxisState.eNamePos.x = x;
motionAxisState.eNamePos.y = y;
drawCurESelection();
TERN_(HAS_TFT_XPT2046, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
x += BTN_WIDTH + spacing;
drawBtn(x, y, "X-", (intptr_t)x_minus, imgLeft, X_BTN_COLOR, !busy);
x += BTN_WIDTH + spacing; //imgHome is 64x64
TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy));
TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy));
x += BTN_WIDTH + spacing;
uint16_t xplus_x = x;
@ -904,13 +909,13 @@ void MarlinUI::move_axis_screen() {
motionAxisState.stepValuePos.y = y;
if (!busy) {
drawCurStepValue();
TERN_(HAS_TFT_XPT2046, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
}
// aligned with x+
drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);
TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));
TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));
}
#endif // HAS_UI_480x320

View File

@ -24,8 +24,15 @@
#include "touch_buttons.h"
#include "../scaled_tft.h"
#include HAL_PATH(../../HAL, tft/xpt2046.h)
XPT2046 touchIO;
#if ENABLED(TFT_TOUCH_DEVICE_GT911)
#include HAL_PATH(../../HAL, tft/gt911.h)
GT911 touchIO;
#elif ENABLED(TFT_TOUCH_DEVICE_XPT2046)
#include HAL_PATH(../../HAL, tft/xpt2046.h)
XPT2046 touchIO;
#else
#error "Unknown Touch Screen Type."
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../tft_io/touch_calibration.h"