Fixed detecting the wired XBox 360 controller on Linux
authorSam Lantinga <slouken@libsdl.org>
Fri, 06 Dec 2013 09:13:31 -0800
changeset 8053495f4a047be1
parent 8052 f0c6c1a45fb1
child 8054 2a38ef3eeabb
Fixed detecting the wired XBox 360 controller on Linux
Also added some more debug output to detect issues
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_gamecontrollerdb.h
src/joystick/linux/SDL_sysjoystick.c
src/joystick/sort_controllers.py
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Fri Dec 06 08:24:00 2013 -0800
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Fri Dec 06 09:13:31 2013 -0800
     1.3 @@ -743,6 +743,7 @@
     1.4  
     1.5      pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString );
     1.6      if (!pchGUID) {
     1.7 +        SDL_SetError("Couldn't parse GUID from %s", mappingString);
     1.8          return -1;
     1.9      }
    1.10  #ifdef SDL_JOYSTICK_DINPUT
    1.11 @@ -753,17 +754,21 @@
    1.12      jGUID = SDL_JoystickGetGUIDFromString(pchGUID);
    1.13      SDL_free(pchGUID);
    1.14  
    1.15 -    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
    1.16 -
    1.17      pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString );
    1.18 -    if (!pchName) return -1;
    1.19 +    if (!pchName) {
    1.20 +        SDL_SetError("Couldn't parse name from %s", mappingString);
    1.21 +        return -1;
    1.22 +    }
    1.23  
    1.24      pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString );
    1.25      if (!pchMapping) {
    1.26 +        SDL_SetError("Couldn't parse %s", mappingString);
    1.27          SDL_free( pchName );
    1.28          return -1;
    1.29      }
    1.30  
    1.31 +    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
    1.32 +
    1.33      if (pControllerMapping) {
    1.34          /* Update existing mapping */
    1.35          SDL_free( pControllerMapping->name );
     2.1 --- a/src/joystick/SDL_gamecontrollerdb.h	Fri Dec 06 08:24:00 2013 -0800
     2.2 +++ b/src/joystick/SDL_gamecontrollerdb.h	Fri Dec 06 09:13:31 2013 -0800
     2.3 @@ -57,7 +57,7 @@
     2.4      "030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
     2.5      "030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),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,",
     2.6      "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
     2.7 -    "03000000de280000ff11000001000000,Valve Streaming Gamepad,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,"
     2.8 +    "03000000de280000ff11000001000000,Valve Streaming Gamepad,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,",
     2.9      "030000005e0400008e02000014010000,X360 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,",
    2.10      "030000005e0400008e02000010010000,X360 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,",
    2.11      "030000005e0400001907000000010000,X360 Wireless Controller,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,",
     3.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Fri Dec 06 08:24:00 2013 -0800
     3.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Fri Dec 06 09:13:31 2013 -0800
     3.3 @@ -509,10 +509,11 @@
     3.4              if (test_bit(i, absbit)) {
     3.5                  struct input_absinfo absinfo;
     3.6  
     3.7 -                if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0)
     3.8 +                if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
     3.9                      continue;
    3.10 +                }
    3.11  #ifdef DEBUG_INPUT_EVENTS
    3.12 -                printf("Joystick has absolute axis: %x\n", i);
    3.13 +                printf("Joystick has absolute axis: 0x%.2x\n", i);
    3.14                  printf("Values = { %d, %d, %d, %d, %d }\n",
    3.15                         absinfo.value, absinfo.minimum, absinfo.maximum,
    3.16                         absinfo.fuzz, absinfo.flat);
    3.17 @@ -539,9 +540,17 @@
    3.18          }
    3.19          for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) {
    3.20              if (test_bit(i, absbit) || test_bit(i + 1, absbit)) {
    3.21 +                struct input_absinfo absinfo;
    3.22 +
    3.23 +                if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
    3.24 +                    continue;
    3.25 +                }
    3.26  #ifdef DEBUG_INPUT_EVENTS
    3.27                  printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2);
    3.28 -#endif
    3.29 +                printf("Values = { %d, %d, %d, %d, %d }\n",
    3.30 +                       absinfo.value, absinfo.minimum, absinfo.maximum,
    3.31 +                       absinfo.fuzz, absinfo.flat);
    3.32 +#endif /* DEBUG_INPUT_EVENTS */
    3.33                  ++joystick->nhats;
    3.34              }
    3.35          }
     4.1 --- a/src/joystick/sort_controllers.py	Fri Dec 06 08:24:00 2013 -0800
     4.2 +++ b/src/joystick/sort_controllers.py	Fri Dec 06 09:13:31 2013 -0800
     4.3 @@ -29,6 +29,8 @@
     4.4      global controller_guids
     4.5      for entry in sorted(controllers, key=lambda entry: entry[2]):
     4.6          line = "".join(entry) + "\n"
     4.7 +        if not line.endswith(",\n") and not line.endswith("*/\n"):
     4.8 +            print "Warning: '%s' is missing a comma at the end of the line" % (line)
     4.9          if (entry[1] in controller_guids):
    4.10              print "Warning: entry '%s' is duplicate of entry '%s'" % (entry[2], controller_guids[entry[1]][2])
    4.11          controller_guids[entry[1]] = entry