From 0f1e528b20aaa8a9ee12620fbb891e96eaf4a57e Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 19 Apr 2025 15:43:55 +0000 Subject: [PATCH] further testing --- src/graphics/Screen.cpp | 6 +++++- src/input/TouchScreenCST226SE.cpp | 22 +++++++++++++++++----- src/input/TouchScreenCST226SE.h | 8 ++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 9e4555e53..95b21c93f 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -39,6 +39,7 @@ along with this program. If not, see . #include "graphics/ScreenFonts.h" #include "graphics/images.h" #include "input/ScanAndSelect.h" +#include "input/TouchScreenCST226SE.h" #include "input/TouchScreenImpl1.h" #include "main.h" #include "mesh-pb-constants.h" @@ -1823,10 +1824,13 @@ void Screen::setup() new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast(dispdev)->getTouch); touchScreenImpl1->init(); } -#elif HAS_TOUCHSCREEN +#elif HAS_TOUCHSCREEN && !HAS_CST226SE touchScreenImpl1 = new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast(dispdev)->getTouch); touchScreenImpl1->init(); +#elif HAS_TOUCHSCREEN && HAS_CST226SE + touchScreenCST226SE = new TouchScreenCST226SE(TFT_HEIGHT, TFT_WIDTH, TouchScreenCST226SE::forwardGetTouch); + touchScreenCST226SE->init(); #endif // Subscribe to status updates diff --git a/src/input/TouchScreenCST226SE.cpp b/src/input/TouchScreenCST226SE.cpp index 3151797c2..ff0b39a7a 100644 --- a/src/input/TouchScreenCST226SE.cpp +++ b/src/input/TouchScreenCST226SE.cpp @@ -10,11 +10,13 @@ volatile bool CST_IRQ = false; +TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr; TouchScreenCST226SE *touchScreenCST226SE; TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)) : TouchScreenBase("touchscreen1", width, height), _getTouch(getTouch) { + instance = this; } void TouchScreenCST226SE::init() @@ -23,11 +25,11 @@ void TouchScreenCST226SE::init() if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) { i2cAddress = addr; -#ifdef TOUCHSCREEN_INT - pinMode(TOUCHSCREEN_INT, INPUT); - attachInterrupt( - TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING); -#endif + // #ifdef TOUCHSCREEN_INT + // pinMode(TOUCHSCREEN_INT, INPUT); + // attachInterrupt( + // TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING); + // #endif LOG_DEBUG("CST226SE init OK at address 0x%02X", addr); return; @@ -53,6 +55,16 @@ bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y) return false; } +bool TouchScreenCST226SE::forwardGetTouch(int16_t *x, int16_t *y) +{ + if (instance) { + return instance->getTouch(*x, *y); + LOG_DEBUG("TouchScreen touched %dx %dy", x, y); + } + + return false; +} + void TouchScreenCST226SE::onEvent(const TouchEvent &event) { InputEvent e; diff --git a/src/input/TouchScreenCST226SE.h b/src/input/TouchScreenCST226SE.h index 71d037724..fe5b81229 100644 --- a/src/input/TouchScreenCST226SE.h +++ b/src/input/TouchScreenCST226SE.h @@ -4,6 +4,8 @@ #ifdef HAS_CST226SE +#include "modules/CannedMessageModule.h" + #include "TouchScreenBase.h" #include "touch/TouchClassCST226.h" @@ -13,13 +15,15 @@ class TouchScreenCST226SE : public TouchScreenBase TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)); void init(void); + static bool forwardGetTouch(int16_t *x, int16_t *y); + bool (*_getTouch)(int16_t *, int16_t *); + protected: virtual bool getTouch(int16_t &x, int16_t &y); virtual void onEvent(const TouchEvent &event); - bool (*_getTouch)(int16_t *, int16_t *); - private: + static TouchScreenCST226SE *instance; TouchClassCST226 touch; uint8_t i2cAddress = 0;