Take an input point, calculate the rotation and return it. No need to deal with device state structures, etc.
Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net> --- src/wcmCommon.c | 4 +++- src/wcmFilter.c | 42 +++++++++++++++++++++--------------------- src/xf86Wacom.h | 2 +- test/wacom-tests.c | 12 ++++++------ 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/wcmCommon.c b/src/wcmCommon.c index 6fe1e8b..39dcf6d 100644 --- a/src/wcmCommon.c +++ b/src/wcmCommon.c @@ -902,7 +902,9 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel, TabletHasFeature(common, WCM_RING)) /* I4 */ { /* convert Intuos4 mouse tilt to rotation */ - wcmTilt2R(&ds, INTUOS4_CURSOR_ROTATION_OFFSET); + /* FIXME: shouldn't we reset tilt? */ + ds.rotation = wcmTilt2R(ds.tiltx, ds.tilty, + INTUOS4_CURSOR_ROTATION_OFFSET); } /* Optionally filter values only while in proximity */ diff --git a/src/wcmFilter.c b/src/wcmFilter.c index d0588b9..47e958a 100644 --- a/src/wcmFilter.c +++ b/src/wcmFilter.c @@ -314,13 +314,15 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel, } /*** - * Convert tilt X and Y to rotation + * Convert a point (X/Y) in a left-handed coordinate system to a normalized + * rotation angle. * * This function is currently called for the Intuos4 mouse (cursor) tool - * only, but it may be used for other devices in the future. + * only (to convert tilt to rotation), but it may be used for other devices + * in the future. * - * Method used: rotation angle is calculated through the atan of the tiltx/y - * coordinates, then converted to degrees and normalized into the rotation + * Method used: rotation angle is calculated through the atan of x/y + * then converted to degrees and normalized into the rotation * range (MIN_ROTATION/MAX_ROTATION). * IMPORTANT: calculation inverts direction, the formula to get the target @@ -333,44 +335,42 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel, * 180 degrees: RANGE/2 * 270 degrees: MIN + RANGE/4 * - * @param ds The current device state, will be modified to set to the - * calculated rotation value. + * @param x X coordinate in left-handed coordiante system. + * @param y Y coordiante in left-handed coordinate system. * @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, double offset) +int wcmTilt2R(int x, int y, double offset) { - short tilt_x = ds->tiltx; - short tilt_y = ds->tilty; - double rotation = 0.0; + double angle = 0.0; + int rotation; - /* other tilt-enabled devices need to apply round() after this call */ - if (tilt_x || tilt_y) + if (x || y) /* rotate in the inverse direction, changing CW to CCW * rotation and vice versa */ - rotation = ((180.0 * atan2(-tilt_x,tilt_y)) / M_PI); + angle = ((180.0 * atan2(-x, y)) / M_PI); /* rotation is now in 0 - 360 deg value range, apply the offset. Use * 360 to avoid getting into negative range, the normalization code * below expects 0...360 */ - rotation = 360 + rotation - offset; + angle = 360 + angle - offset; /* normalize into the rotation range (0...MAX), then offset by MIN_ROTATION we used 360 as base offset above, so %= MAX_ROTATION_RANGE brings us back. Note: we can't use xf86ScaleAxis here because of rounding issues. */ - ds->rotation = round(rotation * (MAX_ROTATION_RANGE / 360.0)); - ds->rotation %= MAX_ROTATION_RANGE; + rotation = round(angle * (MAX_ROTATION_RANGE / 360.0)); + rotation %= MAX_ROTATION_RANGE; /* now scale back from 0...MAX to MIN..(MIN+MAX) */ - ds->rotation = xf86ScaleAxis(ds->rotation, - MIN_ROTATION + MAX_ROTATION_RANGE, - MIN_ROTATION, - MAX_ROTATION_RANGE, 0); + rotation = xf86ScaleAxis(rotation, + MIN_ROTATION + MAX_ROTATION_RANGE, + MIN_ROTATION, + MAX_ROTATION_RANGE, 0); - /* FIXME: shouldn't we reset tilt? */ + return rotation; } /* vim: set noexpandtab tabstop=8 shiftwidth=8: */ diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h index 4581ea9..e5149b3 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, double offset); +extern int wcmTilt2R(int x, int y, 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/test/wacom-tests.c b/test/wacom-tests.c index 841bcdb..8444bf3 100644 --- a/test/wacom-tests.c +++ b/test/wacom-tests.c @@ -416,15 +416,15 @@ test_tilt_to_rotation(void) { -69, 997, 45}, { -52, 998, 40}, { -34, 999, 35}, { -17, 999, 30}, }; int i; - WacomDeviceState ds = {0}; for (i = 0; i < ARRAY_SIZE(rotation_table); i++) { - ds.rotation = 0; - ds.tiltx = rotation_table[i][0]; - ds.tilty = rotation_table[i][1]; - wcmTilt2R(&ds, INTUOS4_CURSOR_ROTATION_OFFSET); - g_assert(ds.rotation == rotation_table[i][2]); + int rotation; + int x, y; + x = rotation_table[i][0]; + y = rotation_table[i][1]; + rotation = wcmTilt2R(x, y, INTUOS4_CURSOR_ROTATION_OFFSET); + g_assert(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