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>
This commit is contained in:
Peter Hutterer 2016-02-18 09:42:27 +10:00
parent 79139ebcd1
commit 0e17dc58aa
2 changed files with 26 additions and 13 deletions

View file

@ -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;
/* 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;
}
/* 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.
*/
return value * WACOM_MAX_DEGREES;
return value;
}
static inline int32_t

View file

@ -3298,7 +3298,8 @@ START_TEST(tilt_x)
ck_assert_double_ge(tx, -52);
ty = libinput_event_tablet_tool_get_tilt_y(tev);
ck_assert_double_eq(ty, -64);
ck_assert_double_ge(ty, -65);
ck_assert_double_lt(ty, -63);
libinput_event_destroy(event);
@ -3320,7 +3321,8 @@ START_TEST(tilt_x)
ck_assert_double_le(tx, expected_tx + 2);
ty = libinput_event_tablet_tool_get_tilt_y(tev);
ck_assert_double_eq(ty, -64);
ck_assert_double_ge(ty, -65);
ck_assert_double_lt(ty, -63);
libinput_event_destroy(event);
@ -3365,7 +3367,8 @@ START_TEST(tilt_y)
ck_assert_double_ge(ty, -52);
tx = libinput_event_tablet_tool_get_tilt_x(tev);
ck_assert_double_eq(tx, -64);
ck_assert_double_ge(tx, -65);
ck_assert_double_lt(tx, -63);
libinput_event_destroy(event);
@ -3387,7 +3390,8 @@ START_TEST(tilt_y)
ck_assert_double_le(ty, expected_ty + 2);
tx = libinput_event_tablet_tool_get_tilt_x(tev);
ck_assert_double_eq(tx, -64);
ck_assert_double_ge(tx, -65);
ck_assert_double_lt(tx, -63);
libinput_event_destroy(event);