test: change extra axes to take a percentage as well

More flexible than having values that are device-specific.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2015-12-10 16:05:37 +10:00
parent 6e614e7bee
commit 8d76734fb6
2 changed files with 38 additions and 18 deletions

View file

@ -1255,7 +1255,8 @@ litest_event(struct litest_device *d, unsigned int type,
} }
static bool 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 evcode,
int32_t *value) int32_t *value)
{ {
@ -1266,7 +1267,7 @@ axis_replacement_value(struct axis_replacement *axes,
while (axis->evcode != -1) { while (axis->evcode != -1) {
if (axis->evcode == evcode) { if (axis->evcode == evcode) {
*value = axis->value; *value = litest_scale(d, evcode, axis->value);
return true; return true;
} }
axis++; axis++;
@ -1307,7 +1308,7 @@ litest_auto_assign_value(struct litest_device *d,
value = touching ? 0 : 1; value = touching ? 0 : 1;
break; break;
default: 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->interface->get_axis_default(d, ev->code, &value); d->interface->get_axis_default(d, ev->code, &value);
break; break;
@ -1671,17 +1672,36 @@ litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press)
litest_button_click(d, key, 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 int
litest_scale(const struct litest_device *d, unsigned int axis, double val) litest_scale(const struct litest_device *d, unsigned int axis, double val)
{ {
int min, max; int min, max;
litest_assert_double_ge(val, 0.0); litest_assert_double_ge(val, 0.0);
litest_assert_double_le(val, 100.0); litest_assert_double_le(val, 100.0);
litest_assert_int_le(axis, (unsigned int)ABS_Y);
min = d->interface->min[axis]; if (axis <= ABS_Y) {
max = d->interface->max[axis]; min = d->interface->min[axis];
return (max - min) * val/100.0 + min; max = d->interface->max[axis];
return (max - min) * val/100.0 + min;
} else {
return litest_scale_axis(d, axis, val);
}
} }
void void

View file

@ -2983,7 +2983,7 @@ START_TEST(touchpad_thumb_begin_no_motion)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3007,7 +3007,7 @@ START_TEST(touchpad_thumb_update_no_motion)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3033,7 +3033,7 @@ START_TEST(touchpad_thumb_moving)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3062,7 +3062,7 @@ START_TEST(touchpad_thumb_clickfinger)
struct libinput_event *event; struct libinput_event *event;
struct libinput_event_pointer *ptrev; struct libinput_event_pointer *ptrev;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3119,7 +3119,7 @@ START_TEST(touchpad_thumb_btnarea)
struct libinput_event *event; struct libinput_event *event;
struct libinput_event_pointer *ptrev; struct libinput_event_pointer *ptrev;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3155,7 +3155,7 @@ START_TEST(touchpad_thumb_edgescroll)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3186,7 +3186,7 @@ START_TEST(touchpad_thumb_tap_begin)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3219,7 +3219,7 @@ START_TEST(touchpad_thumb_tap_touch)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3252,7 +3252,7 @@ START_TEST(touchpad_thumb_tap_hold)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3286,7 +3286,7 @@ START_TEST(touchpad_thumb_tap_hold_2ndfg)
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput; struct libinput *li = dev->libinput;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };
@ -3337,7 +3337,7 @@ START_TEST(touchpad_thumb_tap_hold_2ndfg_tap)
struct libinput_event *event; struct libinput_event *event;
struct libinput_event_pointer *ptrev; struct libinput_event_pointer *ptrev;
struct axis_replacement axes[] = { struct axis_replacement axes[] = {
{ ABS_MT_PRESSURE, 190 }, { ABS_MT_PRESSURE, 75 },
{ -1, 0 } { -1, 0 }
}; };