From: Chris Bagwell <ch...@cnpbagwell.com>

There is possible plans to support at least one more "protocol"
for sending events from Linux input devices to xf86-input-wacom
(GENERIC). In preperation for this, switch to enums which allow
using names to indicate totally unrelated protocols.

Also, add better documentation on what Protocol 4 and Protocol 5
really means in wcmUSB.c.

This patch shows that usage of wcmProtocolLevel in
commonDispatchDevice() is questionable (hopefully,
no protocol specific logic needed in common functions) but
that is left for another patch set.

Signed-off-by: Chris Bagwell <ch...@cnpbagwell.com>
---
 src/wcmCommon.c     |    2 +-
 src/wcmConfig.c     |    2 +-
 src/wcmISDV4.c      |    2 +-
 src/wcmUSB.c        |   56 +++++++++++++++++++++++++++++++++++++++-----------
 src/xf86WacomDefs.h |    8 ++++++-
 5 files changed, 53 insertions(+), 17 deletions(-)

diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index 6e9871f..cd550ea 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -1339,7 +1339,7 @@ static void commonDispatchDevice(WacomCommonPtr common, 
unsigned int channel,
        if (IsCursor(priv))
        {
                /* force out-prox when distance is outside 
wcmCursorProxoutDist. */
-               if (common->wcmProtocolLevel == 5)
+               if (common->wcmProtocolLevel == WCM_PROTOCOL_5)
                {
                        if (common->wcmMaxCursorDist > filtered.distance)
                                common->wcmMaxCursorDist = filtered.distance;
diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index 9126ace..6374758 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -102,7 +102,7 @@ static int wcmAllocate(InputInfoPtr pInfo)
 
        common->wcmFlags = RAW_FILTERING_FLAG;   /* various flags */
        common->wcmDevices = priv;
-       common->wcmProtocolLevel = 4;      /* protocol level */
+       common->wcmProtocolLevel = WCM_PROTOCOL_4; /* protocol level */
        common->wcmTPCButton = 0;          /* set Tablet PC button on/off */
        common->wcmCapacity = -1;          /* Capacity is disabled */
        common->wcmCapacityDefault = -1;    /* default to -1 when capacity 
isn't supported */
diff --git a/src/wcmISDV4.c b/src/wcmISDV4.c
index ae14164..2c3ca9a 100644
--- a/src/wcmISDV4.c
+++ b/src/wcmISDV4.c
@@ -313,7 +313,7 @@ static int isdv4Query(InputInfoPtr pInfo, const char* 
query, char* data)
 static void isdv4InitISDV4(WacomCommonPtr common, const char* id, float 
version)
 {
        /* set parameters */
-       common->wcmProtocolLevel = 4;
+       common->wcmProtocolLevel = WCM_PROTOCOL_4;
        /* length of a packet */
        common->wcmPktLength = ISDV4_PKGLEN_TPCPEN;
 
diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 33dd407..414ce52 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -542,7 +542,7 @@ static Bool usbWcmInit(InputInfoPtr pInfo, char* id, float 
*version)
 static void usbInitProtocol5(WacomCommonPtr common, const char* id,
        float version)
 {
-       common->wcmProtocolLevel = 5;
+       common->wcmProtocolLevel = WCM_PROTOCOL_5;
        common->wcmPktLength = sizeof(struct input_event);
        common->wcmCursorProxoutDistDefault 
                        = PROXOUT_INTUOS_DISTANCE;
@@ -558,7 +558,7 @@ static void usbInitProtocol5(WacomCommonPtr common, const 
char* id,
 static void usbInitProtocol4(WacomCommonPtr common, const char* id,
        float version)
 {
-       common->wcmProtocolLevel = 4;
+       common->wcmProtocolLevel = WCM_PROTOCOL_4;
        common->wcmPktLength = sizeof(struct input_event);
        common->wcmCursorProxoutDistDefault 
                        = PROXOUT_GRAPHIRE_DISTANCE;
@@ -716,6 +716,9 @@ static int usbParse(InputInfoPtr pInfo, const unsigned 
char* data, int len)
        return common->wcmPktLength;
 }
 
+/* Up to MAX_CHANNEL tools can be tracked concurrently by driver.
+ * Chose a channel to use to track current batch of events.
+ */
 static int usbChooseChannel(WacomCommonPtr common)
 {
        /* figure out the channel to use based on serial number */
@@ -723,14 +726,30 @@ static int usbChooseChannel(WacomCommonPtr common)
        wcmUSBData* private = common->private;
        int serial = private->wcmLastToolSerial;
 
-       if (common->wcmProtocolLevel == 4)
+       if (common->wcmProtocolLevel == WCM_PROTOCOL_4)
        {
-               /* Protocol 4 doesn't support tool serial numbers.
-                * However, we pass finger index into serial
-                * numbers for tablets with multi-touch capabilities
-                * to track individual fingers in proper channels.
-                * serial number 0xf0 is reserved for the pad and is
-                * always the last supported channel (i.e. MAX_CHANNELS-1).
+               /* Protocol 4 devices support only 2 devices being
+                * in proximity at the same time.  This includes
+                * the FINGER tool (PAD device) as well as 1 other tool
+                * (stylus, mouse, finger touch, etc).
+                * There is a special case of Tablet PC that also
+                * suport a 3rd tool (2nd finger touch) to also be
+                * in proximity at same time but this should eventually
+                * go away when its switched to MT events to fix loss of
+                * events.
+                *
+                * Protocol 4 send fixed serial numbers along with events.
+                * Events associated with BTN_TOOL_FINGER (PAD device)
+                * will send serial number of 0xf0 always.
+                * Events associated with BTN_TOOL_TRIPLETAP (2nd finger
+                * touch) send a serial number of 0x02 always.
+                * Events associated with all other BTN_TOOL_*'s will
+                * either send a serial # of 0x01 or we can act as if
+                * they did send that value.
+                *
+                * Since its a fixed mapping, directly convert this to
+                * channels 0 to 2 with last channel always used for
+                * pad devices.
                 */
                if (serial == 0xf0)
                        channel = MAX_CHANNELS-1;
@@ -741,7 +760,18 @@ static int usbChooseChannel(WacomCommonPtr common)
        }
        else if (serial) /* serial number should never be 0 for V5 devices */
        {
-               /* dual input is supported */
+               /* Protocol 5 devices can support tracking 2 or 3
+                * tools at once.  One is the FINGER tool (PAD device)
+                * as well as a stylus and/or mouse.
+                *
+                * Events associated with BTN_TOOL_FINGER (PAD device)
+                * will send serial number of -1 (0xffffffff) always.
+                * Events associated with all other BTN_TOOL_*'s will
+                * send a dynamic serial #.
+                *
+                * Logic here is related to dynamically mapping
+                * serial numbers to a fixed channel #.
+                */
                if (TabletHasFeature(common, WCM_DUALINPUT))
                {
                        /* find existing channel */
@@ -1017,7 +1047,7 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                case BTN_TOOL_AIRBRUSH:
                        ds->device_type = STYLUS_ID;
                        /* V5 tools use ABS_MISC to report device_id */
-                       if (common->wcmProtocolLevel == 4)
+                       if (common->wcmProtocolLevel == WCM_PROTOCOL_4)
                                ds->device_id = STYLUS_DEVICE_ID;
                        ds->proximity = (event->value != 0);
                        DBG(6, common,
@@ -1028,7 +1058,7 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                case BTN_TOOL_RUBBER:
                        ds->device_type = ERASER_ID;
                        /* V5 tools use ABS_MISC to report device_id */
-                       if (common->wcmProtocolLevel == 4)
+                       if (common->wcmProtocolLevel == WCM_PROTOCOL_4)
                                ds->device_id = ERASER_DEVICE_ID;
                        ds->proximity = (event->value != 0);
                        if (ds->proximity)
@@ -1045,7 +1075,7 @@ static void usbParseKeyEvent(WacomCommonPtr common,
                            event->code, event->value);
                        ds->device_type = CURSOR_ID;
                        /* V5 tools use ABS_MISC to report device_id */
-                       if (common->wcmProtocolLevel == 4)
+                       if (common->wcmProtocolLevel == WCM_PROTOCOL_4)
                                ds->device_id = CURSOR_DEVICE_ID;
                        ds->proximity = (event->value != 0);
                        break;
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 2b38860..bf17fb7 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -371,6 +371,12 @@ typedef struct {
        int wcmTapTimeDefault;         /* default minimum time between taps for 
a right click */
 } WacomGesturesParameters;
 
+enum WacomProtocol {
+       WCM_PROTOCOL_GENERIC,
+       WCM_PROTOCOL_4,
+       WCM_PROTOCOL_5
+};
+
 struct _WacomCommonRec 
 {
        /* Do not move device_path, same offset as priv->name. Used by DBG 
macro */
@@ -410,7 +416,7 @@ struct _WacomCommonRec
 
        WacomDevicePtr wcmDevices;   /* list of devices sharing same port */
        int wcmPktLength;            /* length of a packet */
-       int wcmProtocolLevel;        /* 4 for Wacom IV, 5 for Wacom V */
+       int wcmProtocolLevel;        /* Wacom Protocol used */
        float wcmVersion;            /* ROM version */
        int wcmRotate;               /* rotate screen (for TabletPC) */
        int wcmThreshold;            /* Threshold for button pressure */
-- 
1.7.2.3


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to