On Wed, Feb 12, 2014 at 11:02 AM, Egbert Eich <e...@freedesktop.org> 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;
> +#define LIMIT_HIGH_PRESSURE_COUNTER 3
> +#define  LIMIT_LOW_PRESSURE 40 /* percentage of max value */

You could probably increase the first and decrease the latter and
still maintain accuracy. A LIMIT_LOW_PRESSURE of 20 would catch more
pens that are beginning to go bad, and as long of
LIMIT_HIGH_PRESSURE_COUNTER were increased you shouldn't really see an
increase in false-positives (10 consecutive high-pressure events, for
instance, would filter all but the most pathological cases of repeated
"jabs") or decrease in false-negatives (from what I understand, the
reported "zero pressure" value simply drifts up as the pen wears).

> +
> +
> +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);

I second Peter's suggestion for a wiki link here. Its an elegant way
to effectively communicate the condition.

> +                       }
> +               }
> +       }
> +       /* 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);
> +

I would remove this if-statement and the associated log message
entirely. On the odd chance the user is looking at the logs in the
first place, an "oops, I might be wrong" message isn't exactly
enlightening :D

> +               /* 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

Reply via email to