From 85f0556118a71208fc0f2290ac60dc3657c8638c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 5 Sep 2019 00:32:20 +0200 Subject: [PATCH] Add XPT2046 calibration functions (#15140) --- Marlin/src/feature/touch/xpt2046.cpp | 8 ++++++++ Marlin/src/feature/touch/xpt2046.h | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Marlin/src/feature/touch/xpt2046.cpp b/Marlin/src/feature/touch/xpt2046.cpp index 3acfc0199e..cf1afc554c 100644 --- a/Marlin/src/feature/touch/xpt2046.cpp +++ b/Marlin/src/feature/touch/xpt2046.cpp @@ -135,4 +135,12 @@ uint16_t XPT2046::getInTouch(const XPTCoordinate coordinate) { return (data[1] + data[2]) >> 1; } +bool XPT2046::getTouchPoint(uint16_t &x, uint16_t &y) { + if (isTouched()) { + x = getInTouch(XPT2046_X); + y = getInTouch(XPT2046_Y); + } + return isTouched(); +} + #endif // TOUCH_BUTTONS diff --git a/Marlin/src/feature/touch/xpt2046.h b/Marlin/src/feature/touch/xpt2046.h index aea840576c..c4ac9d9662 100644 --- a/Marlin/src/feature/touch/xpt2046.h +++ b/Marlin/src/feature/touch/xpt2046.h @@ -42,8 +42,11 @@ class XPT2046 { public: static void init(void); static uint8_t read_buttons(); -private: + bool getTouchPoint(uint16_t &x, uint16_t &y); static bool isTouched(); + inline void waitForRelease(void) { while (isTouched()) { /* nada */ } } + inline void waitForTouch(uint16_t &x, uint16_t &y) { while (!getTouchPoint(x, y)) { /* nada */ } } +private: static uint16_t getInTouch(const XPTCoordinate coordinate); };