Say No To Hardcoding.

Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 src/wcmCommon.c     |    2 +-
 src/wcmFilter.c     |   12 ++++++++----
 src/xf86Wacom.h     |    2 +-
 src/xf86WacomDefs.h |    3 +++
 test/wacom-tests.c  |    2 +-
 5 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index 47deba4..6fe1e8b 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -902,7 +902,7 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel,
                TabletHasFeature(common, WCM_RING)) /* I4 */
        {
                /* convert Intuos4 mouse tilt to rotation */
-               wcmTilt2R(&ds);
+               wcmTilt2R(&ds, INTUOS4_CURSOR_ROTATION_OFFSET);
        }
 
        /* Optionally filter values only while in proximity */
diff --git a/src/wcmFilter.c b/src/wcmFilter.c
index e6f7402..e020001 100644
--- a/src/wcmFilter.c
+++ b/src/wcmFilter.c
@@ -335,8 +335,12 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr 
pChannel,
  *
  * @param ds The current device state, will be modified to set to the
  * calculated rotation value.
+ * @param offset Custom rotation offset in degrees. Offset is
+ * applied in counterclockwise direction.
+ *
+ * @return The mapped rotation angle based on the device's tilt state.
  */
-void wcmTilt2R(WacomDeviceStatePtr ds)
+void wcmTilt2R(WacomDeviceStatePtr ds, double offset)
 {
        short tilt_x = ds->tiltx;
        short tilt_y = ds->tilty;
@@ -348,9 +352,9 @@ void wcmTilt2R(WacomDeviceStatePtr ds)
                 * rotation  and vice versa */
                rotation = ((180.0 * atan2(-tilt_x,tilt_y)) / M_PI) + 180.0;
 
-       /* Intuos4 mouse has an (180-5) offset,
-        * normalize into the rotation range. */
-       ds->rotation = round((360.0 - rotation + 180.0 - 5.0) * 
(MAX_ROTATION_RANGE / 360.0));
+       /* rotation is now in 0 - 360 deg value range.
+          normalize into the rotation range and apply the custom offset. */
+       ds->rotation = round((360 - rotation + offset) * (MAX_ROTATION_RANGE / 
360.0));
        ds->rotation %= MAX_ROTATION_RANGE;
 
        /* ds->rotation now normalised into 0 - MAX, but we want MIN - MAX
diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h
index ac012f4..4581ea9 100644
--- a/src/xf86Wacom.h
+++ b/src/xf86Wacom.h
@@ -150,7 +150,7 @@ extern int wcmDevSwitchMode(ClientPtr client, DeviceIntPtr 
dev, int mode);
 
 /* run-time modifications */
 extern void wcmChangeScreen(InputInfoPtr pInfo, int value);
-extern void wcmTilt2R(WacomDeviceStatePtr ds);
+extern void wcmTilt2R(WacomDeviceStatePtr ds, double offset);
 extern void wcmGestureFilter(WacomDevicePtr priv, int channel);
 extern void wcmEmitKeycode(DeviceIntPtr keydev, int keycode, int state);
 extern void wcmSoftOutEvent(InputInfoPtr pInfo);
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 891f6a6..362d40e 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -45,6 +45,9 @@
 #define MIN_PAD_RING 0         /* I4 absolute scroll ring min value */
 #define MAX_PAD_RING 71                /* I4 absolute scroll ring max value */
 
+/* I4 cursor tool has a rotation offset of 175 degrees */
+#define INTUOS4_CURSOR_ROTATION_OFFSET 175
+
 /* Default max distance to the tablet at which a proximity-out event is 
generated for
  * cursor device (e.g. mouse). 
  */
diff --git a/test/wacom-tests.c b/test/wacom-tests.c
index 8ada826..841bcdb 100644
--- a/test/wacom-tests.c
+++ b/test/wacom-tests.c
@@ -423,7 +423,7 @@ test_tilt_to_rotation(void)
                ds.rotation = 0;
                ds.tiltx = rotation_table[i][0];
                ds.tilty = rotation_table[i][1];
-               wcmTilt2R(&ds);
+               wcmTilt2R(&ds, INTUOS4_CURSOR_ROTATION_OFFSET);
                g_assert(ds.rotation == rotation_table[i][2]);
        }
 }
-- 
1.7.4


------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to