2.4 xpad mouse emulation and wheel support

Richard Osborne <[email protected]> Fri, 16 Dec 2005 16:25:14 +0000
Newsgroups gmane.linux.ports.xbox.devel
Message-ID <[email protected]>
I was looking at the xpad mouse emulation in the 2.4 kernel patches and
noticed wheel handling was previously supported but has been commented
out. Up and down on the right analog stick had been mapped to scrolling 
up and down with a mouse wheel. It was pretty easy to put back in, but I
was wondering why it was removed in the first place. It makes
controlling applications a lot easier when you only have a xpad
available. Also the way the D-pad steering is implimented makes it
impossible to move diagonally with the D-pad (e.g. up and left). A patch
is included

Richard
xpad.patch (text/x-patch, 2.4 KB)
--- kernel/drivers/usb/xpad-mouse.c	2004-03-15 20:25:34.000000000 +0000
+++ linux-2.4.31-xbox/drivers/usb/xpad-mouse.c	2005-10-04 02:41:21.000000000 +0100
@@ -26,7 +26,7 @@
 #include "xpad.h"
 #undef __USB_XPAD_MOUSE
 
-#define XPAD_WHEELBRAKE		20
+#define XPAD_WHEELBRAKE	15
 #define JOY_DeadZone_fast	6000
 #define JOY_DeadZone_slow	200
 #define XPAD_OFFSET_COUNTER	5
@@ -103,7 +103,8 @@
 {
         struct input_dev *dev_mouse = &xpad->dev_mouse;
 	
-        int signledirection, xyspeed;
+        int xyspeed;
+	//int signledirection;
         //int joy_y2;
 	unsigned char MouseLeft,MouseRight, MouseMiddle;
         signed int left_joy_x, left_joy_y, right_joy_x, right_joy_y;
@@ -166,16 +167,16 @@
 	}
 	
 	// X-Y Steering
-	signledirection=1;
-	if (signledirection&((data[2] & 0x04)!=0)) { signledirection=0; xpad->rel_x -=xyspeed; }
-	if (signledirection&((data[2] & 0x08)!=0)) { signledirection=0; xpad->rel_x +=xyspeed; }
-	if (signledirection&((data[2] & 0x02)!=0)) { signledirection=0; xpad->rel_y +=xyspeed; }
-	if (signledirection&((data[2] & 0x01)!=0)) { signledirection=0; xpad->rel_y -=xyspeed; }
+	//signledirection=1;
+	if ((data[2] & 0x04)>>2!=0)  xpad->rel_x -=xyspeed;
+	if ((data[2] & 0x08)>>3!=0)  xpad->rel_x +=xyspeed;
+	if ((data[2] & 0x02)>>1!=0)  xpad->rel_y +=xyspeed;
+	if ((data[2] & 0x01)!=0)  xpad->rel_y -=xyspeed;
   	
 	/* wheel handling */
-	//joy_y2 = xpad_removedeadzone(joy_y2);
-	//xpad->rel_wheel = (joy_y2>0)?1:(joy_y2<0)?-1:0;
-	xpad->rel_wheel=0;
+	xpad->rel_wheel = xpad_removedeadzone(right_joy_y,1,0x3800);
+	xpad->rel_wheel = (xpad->rel_wheel>0)?1:(xpad->rel_wheel<0)?-1:0;
+	//xpad->rel_wheel=0;
 	
 	if (data[10]==0xFF) MouseLeft=1; else MouseLeft =0;
 	if ((MouseLeft==0)&(data[7]!=0)) MouseLeft =1;
@@ -209,11 +210,11 @@
 		input_report_rel(&xpad->dev_mouse, REL_X, xpad->rel_x);
 		input_report_rel(&xpad->dev_mouse, REL_Y, xpad->rel_y); 
 	
-		/*if (xpad->rel_wheeltimer == 0) {
+		if (xpad->rel_wheeltimer == 0) {
 			input_report_rel(&xpad->dev_mouse, REL_WHEEL, xpad->rel_wheel);
 			xpad->rel_wheeltimer = XPAD_WHEELBRAKE;
 		} else
-			xpad->rel_wheeltimer--;*/
+			xpad->rel_wheeltimer--;
 	}
 	
 	// reschedule the timer so that it fires continually
@@ -271,6 +272,7 @@
 	xpad->dev_mouse.open = xpad_mouse_open;
 	xpad->dev_mouse.close = xpad_mouse_close;
 	xpad->offsetset_compensation = XPAD_OFFSET_COUNTER; // Find new offset point
+	xpad->rel_wheeltimer = 0;
 	xpad->mouse_enabled = mouse_on_load;
 	
 	/* mouse setup */