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

Worn out pens have an initial pressure != 0. If this pressure
persists while the pen is in proximity and still exists when
going out of proximity, warn about worn out tool.
Some devices seem to send a zero pressure when going out of
proximity. Thus we record the last pressure when still in
proximity.
Also we count the number of events we have received while in
proximity so the risk of false reports on 'quick taps' is lower.

This condition may also occur intermittently on abusive operation.

Signed-off-by: Egbert Eich <e...@suse.com>
---
Algorithm has been reworked, suggestions have been incorporated.
I'm not sure about the Wiki page, though, it seems that one cannot
link to any but the main page using http://linuxwacom.sourceforge.net.


 src/wcmCommon.c     | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/xf86WacomDefs.h |  3 ++-
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index 209565c..73aeeea 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -1121,6 +1121,50 @@ setPressureButton(const WacomDevicePtr priv, const 
WacomDeviceState *ds)
        return buttons;
 }
 
+/*
+ * Broken pen with a broken tip might give high pressure values
+ * all the time. We want to warn about this. To avoid getting
+ * spurious warnings when the tablet is hit quickly will wait
+ * until the device goes out of proximity and check if the minimum
+ * pressure is still above a threshold of 20 percent of the maximum
+ * pressure. Also we make sure the device has seen a sufficient number
+ * of events while in proximity that it had a chance to see decreasing
+ * pressure values.
+ */
+#define  LIMIT_LOW_PRESSURE 20 /* percentage of max value */
+#define PERCENT_TOLERANCE 10
+#define MIN_EVENT_COUNT 15
+
+static void detectPressureIssue(WacomDevicePtr priv,
+                               WacomCommonPtr common,
+                               WacomDeviceStatePtr ds)
+{
+       /* pen is just going out of proximity */
+       if (priv->oldProximity && !ds->proximity) {
+
+               int pressureThreshold = common->wcmMaxZ * LIMIT_LOW_PRESSURE / 
100;
+               /* check if minPressure has persisted all the time
+                  and is too close to the maximum pressure */
+               if (priv->oldMinPressure > pressureThreshold &&
+                   priv->eventCount > MIN_EVENT_COUNT)
+                       LogMessageVerbSigSafe(
+                               X_WARNING, 0,
+                               "%s(%d) has seen an initial pressure > 0\n\t"
+                               "there is a base pressure of %d which 
persists\n\t"
+                               "while the pen is in proximity and "
+                               "which is too close\n\tto the maximum value 
(%d).\n\t"
+                               "This indicates a worn out pen, "
+                               "Time to change your tool. Also see:\n\t"
+                               "http://linuxwacom.sourceforge.net/Pen_Wear.\n";,
+                               priv->pInfo->name, priv->serial, 
priv->minPressure,
+                               common->wcmMaxZ);
+       } else if (!priv->oldProximity)
+               priv->eventCount = 0;
+
+       priv->oldMinPressure = priv->minPressure;
+       priv->eventCount++;
+}
+
 static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel,
                                 const WacomChannelPtr pChannel,
                                 enum WacomSuppressMode suppress)
@@ -1203,6 +1247,7 @@ static void commonDispatchDevice(WacomCommonPtr common, 
unsigned int channel,
 
        if ((IsPen(priv) || IsTouch(priv)) && common->wcmMaxZ)
        {
+               detectPressureIssue(priv, common, &filtered);
                priv->minPressure = rebasePressure(priv, &filtered);
                filtered.pressure = normalizePressure(priv, &filtered);
                if (IsPen(priv))
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 6de9645..09597a0 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -303,7 +303,8 @@ struct _WacomDeviceRec
        int pPressCurve[FILTER_PRESSURE_RES + 1]; /* pressure curve */
        int nPressCtrl[4];      /* control points for curve */
        int minPressure;        /* the minimum pressure a pen may hold */
-
+       int oldMinPressure;     /* to record the last minPressure before going 
out of proximity */
+       unsigned int eventCount; /* count number of events while in proximity */
        WacomToolPtr tool;         /* The common tool-structure for this device 
*/
 
        int isParent;           /* set to 1 if the device is not 
auto-hotplugged */
-- 
1.8.1.4


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&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