Skip to content

Commit

Permalink
XBOXOLD: fix analog hat readings
Browse files Browse the repository at this point in the history
Properly read left and right analog hat values as 16bit integers.

Signed-off-by: Albert Herranz <[email protected]>
  • Loading branch information
herraa1 committed Jul 14, 2024
1 parent be8847f commit d459f58
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions XBOXOLD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,15 @@ uint8_t XBOXOLD::Poll() {

void XBOXOLD::readReport() {
ButtonState = readBuf[2];
void *p = readBuf;

for(uint8_t i = 0; i < sizeof (buttonValues); i++)
buttonValues[i] = readBuf[i + 4]; // A, B, X, Y, BLACK, WHITE, L1, and R1

hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[12] << 8) | readBuf[13]);
hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[14] << 8) | readBuf[15]);
hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[16] << 8) | readBuf[17]);
hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[18] << 8) | readBuf[19]);
hatValue[LeftHatX] = *(int16_t *)(p + 12);
hatValue[LeftHatY] = *(int16_t *)(p + 14);
hatValue[RightHatX] = *(int16_t *)(p + 16);
hatValue[RightHatY] = *(int16_t *)(p + 18);

//Notify(PSTR("\r\nButtonState"), 0x80);
//PrintHex<uint8_t>(ButtonState, 0x80);
Expand Down

0 comments on commit d459f58

Please sign in to comment.