The rest of the driver tries to split USB and ISDV4 interface and specifics
into the matching source files, let's do the same with the probing.

Signed-off-by: Peter Hutterer <[email protected]>
---
 src/wcmISDV4.c          |   79 ++++++++++++++++++++++++++++++++++++++
 src/wcmUSB.c            |   29 ++++++++++++++
 src/wcmValidateDevice.c |   96 +++--------------------------------------------
 src/xf86Wacom.h         |    3 +
 4 files changed, 117 insertions(+), 90 deletions(-)

diff --git a/src/wcmISDV4.c b/src/wcmISDV4.c
index f705027..c18fc3a 100644
--- a/src/wcmISDV4.c
+++ b/src/wcmISDV4.c
@@ -21,6 +21,7 @@
 #include <config.h>
 #endif
 
+#include <linux/serial.h>
 #include "xf86Wacom.h"
 #include <xf86_OSproc.h>
 #include "wcmFilter.h"
@@ -592,4 +593,82 @@ static int wcmWaitForTablet(int fd, char* answer, int size)
 
        return maxtry;
 }
+
+/**
+ * Query the device's fd for the key bits and the tablet ID. Returns the ID
+ * on success or 0 on failure.
+ * For serial devices, we set the BTN_TOOL_DOUBLETAP etc. bits based on the
+ * device ID. This matching only works for wacom devices (serial ID of
+ * WACf), all others are simply assumed to be pen + erasor.
+ */
+int isdv4ProbeKeys(LocalDevicePtr local, unsigned long *keys)
+{
+       int id, i;
+       int tablet_id = 0;
+       struct serial_struct tmp;
+       const char *device = xf86SetStrOption(local->options, "Device", NULL);
+
+       if (ioctl(local->fd, TIOCGSERIAL, &tmp) < 0)
+               return 0;
+
+       /* check device name for ID first */
+       if (sscanf(local->name, "WACf%x", &id) <= 1)
+       {
+               /* id in file sys/class/tty/%str/device/id */
+               FILE *file;
+               char sysfs_id[256];
+               char *str = strstr(device, "ttyS");
+               snprintf(sysfs_id, sizeof(sysfs_id),
+                               "/sys/class/tty/%s/device/id", str);
+               file = fopen(sysfs_id, "r");
+
+               /* return true since it falls to default */
+               if (file)
+               {
+                       /* make sure we fall to default */
+                       if (fscanf(file, "WACf%x\n", &id) <= 0)
+                               id = 0;
+
+                       fclose(file);
+               }
+       }
+
+       /* we have tried memset. it doesn't work */
+       for (i=0; i<NBITS(KEY_MAX); i++)
+               keys[i] = 0;
+
+       /* default to penabled */
+       keys[LONG(BTN_TOOL_PEN)] |= BIT(BTN_TOOL_PEN);
+       keys[LONG(BTN_TOOL_RUBBER)] |= BIT(BTN_TOOL_RUBBER);
+
+       /* id < 0x008 are only penabled */
+       if (id > 0x007)
+               keys[LONG(BTN_TOOL_DOUBLETAP)] |= BIT(BTN_TOOL_DOUBLETAP);
+       if (id > 0x0a)
+               keys[LONG(BTN_TOOL_TRIPLETAP)] |= BIT(BTN_TOOL_TRIPLETAP);
+
+       /* no pen 2FGT */
+       if (id == 0x010)
+       {
+               keys[LONG(BTN_TOOL_PEN)] &= ~BIT(BTN_TOOL_PEN);
+               keys[LONG(BTN_TOOL_RUBBER)] &= ~BIT(BTN_TOOL_RUBBER);
+       }
+
+       /* 0x9a and 0x9f are only detected by communicating
+        * with device.  This means tablet_id will be updated/refined
+        * at later stage and true knowledge of capacitive
+        * support will be delayed until that point.
+        */
+       if (id >= 0x0 && id <= 0x7)
+               tablet_id = 0x90;
+       else if (id >= 0x8 && id <= 0xa)
+               tablet_id = 0x93;
+       else if (id >= 0xb && id <= 0xe)
+               tablet_id = 0xe3;
+       else if (id == 0x10)
+               tablet_id = 0xe2;
+
+       return tablet_id;
+}
+
 /* vim: set noexpandtab shiftwidth=8: */
diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 01f36c6..2acce02 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -1047,4 +1047,33 @@ static void usbParseChannel(LocalDevicePtr local, int 
channel)
        /* dispatch event */
        wcmEvent(common, channel, ds);
 }
+
+/**
+ * Query the device's fd for the key bits and the tablet ID. Returns the ID
+ * on success or 0 on failure.
+ * For USB devices, we simply copy the information the kernel gives us.
+ */
+int usbProbeKeys(LocalDevicePtr local, unsigned long *keys)
+{
+       struct input_id wacom_id;
+
+       if (ioctl(local->fd, EVIOCGBIT(EV_KEY, (sizeof(unsigned long)
+                                               * NBITS(KEY_MAX))), keys) < 0)
+       {
+               xf86Msg(X_ERROR, "%s: wcmDeviceTypeKeys unable to "
+                               "ioctl USB key bits.\n", local->name);
+               return 0;
+       }
+
+       if (ioctl(local->fd, EVIOCGID, &wacom_id) < 0)
+       {
+               xf86Msg(X_ERROR, "%s: wcmDeviceTypeKeys unable to "
+                               "ioctl Device ID.\n", local->name);
+               return 0;
+       }
+
+       return wacom_id.product;
+}
+
+
 /* vim: set noexpandtab shiftwidth=8: */
diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c
index 918e4f4..86a6351 100644
--- a/src/wcmValidateDevice.c
+++ b/src/wcmValidateDevice.c
@@ -25,7 +25,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <linux/serial.h>
 
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
 
@@ -170,19 +169,13 @@ Bool wcmIsAValidType(const char* type, unsigned long* 
keys)
        return ret;
 }
 
-/* Choose valid types according to device ID.
-   For USB devices, we simply copy the information the kernel gives us. For
-   serial devices, we set the BTN_TOOL_DOUBLETAP etc. bits based on the
-   device ID. This matching only works for wacom devices (serial ID of
-   WACf), all others are simply assumed to be pen + erasor.
- */
+/* Choose valid types according to device ID. */
 int wcmDeviceTypeKeys(LocalDevicePtr local, unsigned long* keys,
                      int* tablet_id)
 {
        int ret = 1;
        int fd = -1;
        char* device;
-       struct serial_struct tmp;
 
        device = xf86SetStrOption(local->options, "Device", NULL);
 
@@ -194,92 +187,15 @@ int wcmDeviceTypeKeys(LocalDevicePtr local, unsigned 
long* keys,
                return 0;
        }
 
-       *tablet_id = 0;
+       local->fd = fd;
 
        /* serial ISDV4 devices */
-       if (ioctl(fd, TIOCGSERIAL, &tmp) == 0)
-       {
-               int id, i;
-
-               /* check device name for ID first */
-               if (sscanf(local->name, "WACf%x", &id) <= 1)
-               {
-                       /* id in file sys/class/tty/%str/device/id */
-                       FILE *file;
-                       char sysfs_id[256];
-                       char *str = strstr(device, "ttyS");
-                       snprintf(sysfs_id, sizeof(sysfs_id),
-                               "/sys/class/tty/%s/device/id", str);
-                       file = fopen(sysfs_id, "r");
-
-                       /* return true since it falls to default */
-                       if (file)
-                       {
-                               /* make sure we fall to default */
-                               if (fscanf(file, "WACf%x\n", &id) <= 0)
-                                       id = 0;
-
-                               fclose(file);
-                       }
-               }
-
-               /* we have tried memset. it doesn't work */
-               for (i=0; i<NBITS(KEY_MAX); i++)
-                       keys[i] = 0;
-
-               /* default to penabled */
-               keys[LONG(BTN_TOOL_PEN)] |= BIT(BTN_TOOL_PEN);
-               keys[LONG(BTN_TOOL_RUBBER)] |= BIT(BTN_TOOL_RUBBER);
-
-               /* id < 0x008 are only penabled */
-               if (id > 0x007)
-                       keys[LONG(BTN_TOOL_DOUBLETAP)] |= 
BIT(BTN_TOOL_DOUBLETAP);
-               if (id > 0x0a)
-                       keys[LONG(BTN_TOOL_TRIPLETAP)] |= 
BIT(BTN_TOOL_TRIPLETAP);
-
-               /* no pen 2FGT */
-               if (id == 0x010)
-               {
-                       keys[LONG(BTN_TOOL_PEN)] &= ~BIT(BTN_TOOL_PEN);
-                       keys[LONG(BTN_TOOL_RUBBER)] &= ~BIT(BTN_TOOL_RUBBER);
-               }
+       *tablet_id = isdv4ProbeKeys(local, keys);
+       if (!*tablet_id) /* USB devices */
+               *tablet_id = usbProbeKeys(local, keys);
 
-               /* 0x9a and 0x9f are only detected by communicating
-                * with device.  This means tablet_id will be updated/refined
-                * at later stage and true knowledge of capacitive
-                * support will be delayed until that point.
-                */
-               if (id >= 0x0 && id <= 0x7)
-                       *tablet_id = 0x90;
-               else if (id >= 0x8 && id <= 0xa)
-                       *tablet_id = 0x93;
-               else if (id >= 0xb && id <= 0xe)
-                       *tablet_id = 0xe3;
-               else if (id == 0x10)
-                       *tablet_id = 0xe2;
-       }
-       else /* USB devices */
-       {
-               struct input_id wacom_id;
-
-               if (ioctl(fd, EVIOCGBIT(EV_KEY, (sizeof(unsigned long)
-                        * NBITS(KEY_MAX))), keys) < 0)
-               {
-                       xf86Msg(X_ERROR, "%s: wcmDeviceTypeKeys unable to "
-                               "ioctl USB key bits.\n", local->name);
-                       ret = 0;
-               }
-
-               if (ioctl(fd, EVIOCGID, &wacom_id) < 0)
-               {
-                       xf86Msg(X_ERROR, "%s: wcmDeviceTypeKeys unable to "
-                               "ioctl Device ID.\n", local->name);
-                       ret = 0;
-               }
-               else
-                       *tablet_id = wacom_id.product;
-       }
        close(fd);
+       local->fd = -1;
        return ret;
 }
 
diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h
index 802ea9e..e17c4be 100644
--- a/src/xf86Wacom.h
+++ b/src/xf86Wacom.h
@@ -184,6 +184,9 @@ extern int wcmSetProperty(DeviceIntPtr dev, Atom property, 
XIPropertyValuePtr pr
 extern void InitWcmDeviceProperties(LocalDevicePtr local);
 #endif
 
+/* Device probing */
+int isdv4ProbeKeys(LocalDevicePtr local, unsigned long *keys);
+int usbProbeKeys(LocalDevicePtr local, unsigned long *keys);
 
 /****************************************************************************/
 #endif /* __XF86WACOM_H */
-- 
1.6.6.1


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to