Skip to content

Commit 3fc8959

Browse files
committed
Use enum for USB receive packet types
I've seen 0x02 before as well although I don't know what it's used for. Byte 0 is the message type and byte 1 is the length
1 parent e125b60 commit 3fc8959

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

keywords.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ XInputGamepad KEYWORD1
1414

1515
# Enums
1616
XInputControl KEYWORD1
17+
XInputReceiveType KEYWORD1
1718
XInputLEDPattern KEYWORD1
1819

1920
#######################################
@@ -89,6 +90,10 @@ TRIGGER_RIGHT LITERAL1
8990
JOY_LEFT LITERAL1
9091
JOY_RIGHT LITERAL1
9192

93+
# USB Receive Packet Types
94+
Rumble LITERAL1
95+
LEDs LITERAL1
96+
9297
# LED Patterns
9398
Off LITERAL1
9499
Blinking LITERAL1

src/XInput.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,16 @@ size_t XInputGamepad::receive() {
347347
// Grab packet and store it in rx array
348348
uint8_t rx[8];
349349
size_t bytesRecv = XInputUSB::recv(rx, USB_Timeout);
350+
351+
const uint8_t PacketType = rx[0];
350352

351353
// Rumble Packet
352-
if ((rx[0] == 0x00) & (rx[1] == 0x08)) {
354+
if(PacketType == (uint8_t) XInputReceiveType::Rumble) {
353355
rumble[RumbleLeft.bufferIndex] = rx[RumbleLeft.rxIndex]; // Big weight (Left grip)
354356
rumble[RumbleRight.bufferIndex] = rx[RumbleRight.rxIndex]; // Small weight (Right grip)
355357
}
356358
// LED Packet
357-
else if (rx[0] == 0x01) {
359+
else if (PacketType == (uint8_t) XInputReceiveType::LEDs) {
358360
parseLED(rx[2]);
359361
}
360362
return bytesRecv;

src/XInput.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ enum XInputControl {
5151
JOY_RIGHT,
5252
};
5353

54+
enum class XInputReceiveType {
55+
Rumble = 0x00,
56+
LEDs = 0x01,
57+
};
58+
5459
enum class XInputLEDPattern {
5560
Off = 0x00,
5661
Blinking = 0x01,

0 commit comments

Comments
 (0)