Skip to content

Commit

Permalink
Merge pull request #298 from felis/XBOXONE_fix
Browse files Browse the repository at this point in the history
Newer Xbox One controllers requires a longer initialisation command
  • Loading branch information
Lauszus authored Jun 25, 2017
2 parents ff8bdb2 + 39150a1 commit fb47645
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 9 additions & 1 deletion XBOXONE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ uint8_t XBOXONE::Init(uint8_t parent, uint8_t port, bool lowspeed) {
// initialize the controller for input
writeBuf[0] = 0x05;
writeBuf[1] = 0x20;
rcode = XboxCommand(writeBuf, 2);
writeBuf[2] = 0x00;
writeBuf[3] = 0x01;
writeBuf[4] = 0x00;
rcode = XboxCommand(writeBuf, 5);
if (rcode)
goto Fail;

Expand Down Expand Up @@ -263,6 +266,11 @@ void XBOXONE::readReport() {
ButtonState |= pgm_read_word(&XBOX_BUTTONS[XBOX]);
else
ButtonState &= ~pgm_read_word(&XBOX_BUTTONS[XBOX]);

if(ButtonState != OldButtonState) {
ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable
OldButtonState = ButtonState;
}
}
if(readBuf[0] != 0x20) { // Check if it's the correct report, otherwise return - the controller also sends different status reports
#ifdef EXTRADEBUG
Expand Down
32 changes: 28 additions & 4 deletions XBOXONE.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,30 @@
#define XBOX_OUTPUT_PIPE 1
#define XBOX_INPUT_PIPE 2

// PID and VID of the different devices
#define XBOX_VID 0x045E // Microsoft Corporation
#define XBOX_ONE_PID 0x02D1 // Microsoft One Wired controller
// PID and VID of the different devices - see: https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c

// Official controllers
#define XBOX_VID1 0x045E // Microsoft Corporation
#define XBOX_ONE_PID1 0x02D1 // Microsoft X-Box One pad
#define XBOX_ONE_PID2 0x02DD // Microsoft X-Box One pad (Firmware 2015)
#define XBOX_ONE_PID3 0x02E3 // Microsoft X-Box One Elite pad
#define XBOX_ONE_PID4 0x02EA // Microsoft X-Box One S pad

// Unofficial controllers
#define XBOX_VID2 0x0738 // Mad Catz
#define XBOX_VID3 0x0E6F // Afterglow
#define XBOX_VID4 0x0F0D // HORIPAD ONE
#define XBOX_VID5 0x1532 // Razer
#define XBOX_VID6 0x24C6 // PowerA

#define XBOX_ONE_PID5 0x4A01 // Mad Catz FightStick TE 2 - might have different mapping for triggers?
#define XBOX_ONE_PID6 0x0139 // Afterglow Prismatic Wired Controller
#define XBOX_ONE_PID7 0x0146 // Rock Candy Wired Controller for Xbox One
#define XBOX_ONE_PID8 0x0067 // HORIPAD ONE
#define XBOX_ONE_PID9 0x0A03 // Razer Wildcat
#define XBOX_ONE_PID10 0x541A // PowerA Xbox One Mini Wired Controller
#define XBOX_ONE_PID11 0x542A // Xbox ONE spectra
#define XBOX_ONE_PID12 0x543A // PowerA Xbox One wired controller

#define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer

Expand Down Expand Up @@ -94,7 +115,10 @@ class XBOXONE : public USBDeviceConfig {
* @return Returns true if the device's VID and PID matches this driver.
*/
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
return (vid == XBOX_VID && pid == XBOX_ONE_PID);
return ((vid == XBOX_VID1 || vid == XBOX_VID2 || vid == XBOX_VID3 || vid == XBOX_VID4 || vid == XBOX_VID5 || vid == XBOX_VID6) &&
(pid == XBOX_ONE_PID1 || pid == XBOX_ONE_PID2 || pid == XBOX_ONE_PID3 || pid == XBOX_ONE_PID4 ||
pid == XBOX_ONE_PID5 || pid == XBOX_ONE_PID6 || pid == XBOX_ONE_PID7 || pid == XBOX_ONE_PID8 ||
pid == XBOX_ONE_PID9 || pid == XBOX_ONE_PID10 || pid == XBOX_ONE_PID11 || pid == XBOX_ONE_PID12));
};
/**@}*/

Expand Down

0 comments on commit fb47645

Please sign in to comment.