Fixed mapping for both versions of the Xbox One Elite Series 2 controller firmware connecting over Bluetooth
authorSam Lantinga <slouken@libsdl.org>
Thu, 23 Jan 2020 12:53:43 -0800
changeset 134443b0ad6c584ac
parent 13443 93fcc499b16f
child 13445 39a7b759a38a
Fixed mapping for both versions of the Xbox One Elite Series 2 controller firmware connecting over Bluetooth
src/joystick/SDL_gamecontrollerdb.h
src/joystick/linux/SDL_sysjoystick.c
     1.1 --- a/src/joystick/SDL_gamecontrollerdb.h	Thu Jan 23 12:53:41 2020 -0800
     1.2 +++ b/src/joystick/SDL_gamecontrollerdb.h	Thu Jan 23 12:53:43 2020 -0800
     1.3 @@ -612,7 +612,8 @@
     1.4      "0000000058626f782033363020576900,Xbox 360 Wireless Controller,a:b0,b:b1,back:b14,dpdown:b11,dpleft:b12,dpright:b13,dpup:b10,guide:b7,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,",
     1.5      "030000005e040000a102000014010000,Xbox 360 Wireless Receiver (XBOX),a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
     1.6      "0000000058626f782047616d65706100,Xbox Gamepad (userspace driver),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
     1.7 -    "050000005e040000050b000003090000,Xbox One Elite Series 2,a:b0,b:b1,back:b136,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b137,leftshoulder:b6,leftstick:b13,lefttrigger:a6,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
     1.8 +    "050000005e040000050b000002090000,Xbox One Elite Series 2,a:b0,b:b1,back:b136,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a6,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
     1.9 +    "050000005e040000050b000003090000,Xbox One Elite Series 2,a:b0,b:b1,back:b121,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
    1.10      "030000005e040000ea02000000000000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    1.11      "030000005e040000ea02000001030000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    1.12      "050000005e040000e002000003090000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
     2.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 23 12:53:41 2020 -0800
     2.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Thu Jan 23 12:53:43 2020 -0800
     2.3 @@ -102,6 +102,23 @@
     2.4      return matchlen;
     2.5  }
     2.6  
     2.7 +static void
     2.8 +FixupDeviceInfoForMapping(int fd, struct input_id *inpid)
     2.9 +{
    2.10 +    if (inpid->vendor == 0x045e && inpid->product == 0x0b05 && inpid->version == 0x0903) {
    2.11 +        /* This is a Microsoft Xbox One Elite Series 2 controller */
    2.12 +        unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
    2.13 +
    2.14 +        /* The first version of the firmware duplicated all the inputs */
    2.15 +        if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
    2.16 +            test_bit(0x2c0, keybit)) {
    2.17 +            /* Change the version to 0x0902, so we can map it differently */
    2.18 +            inpid->version = 0x0902;
    2.19 +        }
    2.20 +    }
    2.21 +}
    2.22 +
    2.23 +
    2.24  static int
    2.25  IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
    2.26  {
    2.27 @@ -157,6 +174,8 @@
    2.28      }
    2.29  #endif
    2.30  
    2.31 +    FixupDeviceInfoForMapping(fd, &inpid);
    2.32 +
    2.33  #ifdef DEBUG_JOYSTICK
    2.34      printf("Joystick: %s, bustype = %d, vendor = 0x%.4x, product = 0x%.4x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
    2.35  #endif
    2.36 @@ -819,6 +838,9 @@
    2.37              joystick->hwdata->effect_expiration = 1;
    2.38          }
    2.39      } else {
    2.40 +        if (!joystick->hwdata->effect_expiration) {
    2.41 +            return 0;
    2.42 +        }
    2.43          joystick->hwdata->effect_expiration = 0;
    2.44      }
    2.45