From f286114ac9c90bf50b5bb46ca7ebf9f91322860b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 15 Jun 2017 12:03:02 +0200 Subject: [PATCH 1/3] Newer Xbox One controllers requires a longer initialisation command Fixes #216 --- XBOXONE.cpp | 5 ++++- XBOXONE.h | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index d3f1fd77..8411140d 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -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; diff --git a/XBOXONE.h b/XBOXONE.h index 11710fcf..60c2806d 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -36,7 +36,8 @@ // PID and VID of the different devices #define XBOX_VID 0x045E // Microsoft Corporation -#define XBOX_ONE_PID 0x02D1 // Microsoft One Wired controller +#define XBOX_ONE_PID1 0x02D1 // Microsoft One Wired controller +#define XBOX_ONE_PID2 0x02DD // Microsoft One Wired controller #define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer @@ -94,7 +95,7 @@ public: * @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_VID && (pid == XBOX_ONE_PID1 || pid == XBOX_ONE_PID2)); }; /**@}*/ From e7d0695616c9f8f1d845737e04140f0495cbba18 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 15 Jun 2017 12:50:17 +0200 Subject: [PATCH 2/3] Added support for all known Xbox One controllers See: https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c --- XBOXONE.h | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/XBOXONE.h b/XBOXONE.h index 60c2806d..ab309d34 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -34,10 +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_PID1 0x02D1 // Microsoft One Wired controller -#define XBOX_ONE_PID2 0x02DD // 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 @@ -95,7 +115,10 @@ public: * @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_PID1 || pid == XBOX_ONE_PID2)); + 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)); }; /**@}*/ From 39150a15ea86557ce8360301fe1b539824fefb00 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 18 Jun 2017 18:02:43 +0200 Subject: [PATCH 3/3] Also update the ButtonClickState variable when the Xbox button is pressed Fixes #299 --- XBOXONE.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 8411140d..9c5b388f 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -266,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