I've got a trivial patch here for kernel 2.6.8.1 for the xbox gamepad
usb input device (xpad.c)

Basically the current version maps the D-PAD to axes, but some DDR 
(Dance Dance Revolution) style games need to know when both left/right 
and top/down are being pressed at the same time.

I've added the ability to pass a parameter at module load time called
ddr_mode.  If its 0 (default), the driver uses the old behavior with D-PAD
to axes mapping, if its 1, then D-PAD maps to BTN_0 - BTN_4.  there's a small
message outputted as well notifying the user about this in dmesg/whatever.

this patch applies to 2.6.8.1 but I think it should work with any 2.6 kernel.

I'm not subscribed to any mailing lists, please CC me if you need to.

-Dom

patch follows:

--- drivers/usb/input/xpad.c.orig       Mon Oct 11 08:41:08 2004
+++ drivers/usb/input/xpad.c    Sun Oct  3 11:47:34 2004
@@ -1,8 +1,8 @@
 /*
- * X-Box gamepad - v0.0.5
+ * X-Box gamepad - v0.0.6
  *
  * Copyright (c) 2002 Marko Friedemann <[EMAIL PROTECTED]>
- *
+ *               2004 Dominic Cerquetti <[EMAIL PROTECTED]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -33,6 +33,7 @@
  *  - fine tune axes
  *  - fix "analog" buttons (reported as digital now)
  *  - get rumble working
+ *  - distinction between usb id's for controllers and ddr pads?
  *
  * History:
  *
@@ -52,6 +53,12 @@
  *  - fixed d-pad to axes mapping
  *
  * 2002-07-17 - 0.0.5 : simplified d-pad handling
+ *
+ * 2004-10-02 - 0.0.6 : added ddr mode - Dominic Cerquetti <[EMAIL PROTECTED]>
+ *  - pass the option 'ddr_mode=1' to enable
+ *    mapping D-PAD to buttons rather than axes
+ *    needed for Dance Dance Revolution pads
+ *       
  */
 
 #include <linux/config.h>
@@ -60,10 +67,16 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/smp_lock.h>
 #include <linux/usb.h>
 
-#define DRIVER_VERSION "v0.0.5"
+static int ddr_mode;
+module_param(ddr_mode, int, 0000);
+MODULE_PARM_DESC(ddr_mode, 
+                               "Map D-PAD to buttons rather than axes (for DDR 
pads)");
+
+#define DRIVER_VERSION "v0.0.6"
 #define DRIVER_AUTHOR "Marko Friedemann <[EMAIL PROTECTED]>"
 #define DRIVER_DESC "X-Box pad driver"
 
@@ -80,9 +93,11 @@
        { 0x0000, 0x0000, "X-Box pad" }
 };
 
+/* BTN_0 through BTN_4 used only for ddr_mode */
 static signed short xpad_btn[] = {
        BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,       /* "analog" buttons */
        BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR,    /* start/back/sticks */
+       BTN_0, BTN_1, BTN_2, BTN_3,                     /* left,right,up,down */
        -1                                              /* terminating entry */
 };
 
@@ -142,8 +157,17 @@
        input_report_abs(dev, ABS_RZ, data[11]);
        
        /* digital pad */
-       input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04));
-       input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01));
+       if (ddr_mode) {
+               /* report as buttons */
+               input_report_key(dev, BTN_0, (data[2] & 0x04) >> 2); // left
+               input_report_key(dev, BTN_1, (data[2] & 0x08) >> 3); // right
+               input_report_key(dev, BTN_2, (data[2] & 0x01));      // up
+               input_report_key(dev, BTN_3, (data[2] & 0x02) >> 1); // down
+       } else {
+               /* report as axes */
+               input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 
0x04));
+               input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 
0x01));
+       }
        
        /* start/back buttons and stick press left/right */
        input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4);
@@ -344,8 +368,16 @@
 static int __init usb_xpad_init(void)
 {
        int result = usb_register(&xpad_driver);
+
        if (result == 0)
                info(DRIVER_DESC ":" DRIVER_VERSION);
+
+       if (ddr_mode) {
+               info("DDR mode enabled.");
+       } else {
+               info("For DDR pads, pass ddr_mode=1");
+       }
+       
        return result;
 }



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to