[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

xserver-xorg-input-joystick: Changes to 'upstream-unstable'



 ChangeLog          |    6 
 configure.ac       |   42 +-
 man/.cvsignore     |    2 
 man/.gitignore     |    3 
 man/Makefile.am    |    4 
 man/joystick.man   |  217 ++++++++++++++
 src/.cvsignore     |    6 
 src/.gitignore     |    6 
 src/Makefile.am    |   18 +
 src/bsd_jstk.c     |  315 +++++++++++++++++++++
 src/jstk.c         |  608 ++++++++++++++++++++++++++++++++++++++++
 src/jstk.h         |  123 ++++++++
 src/jstk_axis.c    |  348 +++++++++++++++++++++++
 src/jstk_axis.h    |   31 ++
 src/jstk_hw.h      |   38 ++
 src/jstk_options.c |  212 ++++++++++++++
 src/jstk_options.h |   35 ++
 src/linux_jstk.c   |  191 ++++++++++++
 src/xf86Jstk.c     |  795 -----------------------------------------------------
 19 files changed, 2174 insertions(+), 826 deletions(-)

New commits:
commit 25b5234948b6231577d44c5ad97a85d3a82b514a
Author: Sascha Hlusiak <saschahlusiak@arcor.de>
Date:   Fri Apr 20 21:09:10 2007 -0400

    Fixed wrong button number reported by bsd_jstk.c.
    Fixed typo in reporting button and axes numbers in bsd_jstk.c

diff --git a/src/bsd_jstk.c b/src/bsd_jstk.c
index 61ae781..a0c8ea3 100644
--- a/src/bsd_jstk.c
+++ b/src/bsd_jstk.c
@@ -78,7 +78,7 @@ struct jstk_bsd_hid_data {
 int
 jstkOpenDevice(JoystickDevPtr joystick)
 {
-  int cur_axis, cur_button;
+  int cur_axis;
   int is_joystick, report_id = 0;
   int got_something;
   struct hid_data *d;
@@ -124,7 +124,6 @@ jstkOpenDevice(JoystickDevPtr joystick)
   is_joystick = 0;
   got_something = 0;
   cur_axis = 0;
-  cur_button = 0;
   bsddata->hats = 0;
   bsddata->axes = 0;
   bsddata->buttons = 0;
@@ -172,8 +171,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
 	{
           if (bsddata->buttons < MAXBUTTONS) {
 	    got_something = 1;
-            memcpy(&bsddata->button_item[cur_button], &h, sizeof(h));
-            cur_button++;
+            memcpy(&bsddata->button_item[bsddata->buttons], &h, sizeof(h));
             bsddata->buttons++;
           }
 	}
@@ -192,7 +190,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
   bsddata->hotdata = 0;
   joystick->devicedata = (void*) bsddata;
   xf86Msg(X_INFO, "Joystick: %d buttons, %d axes\n", 
-      bsddata->axes, bsddata->buttons);
+      bsddata->buttons, bsddata->axes);
 
   return joystick->fd;
 }
@@ -300,8 +298,9 @@ jstkReadData(JoystickDevPtr joystick,
 
   for (j=0; j<bsddata->buttons; j++)
     {
-       int pressed = (d == bsddata->button_item[j].logical_minimum) ? 0 : 1;
+       int pressed;
        d = hid_get_data(bsddata->data_buf, &bsddata->button_item[j]);
+       pressed = (d == bsddata->button_item[j].logical_minimum) ? 0 : 1;
        if (pressed != joystick->button[j].pressed) {
          joystick->button[j].pressed = pressed;
          if (event != NULL) *event = EVENT_BUTTON;

commit e1871e21955d5403c2751e83b5c00b2fa4886f22
Author: Sascha Hlusiak <saschahlusiak@arcor.de>
Date:   Thu Apr 19 12:39:53 2007 -0400

    Fixed accelerated axis movement not working the first time after startup
    
    Modified used algorithm to produce slower and smoother acceleration

diff --git a/src/jstk_axis.c b/src/jstk_axis.c
index d71dc9b..4840ade 100644
--- a/src/jstk_axis.c
+++ b/src/jstk_axis.c
@@ -89,9 +89,9 @@ jstkAxisTimer(OsTimerPtr        timer,
 
     } else if (axis->type == TYPE_ACCELERATED) {
       /* Stop to accelerate at a certain speed */
-      if (axis->currentspeed < 100.0f) axis->currentspeed *= 1.15f;
-
-      p1 = (axis->currentspeed - 0.1f) * (float)NEXTTIMER / 180.0f;
+      if (axis->currentspeed < 100.0f) axis->currentspeed = 
+                                     (axis->currentspeed + 3.0) * 1.07f - 3.0;
+      p1 = axis->currentspeed * (float)NEXTTIMER / 180.0f;
       p2 = p1 / 8.0f;
     }
     if (axis->value < 0) {
@@ -124,9 +124,10 @@ jstkAxisTimer(OsTimerPtr        timer,
     float p1;
     float p2;
 
-    if (priv->button[i].currentspeed < 100.0f) priv->button[i].currentspeed *= 1.15f;
-    p1 = (priv->button[i].currentspeed - 0.1) * (float)NEXTTIMER / 180.0f *
-         priv->button[i].amplify;
+    if (priv->button[i].currentspeed < 100.0f) priv->button[i].currentspeed = 
+                           (priv->button[i].currentspeed + 3.0) * 1.07f - 3.0;
+   p1 = priv->button[i].currentspeed * (float)NEXTTIMER / 180.0f *
+        priv->button[i].amplify;
     p1 *= priv->amplify;
     p2 = p1 / 8.0f;
 
diff --git a/src/jstk_options.c b/src/jstk_options.c
index 191cb24..a45c883 100644
--- a/src/jstk_options.c
+++ b/src/jstk_options.c
@@ -100,6 +100,7 @@ jstkParseButtonOption(const char* org,
   } else if (sscanf(param, "axis=%15s", p) == 1) {
     button->mapping = jstkGetAxisMapping(&fvalue, p, name);
     button->amplify = fvalue;
+    button->currentspeed = 1.0;
     if (button->mapping == MAPPING_NONE)
       xf86Msg(X_WARNING, "%s: error parsing axis: %s.\n", 
               name, p);
@@ -160,9 +161,10 @@ jstkParseAxisOption(const char* org, AXIS *axis, const char *name)
       p[15]='\0';
       if (strcmp(p, "relative") == 0)
         axis->type = TYPE_BYVALUE;
-      else if (strcmp(p, "accelerated") == 0)
+      else if (strcmp(p, "accelerated") == 0) {
         axis->type = TYPE_ACCELERATED;
-      else if (strcmp(p, "absolute") == 0)
+        axis->currentspeed = 1.0;
+      } else if (strcmp(p, "absolute") == 0)
         axis->type = TYPE_ABSOLUTE;
       else if (strcmp(p, "none") == 0)
         axis->type = TYPE_NONE;

commit 44aafff9e99ff02091580978a2dd7306eb9ad910
Author: Sascha Hlusiak <saschahlusiak@arcor.de>
Date:   Mon Apr 16 23:01:31 2007 -0400

    Considering JS_EVENT_INIT events as real events again
    
    We want to perform actions on JS_EVENT_INIT events, so we don't miss anything and follow the state of
    the device

diff --git a/src/linux_jstk.c b/src/linux_jstk.c
index d5ae00a..5726304 100644
--- a/src/linux_jstk.c
+++ b/src/linux_jstk.c
@@ -52,7 +52,8 @@
  *
  * jstkOpenDevice --
  *
- * Open and initialize a joystick device
+ * Open and initialize a joystick device. The device name is
+ * taken from JoystickDevPtr 
  * Returns the filedescriptor, or -1 in case of error
  *
  ***********************************************************************
@@ -186,11 +187,5 @@ jstkReadData(JoystickDevPtr joystick,
       }
       break;
   }
-
-  /* If it is an JS_EVENT_INIT just save the state, but don't report
-     as an event */
-  if ((js.type & JS_EVENT_INIT) == JS_EVENT_INIT) {
-    if (event != NULL) *event = EVENT_NONE;
-  }
   return 1;
 }

commit 8cafcf33ec1dcffa0ecbe2647ebb89c879989d4c
Author: Sascha Hlusiak <saschahlusiak@arcor.de>
Date:   Sun Apr 15 23:48:52 2007 -0400

    Fixed possible double close of device in case of error.
    Opening device in O_RDONLY mode, instead of O_RDWR.

diff --git a/src/bsd_jstk.c b/src/bsd_jstk.c
index 437faff..61ae781 100644
--- a/src/bsd_jstk.c
+++ b/src/bsd_jstk.c
@@ -96,6 +96,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
     xf86Msg(X_ERROR, "Joystick: hid_get_report_desc failed: %s\n",
             strerror(errno));
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
 
@@ -103,6 +104,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
     xf86Msg(X_ERROR, "Joystick: ioctl USB_GET_REPORT_ID failed: %s\n",
             strerror(errno));
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
 
@@ -115,6 +117,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
     hid_dispose_report_desc(rd);
     free(bsddata);
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
 
@@ -182,6 +185,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
     xf86Msg(X_ERROR, "Joystick: Didn't find any usable axes.\n");
     free(bsddata);
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
 
diff --git a/src/linux_jstk.c b/src/linux_jstk.c
index 4b86d22..d5ae00a 100644
--- a/src/linux_jstk.c
+++ b/src/linux_jstk.c
@@ -65,7 +65,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
   unsigned char axes, buttons;
   int driver_version;
 
-  if ((joystick->fd = open(joystick->device, O_RDWR | O_NDELAY, 0)) < 0) {
+  if ((joystick->fd = open(joystick->device, O_RDONLY | O_NDELAY, 0)) < 0) {
     xf86Msg(X_ERROR, "Cannot open joystick '%s' (%s)\n", joystick->device,
             strerror(errno));
     return -1;
@@ -75,6 +75,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
     xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
             strerror(errno));
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
   if ((driver_version >> 16) < 1) {
@@ -88,6 +89,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
     xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
             strerror(errno));
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
 
@@ -95,6 +97,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
     xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
             strerror(errno));
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
 
@@ -102,6 +105,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
       xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", 
               joystick->device, strerror(errno));
     close(joystick->fd);
+    joystick->fd = -1;
     return -1;
   }
 

commit 1640d08d168241fd6168090841ef0d811d9dc3c2
Author: Sascha Hlusiak <saschahlusiak@arcor.de>
Date:   Sun Apr 15 23:18:39 2007 -0400

    Got rid of JoystickDevRec->axes and JoystickDevRec->buttons, since not really needed.

diff --git a/src/bsd_jstk.c b/src/bsd_jstk.c
index 0454528..437faff 100644
--- a/src/bsd_jstk.c
+++ b/src/bsd_jstk.c
@@ -55,6 +55,8 @@ struct jstk_bsd_hid_data {
     struct hid_item button_item[MAXBUTTONS]; /* Button HID items */
     struct hid_item hat_item[MAXAXES];       /* HID items for hats */
     int hats;                                /* Number of hats */
+    int axes;                                /* Number of found axes */
+    int buttons;                             /* Number of found buttons */
     int hotdata;                             /* Is unprocessed data available
                                                 in data_buf? */
 };
@@ -89,8 +91,6 @@ jstkOpenDevice(JoystickDevPtr joystick)
             strerror(errno));
     return -1;
   }
-  joystick->axes = 0;
-  joystick->buttons = 0;
 
   if ((rd = hid_get_report_desc(joystick->fd)) == 0) {
     xf86Msg(X_ERROR, "Joystick: hid_get_report_desc failed: %s\n",
@@ -123,6 +123,8 @@ jstkOpenDevice(JoystickDevPtr joystick)
   cur_axis = 0;
   cur_button = 0;
   bsddata->hats = 0;
+  bsddata->axes = 0;
+  bsddata->buttons = 0;
 
   for (d = hid_start_parse(rd, 1 << hid_input, report_id);
        hid_get_item(d, &h); ) {
@@ -146,30 +148,30 @@ jstkOpenDevice(JoystickDevPtr joystick)
 	{
 	  if (usage == HUG_HAT_SWITCH)
 	    {
-              if ((bsddata->hats < MAXAXES) && (joystick->axes <= MAXAXES-2)) {
+              if ((bsddata->hats < MAXAXES) && (bsddata->axes <= MAXAXES-2)) {
 	        got_something = 1;
 	        memcpy(&bsddata->hat_item[bsddata->hats], &h, sizeof(h));
                 bsddata->hats++;
-                joystick->axes += 2;
+                bsddata->axes += 2;
               }
 	    }
 	  else
 	    {
-              if (joystick->axes < MAXAXES) {
+              if (bsddata->axes < MAXAXES) {
 		got_something = 1;
 		memcpy(&bsddata->axis_item[cur_axis], &h, sizeof(h));
 		cur_axis++;
-                joystick->axes++;
+                bsddata->axes++;
 	      }
 	    }
 	}
       else if (page == HUP_BUTTON)
 	{
-          if (joystick->buttons < MAXBUTTONS) {
+          if (bsddata->buttons < MAXBUTTONS) {
 	    got_something = 1;
             memcpy(&bsddata->button_item[cur_button], &h, sizeof(h));
             cur_button++;
-            joystick->buttons++;
+            bsddata->buttons++;
           }
 	}
     }
@@ -186,7 +188,7 @@ jstkOpenDevice(JoystickDevPtr joystick)
   bsddata->hotdata = 0;
   joystick->devicedata = (void*) bsddata;
   xf86Msg(X_INFO, "Joystick: %d buttons, %d axes\n", 
-      joystick->axes, joystick->buttons);
+      bsddata->axes, bsddata->buttons);
 
   return joystick->fd;
 }
@@ -250,7 +252,7 @@ jstkReadData(JoystickDevPtr joystick,
     bsddata->hotdata = 1;
   }
 
-  for (j=0; j<joystick->axes - (bsddata->hats * 2); j++)
+  for (j=0; j<bsddata->axes - (bsddata->hats * 2); j++)
     {
       d = hid_get_data(bsddata->data_buf, &bsddata->axis_item[j]);
       /* Scale the range to our expected range of -32768 to 32767 */
@@ -275,7 +277,7 @@ jstkReadData(JoystickDevPtr joystick,
       int v2_data[9] =
         { -32768, -32768, 0, 32767, 32767, 32767, 0, -32767, 0 };
 
-      a = j*2 + joystick->axes - bsddata->hats *2;
+      a = j*2 + bsddata->axes - bsddata->hats *2;
       d = hid_get_data(bsddata->data_buf, &bsddata->hat_item[j]) 
         - bsddata->hat_item[j].logical_minimum;
       if (joystick->axis[a].value != v1_data[d]) {
@@ -292,7 +294,7 @@ jstkReadData(JoystickDevPtr joystick,
       }
     }
 
-  for (j=0; j<joystick->buttons; j++)
+  for (j=0; j<bsddata->buttons; j++)
     {
        int pressed = (d == bsddata->button_item[j].logical_minimum) ? 0 : 1;
        d = hid_get_data(bsddata->data_buf, &bsddata->button_item[j]);
diff --git a/src/jstk.c b/src/jstk.c
index 5cdc756..ceaeb4f 100644
--- a/src/jstk.c
+++ b/src/jstk.c
@@ -388,8 +388,6 @@ jstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags)
     priv->mouse_enabled = TRUE;
     priv->keys_enabled = TRUE;
     priv->amplify = 1.0f;
-    priv->axes = 0;
-    priv->buttons = 0;
 
     /* Initialize default mappings */
     for (i=0; i<MAXAXES; i++) {
diff --git a/src/jstk.h b/src/jstk.h
index 7a01fcb..2c8a1ff 100644
--- a/src/jstk.h
+++ b/src/jstk.h
@@ -105,20 +105,19 @@ typedef struct _BUTTON {
 #define MAXAXES 32
 
 typedef struct _JoystickDevRec {
-    int          fd;             /* Actual file descriptor */
-    void         *devicedata;    /* Extra platform device dependend data */
-    char         *device;        /* Name of the device */
+    int          fd;          /* Actual file descriptor */
+    void         *devicedata; /* Extra platform device dependend data */
+    char         *device;     /* Name of the device */
 
-    OsTimerPtr   timer;
+    OsTimerPtr   timer;       /* Timer for axis movement */
     Bool         timerrunning;
-    float        x,y,zx,zy;      /* Pending subpixel movements */
+    float        x,y,zx,zy;   /* Pending subpixel movements */
 
     Bool         mouse_enabled, keys_enabled;
-    float        amplify;        /* Global amplifier of axis movement */
+    float        amplify;     /* Global amplifier of axis movement */
 
-    AXIS axis[MAXAXES];                  /* Configuration per axis */
-    BUTTON button[MAXBUTTONS];           /* Configuration per button */
-    unsigned char axes, buttons;         /* Number of axes and buttons */
+    AXIS axis[MAXAXES];           /* Configuration per axis */
+    BUTTON button[MAXBUTTONS];    /* Configuration per button */
 } JoystickDevRec, *JoystickDevPtr;
 
 #endif
diff --git a/src/linux_jstk.c b/src/linux_jstk.c
index 3b89295..4b86d22 100644
--- a/src/linux_jstk.c
+++ b/src/linux_jstk.c
@@ -62,6 +62,7 @@ int
 jstkOpenDevice(JoystickDevPtr joystick)
 {
   char joy_name[128];
+  unsigned char axes, buttons;
   int driver_version;
 
   if ((joystick->fd = open(joystick->device, O_RDWR | O_NDELAY, 0)) < 0) {
@@ -83,34 +84,30 @@ jstkOpenDevice(JoystickDevPtr joystick)
             driver_version & 0xff);
   }
 
-  if (ioctl(joystick->fd, JSIOCGAXES, &joystick->axes) == -1) {
+  if (ioctl(joystick->fd, JSIOCGAXES, &axes) == -1) {
     xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
             strerror(errno));
     close(joystick->fd);
     return -1;
   }
-  if (joystick->axes > 32) joystick->axes = 32;
 
-  if (ioctl(joystick->fd, JSIOCGBUTTONS, &joystick->buttons) == -1) {
+  if (ioctl(joystick->fd, JSIOCGBUTTONS, &buttons) == -1) {
     xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
             strerror(errno));
     close(joystick->fd);
     return -1;
   }
-  if (joystick->buttons > 32) joystick->buttons = 32;
 
-  {
-    if (ioctl(joystick->fd, JSIOCGNAME(128), joy_name) == -1) {
+  if (ioctl(joystick->fd, JSIOCGNAME(128), joy_name) == -1) {
       xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", 
               joystick->device, strerror(errno));
-      close(joystick->fd);
-      return -1;
-    }
-
-    xf86Msg(X_INFO, "Joystick: %s. %d axes, %d buttons\n", 
-      joy_name, joystick->axes, joystick->buttons);
+    close(joystick->fd);
+    return -1;
   }
 
+  xf86Msg(X_INFO, "Joystick: %s. %d axes, %d buttons\n", 
+          joy_name, axes, buttons);
+
   return joystick->fd;
 }
 

commit 470acec6f440cf3cb1dc5ddcb056f717d74ccbef
Author: Sascha Hlusiak <saschahlusiak@arcor.de>
Date:   Sun Apr 15 22:51:35 2007 -0400

    Cosmetic changes to structs, got rid of XFree86LOADER blocks
    
    The XFree86LOADER is mandatory, without it it wouldn't compile anyway, so checks were deleted.
    Named structs in jstk.h again
    Added unions for mapping-relative data, given values more telling names

diff --git a/configure.ac b/configure.ac
index d90be0f..c4dea3b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@
 
 AC_PREREQ(2.57)
 AC_INIT([xf86-input-joystick],
-        1.2.0,
+        1.2.1,
         [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
         xf86-input-joystick)
 
@@ -44,24 +44,6 @@ AC_PROG_CC
 
 AH_TOP([#include "xorg-server.h"])
 
-#AC_DEFINE(XFree86LOADER,1,[Stub define for loadable drivers])
-#
-#AC_ARG_ENABLE(XINPUT, AS_HELP_STRING([--enable-xinput],
-#              [Build XInput support (default: yes)]),
-#              [XINPUT=$enableval],[XINPUT=yes])
-#AM_CONDITIONAL(XINPUT, test "x$XINPUT" = "xyes")
-#if test "x$XINPUT" = "xyes" ; then
-#    AC_DEFINE(XINPUT,1,[Enable XInput support])
-#fi
-#
-#AC_ARG_ENABLE(XKB, AS_HELP_STRING([--enable-xkb],
-#              [Build XKB support (default: yes)]),
-#              [XKB=$enableval],[XKB=yes])
-#AM_CONDITIONAL(XKB, test "x$XKB" = "xyes")
-#if test "x$XKB" = "xyes" ; then
-#    AC_DEFINE(XKB,1,[Enable XKB support])
-#fi
-
 case $host_os in
   linux*)
     IS_LINUX="yes"
@@ -72,9 +54,9 @@ case $host_os in
     ;;
 
   *)
-    AC_MSG_ERROR([Your operating system is not supported by the joystick driver.
-                  Contact xorg@lists.freedesktop.org if you are interested in
-                  porting it.])
+    AC_MSG_ERROR([Your operating system is not supported by the joystick
+                  driver. Contact xorg@lists.freedesktop.org if you are 
+                  interested in porting it.])
     ;;
 esac
 AM_CONDITIONAL(LINUX, [test "x$IS_LINUX" = xyes])
@@ -82,7 +64,8 @@ AM_CONDITIONAL(BSD, [test "x$IS_BSD" = xyes])
 
 AC_ARG_WITH(xorg-module-dir,
             AC_HELP_STRING([--with-xorg-module-dir=DIR],
-                           [Default xorg module directory [[default=$libdir/xorg/modules]]]),
+                           [Default xorg module directory 
+                           [[default=$libdir/xorg/modules]]]),
             [moduledir="$withval"],
             [moduledir="$libdir/xorg/modules"])
 inputdir=${moduledir}/input
@@ -93,7 +76,8 @@ XORG_DRIVER_CHECK_EXT(RANDR, randrproto)
 XORG_DRIVER_CHECK_EXT(XINPUT, inputproto)
 
 # Checks for pkg-config packages
-PKG_CHECK_MODULES(XORG, [xorg-server >= 1.0.99.901] xproto $REQUIRED_MODULES)
+PKG_CHECK_MODULES(XORG, 
+               [xorg-server >= 1.0.99.901] xproto $REQUIRED_MODULES)
 sdkdir=$(pkg-config --variable=sdkdir xorg-server)
 
 CFLAGS="$CFLAGS $XORG_CFLAGS "' -I$(top_srcdir)/src'
diff --git a/man/joystick.man b/man/joystick.man
index 2ddd273..9e1673f 100644
--- a/man/joystick.man
+++ b/man/joystick.man
@@ -13,7 +13,8 @@ joystick \- Joystick input driver
 .fi
 .SH DESCRIPTION
 .B joystick
-is an __xservername__ input driver for Joysticks, using either Linux\'s joystick devices or *BSD\'s uhid devices.
+is an __xservername__ input driver for Joysticks, using either Linux\'s
+joystick devices or *BSD\'s uhid devices.
 
 .SH SUPPORTED HARDWARE
 In general, every by the kernel supported joystick should be supported through the
diff --git a/src/Makefile.am b/src/Makefile.am
index b64ebb9..2987e21 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,7 +32,7 @@
     			       jstk_axis.c jstk_axis.h \
     			       jstk_options.c jstk_options.h
 
-BSD_SRCS = bsd_jstk.c
+BSD_SRCS   = bsd_jstk.c
 LINUX_SRCS = linux_jstk.c
 
 if BSD
diff --git a/src/jstk.c b/src/jstk.c
index eb2e14d..5cdc756 100644
--- a/src/jstk.c
+++ b/src/jstk.c
@@ -35,10 +35,7 @@
 #include <exevents.h>		/* Needed for InitValuator/Proximity stuff */
 
 #include <math.h>
-
-#ifdef XFree86LOADER
 #include <xf86Module.h>
-#endif
 
 
 #include "jstk.h"
@@ -123,7 +120,7 @@ jstkReadProc(LocalDevicePtr local)
     switch (priv->button[number].mapping) {
       case MAPPING_BUTTON:
         if (priv->mouse_enabled == TRUE) {
-          xf86PostButtonEvent(local->dev, 0, priv->button[number].value,
+          xf86PostButtonEvent(local->dev, 0, priv->button[number].buttonnumber,
             priv->button[number].pressed, 0, 0);
         }
         break;
@@ -133,7 +130,7 @@ jstkReadProc(LocalDevicePtr local)
       case MAPPING_ZX:
       case MAPPING_ZY:
         if (priv->button[number].pressed == 0) /* If button was released */
-          priv->button[number].temp = 1.0;     /* Reset speed counter */
+          priv->button[number].currentspeed = 1.0;     /* Reset speed counter */
         else if (priv->mouse_enabled == TRUE)
           jstkStartButtonAxisTimer(local, number);
         break;
@@ -160,7 +157,7 @@ jstkReadProc(LocalDevicePtr local)
         for (i=0; i<MAXAXES; i++) {
           if ((priv->button[i].pressed) && 
               (priv->button[i].mapping == MAPPING_SPEED_MULTIPLY))
-            priv->amplify *= ((float)priv->button[i].value) / 1000.0f;
+            priv->amplify *= priv->button[i].amplify;
         }
         DBG(2, ErrorF("Global amplify is now %.3f\n", priv->amplify));
 
@@ -213,7 +210,7 @@ jstkReadProc(LocalDevicePtr local)
       case TYPE_BYVALUE:
       case TYPE_ACCELERATED:
         if (priv->axis[number].value == 0) /* When axis was released */
-          priv->axis[number].temp = 1.0;   /* Release speed counter */
+          priv->axis[number].currentspeed = 1.0;   /* Release speed counter */
 
         if (priv->mouse_enabled == TRUE)
           jstkStartAxisTimer(local, number);
@@ -337,16 +334,6 @@ jstkDeviceControlProc(DeviceIntPtr       pJstk,
 /*
  ***************************************************************************
  *
- * Dynamic loading functions
- *
- ***************************************************************************
- */
-#ifdef XFree86LOADER
-
-
-/*
- ***************************************************************************
- *
  * jstkCorePreInit --
  *
  * Called when a device will be instantiated
@@ -406,27 +393,27 @@ jstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags)
 
     /* Initialize default mappings */
     for (i=0; i<MAXAXES; i++) {
-      priv->axis[i].value     = 0;
-      priv->axis[i].deadzone  = 1000;
-      priv->axis[i].type      = TYPE_BYVALUE;
-      priv->axis[i].mapping   = MAPPING_NONE;
-      priv->axis[i].temp      = 0.0f;
-      priv->axis[i].amplify   = 1.0f;
+      priv->axis[i].value        = 0;
+      priv->axis[i].deadzone     = 1000;
+      priv->axis[i].type         = TYPE_BYVALUE;
+      priv->axis[i].mapping      = MAPPING_NONE;
+      priv->axis[i].currentspeed = 0.0f;
+      priv->axis[i].amplify      = 1.0f;
     }
     for (i=0; i<MAXBUTTONS; i++) {
-      priv->button[i].pressed = 0;
-      priv->button[i].value   = 0;
-      priv->button[i].mapping = MAPPING_NONE;
-      priv->button[i].temp    = 1.0f;
+      priv->button[i].pressed      = 0;
+      priv->button[i].buttonnumber = 0;
+      priv->button[i].mapping      = MAPPING_NONE;
+      priv->button[i].currentspeed = 1.0f;
     }
 
     /* First three joystick buttons generate mouse clicks */
-    priv->button[0].mapping = MAPPING_BUTTON;
-    priv->button[0].value   = 1;
-    priv->button[1].mapping = MAPPING_BUTTON;
-    priv->button[1].value   = 2;
-    priv->button[2].mapping = MAPPING_BUTTON;
-    priv->button[2].value   = 3;
+    priv->button[0].mapping      = MAPPING_BUTTON;
+    priv->button[0].buttonnumber = 1;
+    priv->button[1].mapping      = MAPPING_BUTTON;
+    priv->button[1].buttonnumber = 2;
+    priv->button[2].mapping      = MAPPING_BUTTON;
+    priv->button[2].buttonnumber = 3;
 
     /* Two axes by default */
     priv->axis[0].type      = TYPE_BYVALUE;
@@ -470,8 +457,8 @@ jstkCorePreInit(InputDriverPtr drv, IDevPtr dev, int flags)
       if (s != NULL) {
         jstkParseButtonOption(s, priv, i, local->name);
       }
-      DBG(1, xf86Msg(X_CONFIG, "Button %d mapped to %d (value=%d)\n", i+1, 
-                     priv->button[i].mapping, priv->button[i].value));
+      DBG(1, xf86Msg(X_CONFIG, "Button %d mapped to %d\n", i+1, 
+                     priv->button[i].mapping));
     }
 
     /* Process button mapping options */
@@ -621,5 +608,3 @@ _X_EXPORT XF86ModuleData joystickModuleData = {
     jstkDriverPlug,
     jstkDriverUnplug
 };
-
-#endif /* XFree86LOADER */
diff --git a/src/jstk.h b/src/jstk.h
index 1728a64..7a01fcb 100644
--- a/src/jstk.h
+++ b/src/jstk.h
@@ -44,61 +44,67 @@
  **/
 
 #if DEBUG
-extern int      debug_level;
-#define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
+    extern int      debug_level;
+    #define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
 #else
-#define DBG(lvl, f)
+    #define DBG(lvl, f)
 #endif
 
 
-
-#define MAXBUTTONS 32
-#define MAXAXES 32
-#define MAXKEYSPERBUTTON 4
-
-typedef enum {
-    TYPE_NONE,
+typedef enum _JOYSTICKTYPE{
+    TYPE_NONE,        /* Axis value is not relevant */
     TYPE_BYVALUE,     /* Speed of cursor is relative to amplitude */
     TYPE_ACCELERATED, /* Speed is accelerated */
     TYPE_ABSOLUTE     /* The amplitude defines the cursor position */
 } JOYSTICKTYPE;
 
-typedef enum {
-    MAPPING_NONE=0,
-    MAPPING_X,
-    MAPPING_Y,
-    MAPPING_ZX,
-    MAPPING_ZY,
-    MAPPING_BUTTON,
-    MAPPING_KEY,
-    MAPPING_SPEED_MULTIPLY,
-    MAPPING_DISABLE,
-    MAPPING_DISABLE_MOUSE,
-    MAPPING_DISABLE_KEYS
-} JOYSTICKMAPPING ;
-
-
-typedef struct
-{
-    int   value;
-    int   deadzone;
-    float temp,amplify;
-    JOYSTICKTYPE type;
+typedef enum _JOYSTICKMAPPING{
+    MAPPING_NONE,           /* Nothing */
+    MAPPING_X,              /* X-Axis */
+    MAPPING_Y,              /* Y-Axis */
+    MAPPING_ZX,             /* Horizontal scrolling */
+    MAPPING_ZY,             /* Vertical scrolling */
+    MAPPING_BUTTON,         /* Mouse button */
+    MAPPING_KEY,            /* Keyboard event */
+    MAPPING_SPEED_MULTIPLY, /* Will amplify all axis movement */
+    MAPPING_DISABLE,        /* Disable mouse and key events */
+    MAPPING_DISABLE_MOUSE,  /* Disable only mouse events */
+    MAPPING_DISABLE_KEYS    /* Disable only key events */
+} JOYSTICKMAPPING;
+
+
+typedef struct _AXIS {
+    JOYSTICKTYPE    type;
     JOYSTICKMAPPING mapping;
+    int             value;
+    int             deadzone;
+    union {
+        float       currentspeed;
+        float       previousposition;
+    };
+    float           amplify;
 } AXIS;
 
-typedef struct
-{
-   char pressed;
-   int value;
-   unsigned int keys[MAXKEYSPERBUTTON];
-   float temp;
+#define MAXKEYSPERBUTTON 4
+
+typedef struct _BUTTON {
    JOYSTICKMAPPING mapping;
+   char pressed;
+   union {
+       int buttonnumber;    /* MAPPING_BUTTON */
+       struct {
+           float amplify;       /* MAPPING_X/Y/ZX/ZY, 
+                                   MAPPING_SPEED_MULTIPLY */
+           float currentspeed;  /* MAPPING_X/Y/ZX/ZY */
+       };
+       unsigned int keys[MAXKEYSPERBUTTON]; /* MAPPING_KEY */
+   };
 } BUTTON;
 
+#define MAXBUTTONS 32
+#define MAXAXES 32
 
-typedef struct
-{
+typedef struct _JoystickDevRec {
     int          fd;             /* Actual file descriptor */
     void         *devicedata;    /* Extra platform device dependend data */
     char         *device;        /* Name of the device */
@@ -115,5 +121,4 @@ typedef struct
     unsigned char axes, buttons;         /* Number of axes and buttons */
 } JoystickDevRec, *JoystickDevPtr;
 
-
 #endif
diff --git a/src/jstk_axis.c b/src/jstk_axis.c
index 95a1894..d71dc9b 100644
--- a/src/jstk_axis.c
+++ b/src/jstk_axis.c
@@ -89,9 +89,9 @@ jstkAxisTimer(OsTimerPtr        timer,
 
     } else if (axis->type == TYPE_ACCELERATED) {
       /* Stop to accelerate at a certain speed */
-      if (axis->temp < 100.0f) axis->temp *= 1.15f;
+      if (axis->currentspeed < 100.0f) axis->currentspeed *= 1.15f;
 
-      p1 = (axis->temp - 0.1f) * (float)NEXTTIMER / 180.0f;
+      p1 = (axis->currentspeed - 0.1f) * (float)NEXTTIMER / 180.0f;
       p2 = p1 / 8.0f;
     }
     if (axis->value < 0) {
@@ -124,9 +124,9 @@ jstkAxisTimer(OsTimerPtr        timer,
     float p1;
     float p2;
 
-    if (priv->button[i].temp < 100.0f) priv->button[i].temp *= 1.15f;
-    p1 = (priv->button[i].temp - 0.1) * (float)NEXTTIMER / 180.0f *
-         ((float)priv->button[i].value) / 1000.0f;
+    if (priv->button[i].currentspeed < 100.0f) priv->button[i].currentspeed *= 1.15f;
+    p1 = (priv->button[i].currentspeed - 0.1) * (float)NEXTTIMER / 180.0f *
+         priv->button[i].amplify;
     p1 *= priv->amplify;
     p2 = p1 / 8.0f;
 
@@ -263,7 +263,7 @@ jstkStartButtonAxisTimer(LocalDevicePtr device, int number)
   priv->timerrunning = TRUE;
 
   pixel = 1;
-  if (priv->button[number].value < 0) pixel = -1;
+  if (priv->button[number].amplify < 0) pixel = -1;
   switch (priv->button[number].mapping) {
     case MAPPING_X:
       priv->x += pixel;
@@ -326,15 +326,15 @@ jstkHandleAbsoluteAxis(LocalDevicePtr device, int number)
     DBG(5, ErrorF("Relative Position of axis %d: %.2f\n", i, rel));
 
     /* Calculate difference to previous position on screen in pixels */
-    dif = (int)(rel - priv->axis[i].temp + 0.5f);
+    dif = (int)(rel - priv->axis[i].previousposition + 0.5f);
     if ((dif >= 1)||(dif <= -1)) {
       if (priv->axis[i].mapping == MAPPING_X) {
         x += (dif);
-        priv->axis[i].temp += (float)dif;
+        priv->axis[i].previousposition += (float)dif;
       }
       if (priv->axis[i].mapping == MAPPING_Y) {
         y += (int)(dif);
-        priv->axis[i].temp += (float)dif;
+        priv->axis[i].previousposition += (float)dif;
       }
     }
   }
diff --git a/src/jstk_hw.h b/src/jstk_hw.h
index 2a270e8..5e8988c 100644
--- a/src/jstk_hw.h
+++ b/src/jstk_hw.h
@@ -24,7 +24,7 @@
 #ifndef _LINUX_JSTK_H_INCLUDED_
 #define _LINUX_JSTK_H_INCLUDED_
 
-typedef enum {
+typedef enum _JOYSTICKEVENT {
     EVENT_NONE=0,
     EVENT_BUTTON,
     EVENT_AXIS
diff --git a/src/jstk_options.c b/src/jstk_options.c
index c7a4f39..191cb24 100644
--- a/src/jstk_options.c
+++ b/src/jstk_options.c
@@ -95,17 +95,17 @@ jstkParseButtonOption(const char* org,
   if (strcmp(param, "none") == 0) {
     button->mapping = MAPPING_NONE;
   } else if (sscanf(param, "button=%d", &value) == 1) {
-    button->mapping = MAPPING_BUTTON;
-    button->value   = value;
+    button->mapping      = MAPPING_BUTTON;
+    button->buttonnumber = value;
   } else if (sscanf(param, "axis=%15s", p) == 1) {
     button->mapping = jstkGetAxisMapping(&fvalue, p, name);
-    button->value = (int)(fvalue*1000.0);
+    button->amplify = fvalue;
     if (button->mapping == MAPPING_NONE)
       xf86Msg(X_WARNING, "%s: error parsing axis: %s.\n", 
               name, p);
   } else if (sscanf(param, "amplify=%f", &fvalue) == 1) {
     button->mapping = MAPPING_SPEED_MULTIPLY;
-    button->value = (int)(fvalue*1000.0);
+    button->amplify = fvalue;
   } else if (sscanf(param, "key=%30s", p) == 1) {
     char *current, *next;
     current = p;

commit 886e418b89ac673df3e4be0f7a4b1b8c648cad80
Author: Sascha Hlusiak <saschahlusiak@arcor.de>
Date:   Thu Apr 12 18:12:29 2007 -0400

    Wrapped enums and structs in typedefs
    
    Removed xisb.h include, since we are not going to need it.

diff --git a/src/bsd_jstk.c b/src/bsd_jstk.c
index b1d0602..0454528 100644
--- a/src/bsd_jstk.c
+++ b/src/bsd_jstk.c
@@ -49,14 +49,14 @@
 
 
 struct jstk_bsd_hid_data {
-  int dlen;                                /* Length of one data chunk */
-  char *data_buf;                          /* Data buffer with right size */
-  struct hid_item axis_item[MAXAXES];      /* Axis HID items */
-  struct hid_item button_item[MAXBUTTONS]; /* Button HID items */
-  struct hid_item hat_item[MAXAXES];       /* HID items for hats */
-  int hats;                                /* Number of hats */
-  int hotdata;                             /* Is unprocessed data available
-                                              in data_buf? */
+    int dlen;                                /* Length of one data chunk */
+    char *data_buf;                          /* Data buffer with right size */
+    struct hid_item axis_item[MAXAXES];      /* Axis HID items */
+    struct hid_item button_item[MAXBUTTONS]; /* Button HID items */
+    struct hid_item hat_item[MAXAXES];       /* HID items for hats */
+    int hats;                                /* Number of hats */
+    int hotdata;                             /* Is unprocessed data available
+                                                in data_buf? */
 };
 
 
@@ -230,7 +230,7 @@ jstkCloseDevice(JoystickDevPtr joystick)
 
 int
 jstkReadData(JoystickDevPtr joystick,
-             enum JOYSTICKEVENT *event,
+             JOYSTICKEVENT *event,
              int *number)
 {
   int j,d;
@@ -253,6 +253,7 @@ jstkReadData(JoystickDevPtr joystick,
   for (j=0; j<joystick->axes - (bsddata->hats * 2); j++)
     {
       d = hid_get_data(bsddata->data_buf, &bsddata->axis_item[j]);
+      /* Scale the range to our expected range of -32768 to 32767 */
       d = d - (bsddata->axis_item[j].logical_maximum 
                - bsddata->axis_item[j].logical_minimum) / 2;
       d = d * 65536 / (bsddata->axis_item[j].logical_maximum 
diff --git a/src/jstk.c b/src/jstk.c
index b2ab280..eb2e14d 100644
--- a/src/jstk.c
+++ b/src/jstk.c
@@ -6,15 +6,15 @@
  * documentation for any purpose is  hereby granted without fee, provided that
  * the  above copyright   notice appear  in   all  copies and  that both  that
  * copyright  notice   and   this  permission   notice  appear  in  supporting
- * documentation, and that   the  name of  Sascha   Hlusiak  not  be  used  in
+ * documentation, and that  the  names  of copyright holders not  be  used  in
  * advertising or publicity pertaining to distribution of the software without
- * specific,  written      prior  permission.     Sascha   Hlusiak   makes  no
+ * specific,  written      prior  permission.  The copyright holders  make  no
  * representations about the suitability of this software for any purpose.  It



Reply to: