Re: [AD] Linux joystick driver button limitation

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Tom Fjellstrom <tfjellstrom@xxxxxxxxxx> wrote:
> I have a USB SideWinder GamePad Pro and allegro
> has always ignored the 9th button, so i took
> a look at ljoy.c and changed the 'if(num_buttons > 8)...'
> to 'if(num_buttons > 9)...', and also the line
> in joy_poll so now I have a working 9th button
> and want to know if this change would affect
> other joysticks? (i.e.: gameport joysticks)

Can you check the attached patch?  It uses constants from allegro.h
instead of making up its own.  I'm not sure about it as I haven't
used the joystick API for a long time.
Index: ljoy.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/ljoy.c,v
retrieving revision 1.2
diff -u -r1.2 ljoy.c
--- ljoy.c	2000/08/05 10:54:49	1.2
+++ ljoy.c	2001/02/21 22:58:25
@@ -33,8 +33,10 @@
 #include <linux/joystick.h>
 
 
+#define TOTAL_JOYSTICK_AXES	(MAX_JOYSTICK_STICKS * MAX_JOYSTICK_AXIS)
+
 static int joy_fd[MAX_JOYSTICKS];
-static JOYSTICK_AXIS_INFO *axis[MAX_JOYSTICKS][8];
+static JOYSTICK_AXIS_INFO *axis[MAX_JOYSTICKS][TOTAL_JOYSTICK_AXES];
 
 
 static int joy_init (void)
@@ -58,8 +60,8 @@
 		ioctl (joy_fd[i], JSIOCGAXES, &num_axes);
 		ioctl (joy_fd[i], JSIOCGBUTTONS, &num_buttons);
 
-		if (num_axes > 8) num_axes = 8;
-		if (num_buttons > 8) num_buttons = 8;
+		if (num_axes > TOTAL_JOYSTICK_AXES) num_axes = TOTAL_JOYSTICK_AXES;
+		if (num_buttons > MAX_JOYSTICK_BUTTONS) num_buttons = MAX_JOYSTICK_BUTTONS;
 
 		/* User is allow to override our simple assumption of which
 		 * axis number (kernel) the throttle is located at. */
@@ -148,10 +150,10 @@
 		if (ready <= 0) continue;
 		read (joy_fd[i], &e, sizeof e);
 		if (e.type & JS_EVENT_BUTTON) {
-			if (e.number < 8)
+			if (e.number < MAX_JOYSTICK_BUTTONS)
 				joy[i].button[e.number].b = e.value;
 		} else if (e.type & JS_EVENT_AXIS) {
-			if (e.number < 8) 
+			if (e.number < TOTAL_JOYSTICK_AXES)
 				set_axis (axis[i][e.number], e.value);
 		}
 	}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/