summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-02-18 09:42:27 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2016-02-23 14:42:35 +1000
commit0e17dc58aa2469909d9e21d889ff119b6170e15a (patch)
tree3f7ae8d2c7cc0dc14cd0ba3d0c83e70fc7716b0f /src
parent79139ebcd1cc81eecdd2d0dc6f006fbec4c2c6f2 (diff)
tablet: use the tilt resolution if we have it
A nonzero resolution on the tilt axes is units/rad so we can calculate the physical min/max based. Uneven min/max ranges are supported. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
Diffstat (limited to 'src')
-rw-r--r--src/evdev-tablet.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 1e5c2cd5..22ea1ebc 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -231,16 +231,25 @@ adjust_tilt(const struct input_absinfo *absinfo)
double value = (absinfo->value - absinfo->minimum) / range;
const int WACOM_MAX_DEGREES = 64;
- /* Map to the (-1, 1) range */
- value = (value * 2) - 1;
-
- /* Wacom supports physical [-64, 64] degrees, so map to that by
- * default. If other tablets have a different physical range or
- * nonzero physical offsets, they need extra treatment
- * here.
- */
+ /* If resolution is nonzero, it's in units/radian. But require
+ * a min/max less/greater than zero so we can assume 0 is the
+ * center */
+ if (absinfo->resolution != 0 &&
+ absinfo->maximum > 0 &&
+ absinfo->minimum < 0) {
+ value = 180.0/M_PI * absinfo->value/absinfo->resolution;
+ } else {
+ /* Wacom supports physical [-64, 64] degrees, so map to that by
+ * default. If other tablets have a different physical range or
+ * nonzero physical offsets, they need extra treatment
+ * here.
+ */
+ /* Map to the (-1, 1) range */
+ value = (value * 2) - 1;
+ value *= WACOM_MAX_DEGREES;
+ }
- return value * WACOM_MAX_DEGREES;
+ return value;
}
static inline int32_t