From 0881edd2e6404a21224af2667e8becddf188cf24 Mon Sep 17 00:00:00 2001 From: mark9064 <30447455+mark9064@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:39:30 +0000 Subject: Remove redundant touchpanel read --- src/drivers/Cst816s.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index cf10c895..6abca66e 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -1,5 +1,6 @@ #include "drivers/Cst816s.h" #include +#include #include #include #include @@ -61,23 +62,25 @@ bool Cst816S::Init() { Cst816S::TouchInfos Cst816S::GetTouchInfo() { Cst816S::TouchInfos info; - uint8_t touchData[7]; + std::array touchData {}; - auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData)); + // Skip reading register 0 as we don't need it + constexpr uint8_t addressOffset = 1; + auto ret = twiMaster.Read(twiAddress, addressOffset, touchData.data(), sizeof(touchData)); if (ret != TwiMaster::ErrorCodes::NoError) { info.isValid = false; return info; } // This can only be 0 or 1 - uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f; - uint8_t xHigh = touchData[touchXHighIndex] & 0x0f; - uint8_t xLow = touchData[touchXLowIndex]; + uint8_t nbTouchPoints = touchData[touchPointNumIndex - addressOffset] & 0x0f; + uint8_t xHigh = touchData[touchXHighIndex - addressOffset] & 0x0f; + uint8_t xLow = touchData[touchXLowIndex - addressOffset]; uint16_t x = (xHigh << 8) | xLow; - uint8_t yHigh = touchData[touchYHighIndex] & 0x0f; - uint8_t yLow = touchData[touchYLowIndex]; + uint8_t yHigh = touchData[touchYHighIndex - addressOffset] & 0x0f; + uint8_t yLow = touchData[touchYLowIndex - addressOffset]; uint16_t y = (yHigh << 8) | yLow; - Gestures gesture = static_cast(touchData[gestureIndex]); + Gestures gesture = static_cast(touchData[gestureIndex - addressOffset]); // Validity check if (x >= maxX || y >= maxY || -- cgit v1.2.3-70-g09d2