On Wed, Feb 12, 2014 at 08:02:12PM +0100, Egbert Eich wrote: > 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;
I'd make that unsigned, so overflow is defined, even if it's never going to happen. bonus points for whoever does though :) > +#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 " bamboos have a serial of -1, so this should be printed as %d. > + "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, " Fwiw, this is a complex but obscure enough issue that's hard to explain in two sentences. It will trigger false positives that result in bug reports, especially with messages like "maybe not broken" - that's probably quite confusing to users. So how about changing the warning to include a link to a wiki page that explains what the warning means and what the effect is? Something like: "High initial pressure detected, your tool may be worn out. For more info, see http://linuxwacom.sourceforge.net.." Then we can be as verbose as needed and have an easy way to avoid bugreports, and to close them quickly when they are erroneously reported. Cheers, Peter > + "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 > ------------------------------------------------------------------------------ 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