Fixed detecting the wired XBox 360 controller on Linux
authorSam Lantinga <slouken@libsdl.org>
Fri, 06 Dec 2013 09:13:31 -0800
changeset 8053 495f4a047be1
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
--- a/src/joystick/SDL_gamecontroller.c	Fri Dec 06 08:24:00 2013 -0800
+++ b/src/joystick/SDL_gamecontroller.c	Fri Dec 06 09:13:31 2013 -0800
@@ -743,6 +743,7 @@
 
     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 @@
     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 );
--- a/src/joystick/SDL_gamecontrollerdb.h	Fri Dec 06 08:24:00 2013 -0800
+++ b/src/joystick/SDL_gamecontrollerdb.h	Fri Dec 06 09:13:31 2013 -0800
@@ -57,7 +57,7 @@
     "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,",
--- a/src/joystick/linux/SDL_sysjoystick.c	Fri Dec 06 08:24:00 2013 -0800
+++ b/src/joystick/linux/SDL_sysjoystick.c	Fri Dec 06 09:13:31 2013 -0800
@@ -509,10 +509,11 @@
             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 @@
         }
         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;
             }
         }
--- a/src/joystick/sort_controllers.py	Fri Dec 06 08:24:00 2013 -0800
+++ b/src/joystick/sort_controllers.py	Fri Dec 06 09:13:31 2013 -0800
@@ -29,6 +29,8 @@
     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