Re: [AD] joystick override

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


+# Linux only: which devices to use to probe for joysticks
+# joystick_device_0 = 
+# joystick_device_1 = 

I think we can also use joystick_device as an alias for joystick_device_0.


+        set_config_file("/tmp/foo.cfg");

As Peter said: :-)


 	for (i = 0; i < MAX_JOYSTICKS; i++) {
+                /* Check for a user override on the device to use */
+		uszprintf(tmp, sizeof(tmp), uconvert_ascii("joystick_device_%d", tmp1), 
i);
+                device_path = get_config_string(uconvert_ascii("joystick", 
tmp1), tmp, NULL);
+                if (device_path) {
+		   joy_fd[i] = open (device_path, O_RDONLY);

This will cause a UTF-16 string to be passed to open() in Unicode mode. You 
need to convert back to ASCII with uconvert_toascii() (see for example 
src/linux/lmsems.c)


> Allows one to select the joystick device in the config file.
> I don't have a joystick, but it picks up the mouse device fine,
> though it obviously doesn't pass the check tests.

Same testing here, although I do have a joystick but I haven't figured out 
how to make it work under Linux yet :-)

I've applied the attached patch to mainline and branch.

-- 
Eric Botcazou
? ljoy.diff
Index: allegro.cfg
===================================================================
RCS file: /cvsroot/alleg/allegro/allegro.cfg,v
retrieving revision 1.46
diff -u -p -r1.46 allegro.cfg
--- allegro.cfg	9 Oct 2003 11:30:01 -0000	1.46
+++ allegro.cfg	13 Oct 2003 11:40:56 -0000
@@ -558,12 +558,19 @@ joytype = 
 
 
 
-# BeOS only: joystick device port name (as reported on system joystick prefs)
+# BeoS and Linux only: name of the joystick device
 joystick_device = 
 
 
 
-# Linux only: which axis number the throttle is located at
+# alternatively you can specify it for each joystick:
+# joystick_device_0 = 
+# joystick_device_1 = 
+# ...
+
+
+
+# Linux only: axis number the throttle is located at
 throttle_axis = 
 
 # alternatively you can specify it for each joystick:
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.186
diff -u -p -r1.186 allegro._tx
--- docs/src/allegro._tx	13 Oct 2003 08:58:38 -0000	1.186
+++ docs/src/allegro._tx	13 Oct 2003 11:41:45 -0000
@@ -2047,11 +2047,14 @@ joytype = x<br>
    JOY_TYPE_AUTODETECT.
 <li>
 joystick_device = x<br>
-   BeOS only: specifies the name of the joystick device to be used. First
-   device found is used by default.
+   BeOS and Linux only: specifies the name of the joystick device to be used
+   (as reported in the system joystick preferences under BeOS). The first
+   device found is used by default. If you want to specify the device for
+   each joystick, use variables of the form joystick_device_n, where n is
+   the joystick number.
 <li>
 throttle_axis = x<br>
-   Linux only: sets which axis number the throttle is located at. This
+   Linux only: sets the axis number the throttle is located at. This
    variable will be used for every detected joystick. If you want to specify
    the axis number for each joystick individually, use variables of the form
    throttle_axis_n, where n is the joystick number.
Index: src/linux/ljoy.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/linux/ljoy.c,v
retrieving revision 1.19
diff -u -p -r1.19 ljoy.c
--- src/linux/ljoy.c	13 Oct 2003 09:50:53 -0000	1.19
+++ src/linux/ljoy.c	13 Oct 2003 11:41:47 -0000
@@ -45,6 +45,7 @@ static JOYSTICK_AXIS_INFO *axis[MAX_JOYS
 static int joy_init(void)
 {
    JOYSTICK_INFO *j;
+   AL_CONST char *device_name = NULL;
    char tmp[128], tmp1[128], tmp2[128];
    int version;
    char num_axes, num_buttons;
@@ -52,17 +53,34 @@ static int joy_init(void)
    int i, s, a, b;
 
    for (i = 0; i < MAX_JOYSTICKS; i++) {
-      snprintf(tmp, sizeof(tmp), "/dev/input/js%d", i);
-      tmp[sizeof(tmp)-1] = 0;
-
-      joy_fd[i] = open(tmp, O_RDONLY);
-      if (joy_fd[i] == -1) {
-	 snprintf(tmp, sizeof(tmp), "/dev/js%d", i);
+      /* Check for a user override on the device to use. */
+      uszprintf(tmp, sizeof(tmp), uconvert_ascii("joystick_device_%d", tmp1), i);
+      device_name = get_config_string(uconvert_ascii("joystick", tmp1), tmp, NULL);
+
+      /* Special case for the first joystick. */
+      if (!device_name && (i == 0))
+	 device_name = get_config_string(uconvert_ascii("joystick", tmp1),
+					 uconvert_ascii("joystick_device", tmp2),
+					 NULL);
+
+      if (device_name) {
+	 joy_fd[i] = open(uconvert_toascii(device_name, tmp), O_RDONLY);
+	 if (joy_fd[i] == -1)
+	    break;
+      }
+      else {
+	 snprintf(tmp, sizeof(tmp), "/dev/input/js%d", i);
 	 tmp[sizeof(tmp)-1] = 0;
 
 	 joy_fd[i] = open(tmp, O_RDONLY);
-	 if (joy_fd[i] == -1) 
-	    break;
+	 if (joy_fd[i] == -1) {
+	    snprintf(tmp, sizeof(tmp), "/dev/js%d", i);
+	    tmp[sizeof(tmp)-1] = 0;
+
+	    joy_fd[i] = open(tmp, O_RDONLY);
+	    if (joy_fd[i] == -1) 
+	       break;
+	 }
       }
 
       ioctl(joy_fd[i], JSIOCGVERSION, &version);
@@ -128,7 +146,7 @@ static int joy_init(void)
    num_joysticks = i;
    if (num_joysticks == 0) {
       uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unable to open %s: %s"),
-		uconvert_ascii("/dev/js0", tmp), ustrerror(errno));
+		device_name ? device_name : uconvert_ascii("/dev/js0", tmp), ustrerror(errno));
       return -1;
    }
 


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