[PATCH libevdev 2/6] Add abs setters for changing a single value on an abs axis
Peter Hutterer
peter.hutterer at who-t.net
Sun Jul 28 22:34:33 PDT 2013
Changing a single value on an abs axis is slightly more common than
having to enable that axis outright. Provide a set of accessors for
doing so.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
libevdev/libevdev.c | 22 ++++++++++++++
libevdev/libevdev.h | 54 +++++++++++++++++++++++++++++++++++
test/test-libevdev-has-event.c | 65 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 141 insertions(+)
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index cd33659..c7f5102 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -836,6 +836,28 @@ libevdev_get_abs_resolution(const struct libevdev *dev, unsigned int code)
return absinfo ? absinfo->resolution : 0;
}
+#define ABS_SETTER(name, field) \
+void libevdev_set_abs_##name(struct libevdev *dev, unsigned int code, int val) \
+{ \
+ if (!libevdev_has_event_code(dev, EV_ABS, code)) \
+ return; \
+ dev->abs_info[code].field = val; \
+}
+
+ABS_SETTER(max, maximum)
+ABS_SETTER(min, minimum)
+ABS_SETTER(fuzz, fuzz)
+ABS_SETTER(flat, flat)
+ABS_SETTER(resolution, resolution)
+
+void libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs)
+{
+ if (!libevdev_has_event_code(dev, EV_ABS, code))
+ return;
+
+ dev->abs_info[code] = *abs;
+}
+
int
libevdev_enable_event_type(struct libevdev *dev, unsigned int type)
{
diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h
index d637c29..1800b85 100644
--- a/libevdev/libevdev.h
+++ b/libevdev/libevdev.h
@@ -832,6 +832,60 @@ int libevdev_get_current_slot(const struct libevdev *dev);
/**
* @ingroup kernel
*
+ * Change the minimum for the given EV_ABS event code, if the code exists.
+ * This function has no effect if libevdev_has_event_code() returns false for
+ * this code.
+ */
+void libevdev_set_abs_min(struct libevdev *dev, unsigned int code, int min);
+
+/**
+ * @ingroup kernel
+ *
+ * Change the maximum for the given EV_ABS event code, if the code exists.
+ * This function has no effect if libevdev_has_event_code() returns false for
+ * this code.
+ */
+void libevdev_set_abs_max(struct libevdev *dev, unsigned int code, int max);
+
+/**
+ * @ingroup kernel
+ *
+ * Change the fuzz for the given EV_ABS event code, if the code exists.
+ * This function has no effect if libevdev_has_event_code() returns false for
+ * this code.
+ */
+void libevdev_set_abs_fuzz(struct libevdev *dev, unsigned int code, int fuzz);
+
+/**
+ * @ingroup kernel
+ *
+ * Change the flat for the given EV_ABS event code, if the code exists.
+ * This function has no effect if libevdev_has_event_code() returns false for
+ * this code.
+ */
+void libevdev_set_abs_flat(struct libevdev *dev, unsigned int code, int flat);
+
+/**
+ * @ingroup kernel
+ *
+ * Change the resolution for the given EV_ABS event code, if the code exists.
+ * This function has no effect if libevdev_has_event_code() returns false for
+ * this code.
+ */
+void libevdev_set_abs_resolution(struct libevdev *dev, unsigned int code, int resolution);
+
+/**
+ * @ingroup kernel
+ *
+ * Change the abs info for the given EV_ABS event code, if the code exists.
+ * This function has no effect if libevdev_has_event_code() returns false for
+ * this code.
+ */
+void libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
+
+/**
+ * @ingroup kernel
+ *
* Forcibly enable an event type on this device, even if the underlying
* device does not support it. While this cannot make the device actually
* report such events, it will now return true for libevdev_has_event_type().
diff --git a/test/test-libevdev-has-event.c b/test/test-libevdev-has-event.c
index 8a97b62..5321549 100644
--- a/test/test-libevdev-has-event.c
+++ b/test/test-libevdev-has-event.c
@@ -509,6 +509,70 @@ START_TEST(test_device_get_abs_info)
}
END_TEST
+START_TEST(test_device_set_abs)
+{
+ struct uinput_device* uidev;
+ struct libevdev *dev;
+ struct input_absinfo abs[2];
+ struct input_absinfo a;
+ int rc;
+
+ memset(abs, 0, sizeof(abs));
+ abs[0].value = ABS_X;
+ abs[0].maximum = 1000;
+
+ abs[1].value = ABS_Y;
+ abs[1].maximum = 1000;
+
+ rc = test_create_abs_device(&uidev, &dev,
+ 2, abs,
+ EV_SYN,
+ -1);
+ ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+ libevdev_set_abs_min(dev, ABS_X, 1);
+ libevdev_set_abs_min(dev, ABS_Y, 5);
+ ck_assert_int_eq(libevdev_get_abs_min(dev, ABS_X), 1);
+ ck_assert_int_eq(libevdev_get_abs_min(dev, ABS_Y), 5);
+
+ libevdev_set_abs_max(dev, ABS_X, 3000);
+ libevdev_set_abs_max(dev, ABS_Y, 5000);
+ ck_assert_int_eq(libevdev_get_abs_max(dev, ABS_X), 3000);
+ ck_assert_int_eq(libevdev_get_abs_max(dev, ABS_Y), 5000);
+
+ libevdev_set_abs_fuzz(dev, ABS_X, 3);
+ libevdev_set_abs_fuzz(dev, ABS_Y, 5);
+ ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_X), 3);
+ ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_Y), 5);
+
+ libevdev_set_abs_flat(dev, ABS_X, 8);
+ libevdev_set_abs_flat(dev, ABS_Y, 15);
+ ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_X), 8);
+ ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_Y), 15);
+
+ libevdev_set_abs_resolution(dev, ABS_X, 80);
+ libevdev_set_abs_resolution(dev, ABS_Y, 150);
+ ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_X), 80);
+ ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_Y), 150);
+
+ a.minimum = 10;
+ a.maximum = 100;
+ a.fuzz = 13;
+ a.flat = 1;
+ a.resolution = 16;
+
+ libevdev_set_abs_info(dev, ABS_X, &a);
+ ck_assert_int_eq(memcmp(&a, libevdev_get_abs_info(dev, ABS_X), sizeof(a)), 0);
+
+ libevdev_set_abs_min(dev, ABS_Z, 10);
+ ck_assert_int_eq(libevdev_has_event_code(dev, EV_ABS, ABS_Z), 0);
+
+ uinput_device_free(uidev);
+ libevdev_free(dev);
+}
+END_TEST
+
+
START_TEST(test_device_enable_bit)
{
struct uinput_device* uidev;
@@ -779,6 +843,7 @@ libevdev_has_event_test(void)
suite_add_tcase(s, tc);
tc = tcase_create("device bit manipulation");
+ tcase_add_test(tc, test_device_set_abs);
tcase_add_test(tc, test_device_enable_bit);
tcase_add_test(tc, test_device_enable_bit_invalid);
tcase_add_test(tc, test_device_disable_bit);
--
1.8.2.1
More information about the Input-tools
mailing list