to use ui without TOUCH_SCREEN_CALIBRATION
This commit is contained in:
parent
715502172f
commit
2f4b85568a
3 changed files with 19 additions and 10 deletions
|
|
@ -53,7 +53,7 @@ TouchControlType Touch::touch_control_type = NONE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Touch::init() {
|
void Touch::init() {
|
||||||
touch_calibration.calibration_reset();
|
TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
|
||||||
reset();
|
reset();
|
||||||
io.Init();
|
io.Init();
|
||||||
enable();
|
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 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));
|
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) {
|
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;
|
*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;
|
*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;
|
return is_touched;
|
||||||
}
|
}
|
||||||
Touch touch;
|
Touch touch;
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#include "../../inc/MarlinConfigPre.h"
|
#include "../../inc/MarlinConfigPre.h"
|
||||||
|
|
||||||
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
|
||||||
|
|
||||||
#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION
|
#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION
|
||||||
#define TOUCH_SCREEN_CALIBRATION_PRECISION 80
|
#define TOUCH_SCREEN_CALIBRATION_PRECISION 80
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -50,6 +48,8 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||||
|
|
||||||
typedef struct __attribute__((__packed__)) {
|
typedef struct __attribute__((__packed__)) {
|
||||||
int32_t x;
|
int32_t x;
|
||||||
int32_t y;
|
int32_t y;
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,13 @@ uint8_t TouchButtons::read_buttons() {
|
||||||
if (touch_calibration.handleTouch(x, y)) ui.refresh();
|
if (touch_calibration.handleTouch(x, y)) ui.refresh();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
x = int16_t((int32_t(x) * touch_calibration.calibration.x) >> 16) + touch_calibration.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) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
|
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
|
||||||
|
|
||||||
|
|
||||||
// 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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue