|
1 | 1 | #include "drivers/Cst816s.h" |
2 | 2 | #include <FreeRTOS.h> |
| 3 | +#include <array> |
3 | 4 | #include <legacy/nrf_drv_gpiote.h> |
4 | 5 | #include <nrfx_log.h> |
5 | 6 | #include <task.h> |
@@ -65,23 +66,24 @@ bool Cst816S::Init() { |
65 | 66 |
|
66 | 67 | Cst816S::TouchInfos Cst816S::GetTouchInfo() { |
67 | 68 | Cst816S::TouchInfos info; |
68 | | - uint8_t touchData[7]; |
| 69 | + std::array<uint8_t, 6> touchData {}; |
69 | 70 |
|
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)); |
71 | 73 | if (ret != TwiMaster::ErrorCodes::NoError) { |
72 | 74 | info.isValid = false; |
73 | 75 | return info; |
74 | 76 | } |
75 | 77 |
|
76 | 78 | // 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]; |
80 | 82 | 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]; |
83 | 85 | uint16_t y = (yHigh << 8) | yLow; |
84 | | - Gestures gesture = static_cast<Gestures>(touchData[gestureIndex]); |
| 86 | + Gestures gesture = static_cast<Gestures>(touchData[gestureIndex - addressOffset]); |
85 | 87 |
|
86 | 88 | // Validity check |
87 | 89 | if (x >= maxX || y >= maxY || |
|
0 commit comments