Skip to content

Commit

Permalink
XBOXOLD: fix endianness of analog hats w/o using void pointer arithmetic
Browse files Browse the repository at this point in the history
Signed-off-by: Albert Herranz <[email protected]>
  • Loading branch information
herraa1 committed Jul 15, 2024
1 parent 1f4222c commit 13d42f4
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions XBOXOLD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,14 @@ 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 *)(p + 12);
hatValue[LeftHatY] = *(int16_t *)(p + 14);
hatValue[RightHatX] = *(int16_t *)(p + 16);
hatValue[RightHatY] = *(int16_t *)(p + 18);
hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[19] << 8) | readBuf[18]);

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

0 comments on commit 13d42f4

Please sign in to comment.