Skip to content

Commit eddd9f7

Browse files
committed
Only verify relevant bytes in checkHighRes
In 'high res' mode the analog sticks can drift a little bit, so this was needlessly repeating reads waiting for a stable input. Instead this only checks the two relevant bytes that need to be stable in order for this check to work.
1 parent 3e2c364 commit eddd9f7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/controllers/ClassicController.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,18 @@ boolean ClassicController_Shared::checkHighRes(boolean *hr) const {
158158
* controllers apparently don't understand how to act as a proper
159159
* register-based I2C device and just return junk. So instead we're starting
160160
* at the beginning of the data block.
161-
*
162-
* On the plus side, requesting more data here does make the error-checking
163-
* more robust! Although at the expensive of a longer delay.
164161
*/
165-
static const uint8_t CheckPtr = 0x00; // start of the control data block
166-
static const uint8_t CheckSize = 8; // 8 bytes to cover both std and high res
162+
static const uint8_t CheckPtr = 0x00; // start of the control data block
163+
static const uint8_t CheckSize = 8; // 8 bytes to cover both std and high res
164+
static const uint8_t DataOffset = 0x06; // start of the data we're interested in (7 / 8)
167165
uint8_t checkData[CheckSize] = { 0x00 }, verifyData[CheckSize] = { 0x00 };
168166
do {
169167
if (!requestData(CheckPtr, CheckSize, checkData)) return false;
170168
delayMicroseconds(I2C_ConversionDelay); // need a brief delay between reads
171169
if (!requestData(CheckPtr, CheckSize, verifyData)) return false;
172170

173171
boolean equal = true;
174-
for (uint8_t i = 0; i < CheckSize; i++) {
172+
for (uint8_t i = 0; i < CheckSize - DataOffset; i++) {
175173
if (checkData[i] != verifyData[i]) {
176174
equal = false; // one byte does not match! quit
177175
break;
@@ -182,7 +180,7 @@ boolean ClassicController_Shared::checkHighRes(boolean *hr) const {
182180
delayMicroseconds(I2C_ConversionDelay); // if we're doing another loop, wait between reads again
183181
} while (true);
184182

185-
*hr = !(checkData[6] == 0x00 && checkData[7] == 0x00); // if both are '0', high res is false
183+
*hr = !(checkData[DataOffset] == 0x00 && checkData[DataOffset+1] == 0x00); // if both are '0', high res is false
186184
return true; // successfully read state
187185
}
188186

0 commit comments

Comments
 (0)