From: Egbert Eich <e...@suse.com> Worn out pens have an initial pressure != 0. If this condition happens 3 consecutive times warn about it. If the condition doesn't persist, also notify. This condition may also occur intermittently on abusive operation.
Signed-off-by: Egbert Eich <e...@suse.com> --- src/wcmCommon.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/wcmCommon.c b/src/wcmCommon.c index 9b83e72..ec7ea7e 100644 --- a/src/wcmCommon.c +++ b/src/wcmCommon.c @@ -1124,6 +1124,60 @@ setPressureButton(const WacomDevicePtr priv, const WacomDeviceState *ds) return buttons; } +/* + * Broken pen with a broken tip might give high pressure values + * all the time. The following counter count the number of time a high prox-in + * pressure is detected. As soon as a low pressure event is received, the + * value is reset to 0. + */ +static int highProxInPressureCounter = 0; +#define LIMIT_HIGH_PRESSURE_COUNTER 3 +#define LIMIT_LOW_PRESSURE 40 /* percentage of max value */ + + +static void detectPressureIssue(WacomDevicePtr priv, + WacomCommonPtr common, + WacomDeviceStatePtr ds) +{ + int serial = ds->serial_num; + int pressureThreshold = common->wcmMaxZ * LIMIT_LOW_PRESSURE / 100; + + /* detect broken pens which always have high tip pressure */ + if (!priv->oldProximity) + { + if (ds->pressure > pressureThreshold) + { + highProxInPressureCounter++; + + /* seen enough high prox-in pressure events? */ + if (highProxInPressureCounter == LIMIT_HIGH_PRESSURE_COUNTER) + { + LogMessageVerbSigSafe( + X_WARNING, 0, + "%s(%u) has seen an initial pressure (%d) %d times " + "which is too close to the maximum value (%d). " + "Time to change your tool. \n", + priv->pInfo->name, serial, ds->pressure, + highProxInPressureCounter, + common->wcmMaxZ); + } + } + } + /* got a low pressure event? Then the pen is maybe not broken, in fact. */ + if (ds->pressure < pressureThreshold && ds->pressure != 0) { + /* printed a "broken pen" warning before? */ + if (highProxInPressureCounter >= LIMIT_HIGH_PRESSURE_COUNTER) + LogMessageVerbSigSafe( + X_WARNING, 0, + "Tool %s(%u) maybe not broken, " + "even after %d times high prox-in pressure.\n", + priv->pInfo->name, serial, highProxInPressureCounter); + + /* restart counter game */ + highProxInPressureCounter = 0; + } +} + static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, const WacomChannelPtr pChannel, enum WacomSuppressMode suppress) @@ -1206,6 +1260,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)) -- 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