Patch: more comprehensive Xbox gamepad support

David Fifield david at bamsoftware.com
Tue Jan 11 02:20:14 EST 2005


> There was an existing entry for an Xbox controller with 14 axes and 10
> buttons. I couldn't find any combination of drivers or joydev/evdev that
> produced this configuration.

I found that old versions of the Xbox Linux driver (CVS tags
kernel-2_4_25-0_2_0 and kernel_2_6_4 and earlier) have 14 axes and 10
buttons. After those the D-pad (up, down, left, right) buttons were
added.

Here's an updated patch.

David Fifield
-------------- next part --------------
diff -Nru pydance-1.0.2.orig/pad.py pydance-1.0.2/pad.py
--- pydance-1.0.2.orig/pad.py	2004-01-06 21:41:20.000000000 -0700
+++ pydance-1.0.2/pad.py	2005-01-09 22:11:43.568731920 -0700
@@ -75,10 +75,34 @@
 A2B8 = { 4: UP, 6: DOWN,  5: LEFT, 7: RIGHT, 2: START,
          3: DOWNLEFT, 0: UPRIGHT, 1: DOWNRIGHT }
 
-# X-Box controller with X-Box Linux
-A14B10 = { 4: UP, 0: DOWN, 3: LEFT, 1: RIGHT,  6: START, 9: QUIT }
+# Xbox gamepads, Linux driver
+# With joydev module: 8 axes, 10 buttons
+# With evdev module: 6 axes, 1 hat, 10 buttons
+# B: 1, A: 0, X: 3, Y: 4, White: 5, Black: 2
+# Back: 9, Start: 6
+# Left analog stick: 7, Right analog stick: 8
+A8B10 = { 4: UP, 0: DOWN, 3: LEFT, 1: RIGHT, 6: START, 9: QUIT }
+
+# XBox gamepads, Xbox Linux driver (2.4.25 and 2.6.4 and earlier)
+# With joydev module: 14 axes, 10 buttons
+# With evdev module: 6 axes, 4 hats, 10 buttons
+# B: 1, A: 0, X: 3, Y: 4, White: 5, Black: 2
+# Back: 9, Start: 6
+# Left analog stick: 7, Right analog stick: 8
+A14B10 = { 4: UP, 0: DOWN, 3: LEFT, 1: RIGHT, 6: START, 9: QUIT }
+
+# XBox gamepads, Xbox Linux driver
+# With joydev module: 14 axes, 14 buttons
+# With evdev module: 6 axes, 4 hats, 14 buttons
+# Left: 12, Up: 9, Right: 10, Down: 11
+# B: 1, A: 0, X: 3, Y: 4, White: 5, Black: 2
+# Back: 13, Start: 6
+# Left analog stick: 7, Right analog stick: 8
+A14B14 = { 13: QUIT, 9: UP, 1: UPLEFT, 12: LEFT, 4: DOWNLEFT, 11: DOWN,
+           3: DOWNRIGHT, 10: RIGHT, 0: UPRIGHT, 6: START }
 
-MATS = { (6, 12): A6B12, (14, 10): A14B10, (2, 10): A2B10, (2, 8): A2B8 }
+MATS = { (6, 12): A6B12, (14, 10): A14B10, (2, 10): A2B10, (2, 8): A2B8,
+         (8, 10): A8B10, (14, 14): A14B14 }
 
 class Pad(object):
 
@@ -104,7 +128,8 @@
     for i in range(totaljoy):
       m = pygame.joystick.Joystick(i)
       m.init()
-      args = (i, m.get_numaxes(), m.get_numbuttons())
+      # One hat is two axes.
+      args = (i, m.get_numaxes() + 2 * m.get_numhats(), m.get_numbuttons())
       print "Joystick %d initialized: %d axes, %d buttons." % args
 
       if args[2] == 32: emsusb2 = i
@@ -133,15 +158,15 @@
       print "EMSUSB2 found. Using preset EMSUSB2 config."
     elif mat != None:
       joy = pygame.joystick.Joystick(mat)
-      but, axes = joy.get_numaxes(), joy.get_numbuttons()
+      axes, but = joy.get_numaxes() + 2 * joy.get_numhats(), joy.get_numbuttons()
       print "Initializing player 1 using js%d." % mat
-      self.merge_events(0, mat, MATS[(but, axes)])
+      self.merge_events(0, mat, MATS[(axes, but)])
 
       if mat2:
         joy = pygame.joystick.Joystick(mat2)
-        but, axes = joy.get_numaxes(), joy.get_numbuttons()
+        axes, but = joy.get_numaxes() + 2 * joy.get_numhats(), joy.get_numbuttons()
         print "Initializing player 2 using js%d." % mat2
-        self.merge_events(1, mat2, MATS[(but, axes)])
+        self.merge_events(1, mat2, MATS[(axes, but)])
     elif totaljoy > 0:
       print "No known joysticks found! If you want to use yours,"
       print "you'll have to map its button manually once to use it."


More information about the pyddr-discuss mailing list