thanks for the updated patch, Ping!
On Wed, Apr 14, 2010 at 02:08:01PM -0700, Ping Cheng wrote:
> From c0919ad91f129d50bfd47d34bfd3664912b65a8f Mon Sep 17 00:00:00 2001
> From: Ping Cheng <[email protected]>
> Date: Wed, 14 Apr 2010 13:37:08 -0700
> Subject: [PATCH] xf86-input-wacom: Normalize pressure sensitivity
>
> Instead of reporting the raw pressure, the normalized pressure from
> 0 to FILTER_PRESSURE_RES (which is 2048) is reported. This is mainly
> to deal with the case where heavily used stylus may have a "pre-loaded"
> initial pressure. This patch checks the in-prox pressure and subtract
> it from the raw pressure to prevent a potential left-click before the
> pen touches the tablet.
>
> Left click threshold and pressure curve are updated accordingly.
>
> Signed-off-by: Ping Cheng <[email protected]>
> ---
> src/wcmCommon.c | 71 +++++++++++++++++++++++++++++++++-----------------
> src/wcmXCommand.c | 2 +-
> src/xf86Wacom.c | 4 +-
> src/xf86WacomDefs.h | 1 +
> tools/xsetwacom.c | 4 +-
> 5 files changed, 53 insertions(+), 29 deletions(-)
>
> diff --git a/src/wcmCommon.c b/src/wcmCommon.c
> index f5a91d4..1d4a90e 100644
> --- a/src/wcmCommon.c
> +++ b/src/wcmCommon.c
> @@ -26,6 +26,10 @@
> #include <xkbsrv.h>
> #include <xf86_OSproc.h>
>
> +/* Tested result for setting the pressure threshold to a reasonable value */
> +#define THRESHOLD_TOLERANCE 125
the tolerance is only used in combination with the FILTER_RES. Can we make it
instead:
#define THRESHOLD_TOLERANCE (FILTER_PRESSURE_RES / 125)
> +#define RATIO_FOR_THRESHOLD 75
same here, as (FILTER_PRESSURE_RES / 75). and then we could just rename it
to DEFAULT_THRESHOLD since that's the purpose it has.
> +
>
> /*****************************************************************************
> * Static functions
>
> ****************************************************************************/
> @@ -1445,18 +1449,47 @@ static void commonDispatchDevice(WacomCommonPtr
> common, unsigned int channel,
>
> if (IsStylus(priv) || IsEraser(priv))
> {
> + /* Instead of reporting the raw pressure, we normalize
> + * the pressure from 0 to FILTER_PRESSURE_RES. This is
> + * mainly to deal with the case where heavily used
> + * stylus may have a "pre-loaded" initial pressure. To
> + * do so, we keep the in-prox pressure and subtract it
> + * from the raw pressure to prevent a potential
> + * left-click before the pen touches the tablet.
> + */
> + double tmpP;
> +
> + /* set the minimum pressure when in prox */
> + if (!priv->oldProximity)
> + priv->minPressure = filtered.pressure;
> + else if (priv->minPressure > filtered.pressure)
> + priv->minPressure = filtered.pressure;
could use min() here too instead of the second if() if you want to.
> +
> + /* normalize pressure to FILTER_PRESSURE_RES */
> + tmpP = (filtered.pressure - priv->minPressure)
> + * FILTER_PRESSURE_RES;
> + tmpP /= common->wcmMaxZ - priv->minPressure;
> + filtered.pressure = (int)tmpP;
> +
> /* set button1 (left click) on/off */
> - if (filtered.pressure >= common->wcmThreshold)
> - filtered.buttons |= button;
> - else
> + if (filtered.pressure < common->wcmThreshold)
> {
> - /* threshold tolerance */
> - int tol = common->wcmMaxZ / 250;
> - if (strstr(common->wcmModel->name, "Intuos4"))
> - tol = common->wcmMaxZ / 125;
> - if (filtered.pressure < common->wcmThreshold -
> tol)
> - filtered.buttons &= ~button;
> + filtered.buttons &= ~button;
> + if (priv->oldButtons & button) /* left click
> was on */
> + {
> + /* threshold tolerance */
> + int tol = FILTER_PRESSURE_RES /
> THRESHOLD_TOLERANCE;
> +
> + /* don't set it off if it is within the
> tolerance
> + and the tolerance is larger than
> threshold */
> + if ((common->wcmThreshold > tol) &&
> + (filtered.pressure >
> common->wcmThreshold - tol))
> + filtered.buttons |= button;
> + }
> }
> + else
> + filtered.buttons |= button;
> +
> /* transform pressure */
> transPressureCurve(priv,&filtered);
> }
> @@ -1601,10 +1634,8 @@ int wcmInitTablet(LocalDevicePtr local, const char*
> id, float version)
> if (common->wcmThreshold <= 0)
> {
> /* Threshold for counting pressure as a button */
> - if (strstr(common->wcmModel->name, "Intuos4"))
> - common->wcmThreshold = common->wcmMaxZ * 3 / 25;
> - else
> - common->wcmThreshold = common->wcmMaxZ * 3 / 50;
> + common->wcmThreshold = FILTER_PRESSURE_RES /
> RATIO_FOR_THRESHOLD;
> +
> xf86Msg(X_PROBED, "%s: using pressure threshold of %d for
> button 1\n",
> local->name, common->wcmThreshold);
> }
> @@ -1645,21 +1676,13 @@ static void transPressureCurve(WacomDevicePtr pDev,
> WacomDeviceStatePtr pState)
> {
> if (pDev->pPressCurve)
> {
> - int p = pState->pressure;
> + /* clip the pressure */
> + int p = max(0, pState->pressure);
>
> - /* clip */
> - p = (p < 0) ? 0 : (p > pDev->common->wcmMaxZ) ?
> - pDev->common->wcmMaxZ : p;
> -
> - /* rescale pressure to FILTER_PRESSURE_RES */
> - p = (p * FILTER_PRESSURE_RES) / pDev->common->wcmMaxZ;
> + p = min(FILTER_PRESSURE_RES, p);
>
> /* apply pressure curve function */
> p = pDev->pPressCurve[p];
> -
> - /* scale back to wcmMaxZ */
> - pState->pressure = (p * pDev->common->wcmMaxZ) /
> - FILTER_PRESSURE_RES;
> }
> }
>
> diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c
> index c8e4f5f..40207a3 100644
> --- a/src/wcmXCommand.c
> +++ b/src/wcmXCommand.c
> @@ -636,7 +636,7 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property,
> XIPropertyValuePtr prop,
>
> value = *(CARD32*)prop->data;
>
> - if ((value < 1) || (value > common->wcmMaxZ))
> + if ((value < 1) || (value > FILTER_PRESSURE_RES))
> return BadValue;
>
> if (!checkonly)
> diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c
> index efca491..3f951df 100644
> --- a/src/xf86Wacom.c
> +++ b/src/xf86Wacom.c
> @@ -767,12 +767,12 @@ static int wcmRegisterX11Devices (LocalDevicePtr local)
> /* Rotation rotates the Max X and Y */
> wcmRotateTablet(local, common->wcmRotate);
>
> - /* pressure */
> + /* pressure normalized to FILTER_PRESSURE_RES */
> InitValuatorAxisStruct(local->dev, 2,
> #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
> XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE),
> #endif
> - 0, common->wcmMaxZ, 1, 1, 1);
> + 0, FILTER_PRESSURE_RES, 1, 1, 1);
>
> if (IsCursor(priv))
> {
> diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
> index 2f9e827..da5e2cf 100644
> --- a/src/xf86WacomDefs.h
> +++ b/src/xf86WacomDefs.h
> @@ -242,6 +242,7 @@ struct _WacomDeviceRec
> /* JEJ - filters */
> int* pPressCurve; /* pressure curve */
> int nPressCtrl[4]; /* control points for curve */
> + int minPressure; /* the minimum pressure a pen may hold */
>
> WacomToolPtr tool; /* The common tool-structure for this device
> */
> WacomToolAreaPtr toolarea; /* The area defined for this device */
> diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
> index 03a820a..ae3adf1 100644
> --- a/tools/xsetwacom.c
> +++ b/tools/xsetwacom.c
> @@ -495,8 +495,8 @@ static param_t parameters[] =
> },
> {
> .name = "ClickForce",
> - .desc = "Sets tip/eraser pressure threshold =
> ClickForce*MaxZ/100 "
> - "(default is 6)",
> + .desc = "Sets tip/eraser pressure threshold "
> + "(default is FILTER_PRESSURE_RES / 75 )",
this should also reference the ratio instead, no?
> .prop_name = WACOM_PROP_PRESSURE_THRESHOLD,
> .prop_format = 32,
> .prop_offset = 0,
> --
> 1.6.6.1
Cheers,
Peter
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel