From 727d184230e6d02c8e6c3865ecaf7d92953bcd1a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 10 Dec 2015 16:05:37 +1000 Subject: [PATCH] test: change extra axes to take a percentage as well And change them to doubles, we need more granularity when the range is only 0-100. Signed-off-by: Peter Hutterer --- test/litest.c | 36 ++++++++++++++++++++++++++++-------- test/litest.h | 2 +- test/touchpad.c | 22 +++++++++++----------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/test/litest.c b/test/litest.c index f0def982..632b144a 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1267,7 +1267,8 @@ litest_event(struct litest_device *d, unsigned int type, } static bool -axis_replacement_value(struct axis_replacement *axes, +axis_replacement_value(struct litest_device *d, + struct axis_replacement *axes, int32_t evcode, int32_t *value) { @@ -1278,7 +1279,7 @@ axis_replacement_value(struct axis_replacement *axes, while (axis->evcode != -1) { if (axis->evcode == evcode) { - *value = axis->value; + *value = litest_scale(d, evcode, axis->value); return true; } axis++; @@ -1319,7 +1320,7 @@ litest_auto_assign_value(struct litest_device *d, value = touching ? 0 : 1; break; default: - if (!axis_replacement_value(axes, ev->code, &value) && + if (!axis_replacement_value(d, axes, ev->code, &value) && d->interface->get_axis_default) d->interface->get_axis_default(d, ev->code, &value); break; @@ -1518,7 +1519,7 @@ auto_assign_tablet_value(struct litest_device *d, value = litest_scale(d, ABS_Y, y); break; default: - axis_replacement_value(axes, ev->code, &value); + axis_replacement_value(d, axes, ev->code, &value); break; } @@ -1757,17 +1758,36 @@ litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press) litest_button_click(d, key, is_press); } +static int +litest_scale_axis(const struct litest_device *d, + unsigned int axis, + double val) +{ + const struct input_absinfo *abs; + + litest_assert_double_ge(val, 0.0); + litest_assert_double_le(val, 100.0); + + abs = libevdev_get_abs_info(d->evdev, axis); + litest_assert_notnull(abs); + + return (abs->maximum - abs->minimum) * val/100.0 + abs->minimum; +} + int litest_scale(const struct litest_device *d, unsigned int axis, double val) { int min, max; litest_assert_double_ge(val, 0.0); litest_assert_double_le(val, 100.0); - litest_assert_int_le(axis, (unsigned int)ABS_Y); - min = d->interface->min[axis]; - max = d->interface->max[axis]; - return (max - min) * val/100.0 + min; + if (axis <= ABS_X) { + min = d->interface->min[axis]; + max = d->interface->max[axis]; + return (max - min) * val/100.0 + min; + } else { + return litest_scale_axis(d, axis, val); + } } void diff --git a/test/litest.h b/test/litest.h index 5f907e89..1d36ab9a 100644 --- a/test/litest.h +++ b/test/litest.h @@ -195,7 +195,7 @@ struct litest_device { struct axis_replacement { int32_t evcode; - int32_t value; + double value; }; /* A loop range, resolves to: diff --git a/test/touchpad.c b/test/touchpad.c index 7bc99e98..dab2781e 100644 --- a/test/touchpad.c +++ b/test/touchpad.c @@ -2983,7 +2983,7 @@ START_TEST(touchpad_thumb_begin_no_motion) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3007,7 +3007,7 @@ START_TEST(touchpad_thumb_update_no_motion) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3033,7 +3033,7 @@ START_TEST(touchpad_thumb_moving) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3062,7 +3062,7 @@ START_TEST(touchpad_thumb_clickfinger) struct libinput_event *event; struct libinput_event_pointer *ptrev; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3119,7 +3119,7 @@ START_TEST(touchpad_thumb_btnarea) struct libinput_event *event; struct libinput_event_pointer *ptrev; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3155,7 +3155,7 @@ START_TEST(touchpad_thumb_edgescroll) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3186,7 +3186,7 @@ START_TEST(touchpad_thumb_tap_begin) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3219,7 +3219,7 @@ START_TEST(touchpad_thumb_tap_touch) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3252,7 +3252,7 @@ START_TEST(touchpad_thumb_tap_hold) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3286,7 +3286,7 @@ START_TEST(touchpad_thumb_tap_hold_2ndfg) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3337,7 +3337,7 @@ START_TEST(touchpad_thumb_tap_hold_2ndfg_tap) struct libinput_event *event; struct libinput_event_pointer *ptrev; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } };