From 4ab350d4f2bf32a337856393e07e8a05357adb8a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 6 Dec 2013 09:13:31 -0800 Subject: [PATCH] Fixed detecting the wired XBox 360 controller on Linux Also added some more debug output to detect issues --- src/joystick/SDL_gamecontroller.c | 11 ++++++++--- src/joystick/SDL_gamecontrollerdb.h | 2 +- src/joystick/linux/SDL_sysjoystick.c | 15 ++++++++++++--- src/joystick/sort_controllers.py | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index d0329cd98..edcf5e41e 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -743,6 +743,7 @@ SDL_GameControllerAddMapping( const char *mappingString ) pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString ); if (!pchGUID) { + SDL_SetError("Couldn't parse GUID from %s", mappingString); return -1; } #ifdef SDL_JOYSTICK_DINPUT @@ -753,17 +754,21 @@ SDL_GameControllerAddMapping( const char *mappingString ) jGUID = SDL_JoystickGetGUIDFromString(pchGUID); SDL_free(pchGUID); - pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); - pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString ); - if (!pchName) return -1; + if (!pchName) { + SDL_SetError("Couldn't parse name from %s", mappingString); + return -1; + } pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString ); if (!pchMapping) { + SDL_SetError("Couldn't parse %s", mappingString); SDL_free( pchName ); return -1; } + pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); + if (pControllerMapping) { /* Update existing mapping */ SDL_free( pControllerMapping->name ); diff --git a/src/joystick/SDL_gamecontrollerdb.h b/src/joystick/SDL_gamecontrollerdb.h index 5954ccf74..21f9aaade 100644 --- a/src/joystick/SDL_gamecontrollerdb.h +++ b/src/joystick/SDL_gamecontrollerdb.h @@ -57,7 +57,7 @@ static const char *s_ControllerMappings [] = "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. */ "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,", "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,", - "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," + "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,", "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,", "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,", "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,", diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 43990b42f..b7b1c5327 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -509,10 +509,11 @@ ConfigJoystick(SDL_Joystick * joystick, int fd) if (test_bit(i, absbit)) { struct input_absinfo absinfo; - if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) + if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) { continue; + } #ifdef DEBUG_INPUT_EVENTS - printf("Joystick has absolute axis: %x\n", i); + printf("Joystick has absolute axis: 0x%.2x\n", i); printf("Values = { %d, %d, %d, %d, %d }\n", absinfo.value, absinfo.minimum, absinfo.maximum, absinfo.fuzz, absinfo.flat); @@ -539,9 +540,17 @@ ConfigJoystick(SDL_Joystick * joystick, int fd) } for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) { if (test_bit(i, absbit) || test_bit(i + 1, absbit)) { + struct input_absinfo absinfo; + + if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) { + continue; + } #ifdef DEBUG_INPUT_EVENTS printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2); -#endif + printf("Values = { %d, %d, %d, %d, %d }\n", + absinfo.value, absinfo.minimum, absinfo.maximum, + absinfo.fuzz, absinfo.flat); +#endif /* DEBUG_INPUT_EVENTS */ ++joystick->nhats; } } diff --git a/src/joystick/sort_controllers.py b/src/joystick/sort_controllers.py index 344a42328..03b857a02 100755 --- a/src/joystick/sort_controllers.py +++ b/src/joystick/sort_controllers.py @@ -29,6 +29,8 @@ def write_controllers(): global controller_guids for entry in sorted(controllers, key=lambda entry: entry[2]): line = "".join(entry) + "\n" + if not line.endswith(",\n") and not line.endswith("*/\n"): + print "Warning: '%s' is missing a comma at the end of the line" % (line) if (entry[1] in controller_guids): print "Warning: entry '%s' is duplicate of entry '%s'" % (entry[2], controller_guids[entry[1]][2]) controller_guids[entry[1]] = entry