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

If the initial pressure of a device is != 0 the driver recalibrates
the pressure range. This is to account for worn out devices.
The downside is that when the user hits the tablet very hard the
initial pressure reading may be unequal to zero even for a perfectly
good pen. If the consecutive pressure readings are not higher than
the initial pressure by a threshold no button event will be generated.
This option allows to disable the recalibration.

Signed-off-by: Egbert Eich <e...@suse.com>
---
v2: Fix bit-twiddling

 include/wacom-properties.h |  4 ++++
 man/wacom.man              | 10 ++++++++++
 man/xsetwacom.man          |  9 +++++++++
 src/wcmCommon.c            | 11 +++++++----
 src/wcmValidateDevice.c    |  6 ++++++
 src/wcmXCommand.c          | 23 +++++++++++++++++++++++
 src/xf86WacomDefs.h        |  2 ++
 test/wacom-tests.c         |  1 +
 tools/xsetwacom.c          | 11 ++++++++++-
 9 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/include/wacom-properties.h b/include/wacom-properties.h
index dd7e7f3..cb94ffc 100644
--- a/include/wacom-properties.h
+++ b/include/wacom-properties.h
@@ -103,6 +103,10 @@
  */
 #define WACOM_PROP_DEBUGLEVELS "Wacom Debug Levels"
 
+/* BOOL, 1 value,
+   TRUE == pressure renormalization enabled, FALSE == pressure renormalization 
disabled
+*/
+#define WACOM_PROP_PRESSURE_RECAL "Wacom Pressure Recalibration"
 
 /* The following are tool types used by the driver in WACOM_PROP_TOOL_TYPE
  * or in the 'type' field for XI1 clients. Clients may check for one of
diff --git a/man/wacom.man b/man/wacom.man
index 98dec37..ae042f6 100644
--- a/man/wacom.man
+++ b/man/wacom.man
@@ -257,6 +257,16 @@ recognized as tap. A press and release event shorter than
 generates button press and release events. Presses longer than
 .B TapTime
 do not generate button events, only motion events.
+.TP 4
+.B Option \fI"PressureRecalibration"\fP \fI"bool"\fP
+Allows to disable pressure recalibration. Default: true.
+If the initial pressure of a device is != 0 the driver recalibrates
+the pressure range. This is to account for worn out devices.
+The downside is that when the user hits the tablet very hard the
+initial pressure reading may be unequal to zero even for a perfectly
+good pen. If the consecutive pressure readings are not higher than
+the initial pressure by a threshold no button event will be generated.
+This option allows to disable the recalibration.
 .RE
 .SH "TOUCH GESTURES"
 .SS Single finger (1FG)
diff --git a/man/xsetwacom.man b/man/xsetwacom.man
index 978b104..6255352 100644
--- a/man/xsetwacom.man
+++ b/man/xsetwacom.man
@@ -227,6 +227,15 @@ code paths that are specific to a given tool. A higher 
level means more
 fine-grained debug messages, a level of 0 turns debugging off for this
 tool. Requires the driver to be built with debugging enabled. See also
 TabletDebugLevel.  Default:  0, range of 0 to 12.
+.TP
+\fBPressureRecalibration\fR on|off
+If the initial pressure of a device is != 0 the driver recalibrates
+the pressure range. This is to account for worn out devices.
+The downside is that when the user hits the tablet very hard the
+initial pressure reading may be unequal to zero even for a perfectly
+good pen. If the consecutive pressure readings are not higher than
+the initial pressure by a threshold no button event will be generated.
+This option allows to disable the recalibration.  Default:  on
 
 
 .SH "AUTHORS"
diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index e3792d1..7402067 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -1071,12 +1071,15 @@ normalizePressure(const WacomDevicePtr priv, const int 
raw_pressure)
        WacomCommonPtr common = priv->common;
        double pressure;
        int p = raw_pressure;
-       int range_left;
+       int range_left = common->wcmMaxZ;
 
+       if (common->wcmPressureRecalibration) {
+               p -= priv->minPressure;
+               range_left -= priv->minPressure;
+       }
        /* normalize pressure to 0..FILTER_PRESSURE_RES */
-       range_left = common->wcmMaxZ - priv->minPressure;
        if (range_left >= 1)
-               pressure = xf86ScaleAxis(p - priv->minPressure,
+               pressure = xf86ScaleAxis(p,
                                         FILTER_PRESSURE_RES, 0,
                                         range_left,
                                         0);
@@ -1527,7 +1530,7 @@ WacomCommonPtr wcmNewCommon(void)
                        /* transmit position if increment is superior */
        common->wcmRawSample = DEFAULT_SAMPLES;
                        /* number of raw data to be used to for filtering */
-
+       common->wcmPressureRecalibration = 1;
        return common;
 }
 
diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c
index eb94d92..896ce92 100644
--- a/src/wcmValidateDevice.c
+++ b/src/wcmValidateDevice.c
@@ -965,6 +965,12 @@ Bool wcmPreInitParseOptions(InputInfoPtr pInfo, Bool 
is_primary,
                        common->wcmGestureParameters.wcmTapTime);
        }
 
+       if (IsStylus(priv) || IsEraser(priv)) {
+               common->wcmPressureRecalibration
+                       = xf86SetBoolOption(pInfo->options,
+                                           "PressureRecalibration", 1);
+       }
+
        /* Swap stylus buttons 2 and 3 for Tablet PCs */
        if (TabletHasFeature(common, WCM_TPC) && IsStylus(priv))
        {
diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c
index b2ba5a5..a9c233b 100644
--- a/src/wcmXCommand.c
+++ b/src/wcmXCommand.c
@@ -98,6 +98,7 @@ Atom prop_hover;
 Atom prop_tooltype;
 Atom prop_btnactions;
 Atom prop_product_id;
+Atom prop_pressure_recal;
 #ifdef DEBUG
 Atom prop_debuglevels;
 #endif
@@ -300,6 +301,13 @@ void InitWcmDeviceProperties(InputInfoPtr pInfo)
                        wcmResetWheelAction(pInfo, i);
        }
 
+       if (IsStylus(priv) || IsEraser(priv)) {
+               values[0] = common->wcmPressureRecalibration;
+               prop_pressure_recal = InitWcmAtom(pInfo->dev,
+                                                 WACOM_PROP_PRESSURE_RECAL,
+                                                 XA_INTEGER, 8, 1, values);
+       }
+
        values[0] = common->vendor_id;
        values[1] = common->tablet_id;
        prop_product_id = InitWcmAtom(pInfo->dev, XI_PROP_PRODUCT_ID, 
XA_INTEGER, 32, 2, values);
@@ -848,6 +856,21 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property, 
XIPropertyValuePtr prop,
        {
                int nbuttons = priv->nbuttons < 4 ? priv->nbuttons : 
priv->nbuttons + 4;
                return wcmSetActionsProperty(dev, property, prop, checkonly, 
nbuttons, priv->btn_actions, priv->keys);
+       } else if (property == prop_pressure_recal)
+       {
+               CARD8 *values = (CARD8*)prop->data;
+
+               if (prop->size != 1 || prop->format != 8)
+                       return BadValue;
+
+               if ((values[0] != 0) && (values[0] != 1))
+                       return BadValue;
+
+               if (!IsStylus(priv) && !IsEraser(priv))
+                       return BadMatch;
+
+               if (!checkonly)
+                       common->wcmPressureRecalibration = values[0];
        } else
        {
                Atom *handler = NULL;
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index a6f1344..101ee52 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -491,6 +491,8 @@ struct _WacomCommonRec
        int wcmCursorProxoutDistDefault; /* Default max mouse distance for 
proxy-out */
        int wcmSuppress;                 /* transmit position on delta > 
supress */
        int wcmRawSample;            /* Number of raw data used to filter an 
event */
+       int wcmPressureRecalibration; /* Determine if pressure recalibration of
+                                        worn pens should be performed */
 
        int bufpos;                        /* position with buffer */
        unsigned char buffer[BUFFER_SIZE]; /* data read from device */
diff --git a/test/wacom-tests.c b/test/wacom-tests.c
index a245021..8c74a72 100644
--- a/test/wacom-tests.c
+++ b/test/wacom-tests.c
@@ -185,6 +185,7 @@ test_normalize_pressure(void)
        priv.common = &common;
        priv.pInfo = &pInfo;
        pInfo.name = strdupa("Wacom test device");
+       common.wcmPressureRecalibration = 1;
 
        priv.minPressure = 0;
 
diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
index bbe25ea..2ceb384 100644
--- a/tools/xsetwacom.c
+++ b/tools/xsetwacom.c
@@ -433,6 +433,15 @@ static param_t parameters[] =
                .prop_flags = PROP_FLAG_READONLY
        },
        {
+               .name = "PressureRecalibration",
+               .desc = "Turns on/off Tablet pressure recalibration",
+               .prop_name = WACOM_PROP_PRESSURE_RECAL,
+               .prop_format = 8,
+               .prop_offset = 0,
+               .arg_count = 1,
+               .prop_flags = PROP_FLAG_BOOLEAN
+       },
+       {
                .name = "MapToOutput",
                .desc = "Map the device to the given output. ",
                .set_func = set_output,
@@ -2791,7 +2800,7 @@ static void test_parameter_number(void)
         * deprecated them.
         * Numbers include trailing NULL entry.
         */
-       assert(ARRAY_SIZE(parameters) == 37);
+       assert(ARRAY_SIZE(parameters) == 38);
        assert(ARRAY_SIZE(deprecated_parameters) == 17);
 }
 
-- 
1.8.4.5


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to