From: Egbert Eich <e...@suse.com>

Tool type detection is done in two places: early in usbDispatchEvents()
by calling usbInitToolType() and later on in the same function when the
events are parsed.
usbInitToolType() is used to set (wcmUSBData*)->wcmDeviceType, the
detection that happens later when the events are parsed sets
(WacomDeviceState).device_type. These variables are matched against each
to find the right channel for a device.
If the algorithms used for both set of tool type detection diverge
undesirable effects may happen. Therefore it is advisable to determine the
tool type only once ie. in usbInitToolType() and copy the result to
(WacomDeviceState).device_type if this value is unset.
Since we now have brought the algorithm in usbInitToolType() in sync with
the reset, we delete any duplicate tool type setting.

Signed-off-by: Egbert Eich <e...@suse.com>
---
 src/wcmUSB.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 919aec8..d69f291 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -1078,6 +1078,16 @@ static int usbIdToType(int id)
        return type;
 }
 
+/**
+ * Find the tool type (STYLUS_ID, etc.) based on the device_id or the
+ *  current tool serial number if the device_id is unknown (0).
+ *
+ * Protocol 5 devices report different IDs for different styli and pucks,
+ * Protocol 4 devices simply report STYLUS_DEVICE_ID, etc.
+ *
+ * @device_id id of the device
+ * @return device type
+ */
 static int usbFindDeviceTypeById(int device_id)
 {
        switch (device_id)
@@ -1240,7 +1250,6 @@ static void usbParseAbsMTEvent(WacomCommonPtr common, 
struct input_event *event)
 
                case ABS_MT_TRACKING_ID:
                        ds->proximity = (event->value != -1);
-                       ds->device_type = TOUCH_ID;
                        ds->device_id = TOUCH_DEVICE_ID;
                        ds->sample = (int)GetTimeInMillis();
                        break;
@@ -1283,7 +1292,6 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                case BTN_TOOL_PENCIL:
                case BTN_TOOL_BRUSH:
                case BTN_TOOL_AIRBRUSH:
-                       ds->device_type = STYLUS_ID;
                        /* V5 tools use ABS_MISC to report device_id */
                        if (common->wcmProtocolLevel == WCM_PROTOCOL_4)
                                ds->device_id = STYLUS_DEVICE_ID;
@@ -1294,7 +1302,6 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                        break;
 
                case BTN_TOOL_RUBBER:
-                       ds->device_type = ERASER_ID;
                        /* V5 tools use ABS_MISC to report device_id */
                        if (common->wcmProtocolLevel == WCM_PROTOCOL_4)
                                ds->device_id = ERASER_DEVICE_ID;
@@ -1311,7 +1318,6 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                        DBG(6, common,
                            "USB mouse detected %x (value=%d)\n",
                            event->code, event->value);
-                       ds->device_type = CURSOR_ID;
                        /* V5 tools use ABS_MISC to report device_id */
                        if (common->wcmProtocolLevel == WCM_PROTOCOL_4)
                                ds->device_id = CURSOR_DEVICE_ID;
@@ -1329,7 +1335,6 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                                        DBG(6, common,
                                            "USB 1FG Touch detected %x 
(value=%d)\n",
                                            event->code, event->value);
-                                       ds->device_type = TOUCH_ID;
                                        ds->device_id = TOUCH_DEVICE_ID;
                                        ds->proximity = event->value;
                                }
@@ -1343,7 +1348,6 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                                DBG(6, common,
                                    "USB Pad detected %x (value=%d)\n",
                                event->code, event->value);
-                               ds->device_type = PAD_ID;
                                ds->device_id = PAD_DEVICE_ID;
                                ds->proximity = (event->value != 0);
                                break;
@@ -1354,7 +1358,6 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                        DBG(6, common,
                            "USB Touch detected %x (value=%d)\n",
                            event->code, event->value);
-                       ds->device_type = TOUCH_ID;
                        ds->device_id = TOUCH_DEVICE_ID;
                        ds->proximity = event->value;
                        /* time stamp for 2FGT gesture events */
@@ -1367,7 +1370,6 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                        DBG(6, common,
                            "USB Touch second finger detected %x (value=%d)\n",
                            event->code, event->value);
-                       ds->device_type = TOUCH_ID;
                        ds->device_id = TOUCH_DEVICE_ID;
                        ds->proximity = event->value;
                        /* time stamp for 2GT gesture events */
@@ -1492,7 +1494,7 @@ static int toolTypeToDeviceType(WacomCommonPtr common, 
int type, int code, int v
 
                        case BTN_TOOL_FINGER:
                                if ((common->wcmProtocolLevel != 
WCM_PROTOCOL_GENERIC)
-                                   && !private->wcmUseMT)
+                                   && !private->wcmUseMT)  /* this isn't in 
usbParseKeyEvent() */
                                        return PAD_ID;
                                else
                                        return TOUCH_ID;
-- 
1.8.4.5


------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to