Skip to content

Commit 7637336

Browse files
committed
Remove redundant touchpanel read
1 parent 332b4a0 commit 7637336

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/drivers/Cst816s.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "drivers/Cst816s.h"
22
#include <FreeRTOS.h>
3+
#include <array>
34
#include <legacy/nrf_drv_gpiote.h>
45
#include <nrfx_log.h>
56
#include <task.h>
@@ -65,23 +66,24 @@ bool Cst816S::Init() {
6566

6667
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
6768
Cst816S::TouchInfos info;
68-
uint8_t touchData[7];
69+
std::array<uint8_t, 6> touchData {};
6970

70-
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
71+
constexpr uint8_t addressOffset = 1;
72+
auto ret = twiMaster.Read(twiAddress, addressOffset, touchData.data(), sizeof(touchData));
7173
if (ret != TwiMaster::ErrorCodes::NoError) {
7274
info.isValid = false;
7375
return info;
7476
}
7577

7678
// This can only be 0 or 1
77-
uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
78-
uint8_t xHigh = touchData[touchXHighIndex] & 0x0f;
79-
uint8_t xLow = touchData[touchXLowIndex];
79+
uint8_t nbTouchPoints = touchData[touchPointNumIndex - addressOffset] & 0x0f;
80+
uint8_t xHigh = touchData[touchXHighIndex - addressOffset] & 0x0f;
81+
uint8_t xLow = touchData[touchXLowIndex - addressOffset];
8082
uint16_t x = (xHigh << 8) | xLow;
81-
uint8_t yHigh = touchData[touchYHighIndex] & 0x0f;
82-
uint8_t yLow = touchData[touchYLowIndex];
83+
uint8_t yHigh = touchData[touchYHighIndex - addressOffset] & 0x0f;
84+
uint8_t yLow = touchData[touchYLowIndex - addressOffset];
8385
uint16_t y = (yHigh << 8) | yLow;
84-
Gestures gesture = static_cast<Gestures>(touchData[gestureIndex]);
86+
Gestures gesture = static_cast<Gestures>(touchData[gestureIndex - addressOffset]);
8587

8688
// Validity check
8789
if (x >= maxX || y >= maxY ||

0 commit comments

Comments
 (0)