From 2f4b85568ab0a548db95d0fc94190f273f06d4e3 Mon Sep 17 00:00:00 2001 From: Victor Mateus Oliveira Date: Thu, 5 Nov 2020 23:09:48 -0300 Subject: [PATCH] to use ui without TOUCH_SCREEN_CALIBRATION --- Marlin/src/lcd/tft/touch.cpp | 18 ++++++++++++------ Marlin/src/lcd/tft_io/touch_calibration.h | 4 ++-- Marlin/src/lcd/touch/touch_buttons.cpp | 7 +++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index c4b931d2a4..1239b31f2f 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -53,7 +53,7 @@ TouchControlType Touch::touch_control_type = NONE; #endif void Touch::init() { - touch_calibration.calibration_reset(); + TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset()); reset(); io.Init(); enable(); @@ -248,12 +248,18 @@ void Touch::hold(touch_control_t *control, millis_t delay) { } bool Touch::get_point(int16_t *x, int16_t *y) { - bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); + #if ENABLED(TOUCH_SCREEN_CALIBRATION) + bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); - if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) { - *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; - *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; - } + if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) { + *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; + *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; + } + #else + bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y)); + *x = uint16_t((uint32_t(*x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; + *y = uint16_t((uint32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; + #endif return is_touched; } Touch touch; diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index 472966cd2e..f70d214a12 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -20,8 +20,6 @@ #include "../../inc/MarlinConfigPre.h" -#if ENABLED(TOUCH_SCREEN_CALIBRATION) - #ifndef TOUCH_SCREEN_CALIBRATION_PRECISION #define TOUCH_SCREEN_CALIBRATION_PRECISION 80 #endif @@ -50,6 +48,8 @@ #endif #endif +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + typedef struct __attribute__((__packed__)) { int32_t x; int32_t y; diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 5e666ac7c3..32aa7ced54 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -57,10 +57,13 @@ uint8_t TouchButtons::read_buttons() { if (touch_calibration.handleTouch(x, y)) ui.refresh(); return 0; } + x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; + y = int16_t((int32_t(y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; + #else + x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; + y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; #endif - x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x; - y = int16_t((int32_t(y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y; // Touch within the button area simulates an encoder button if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)