summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-01-11 09:27:11 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-01-11 09:27:11 +1000
commitd3024c9385140916a2e950108c5dcabfd7584f48 (patch)
tree2762b27b8a254819749c0edcef17704431e6f55b
parentec8404a867de9f3f0ec7fb48f7f4c0688f9cedfe (diff)
Add simple touch device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/Makefile.am3
-rw-r--r--src/touch.c104
2 files changed, 106 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index de6d43e..dac88ad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,7 +59,8 @@ noinst_PROGRAMS=btn0 \
ntrig_pen \
ntrig \
relz \
- 39663
+ 39663 \
+ touch
noinst_LIBRARIES=$(LIBNAME)
libfakedev_a_SOURCES=fakedev.c fakedev.h
diff --git a/src/touch.c b/src/touch.c
new file mode 100644
index 0000000..663a17a
--- /dev/null
+++ b/src/touch.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of Red Hat
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission. Red
+ * Hat makes no representations about the suitability of this software
+ * for any purpose. It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors:
+ * Peter Hutterer (peter.hutterer@redhat.com)
+ */
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <linux/input.h>
+#include <linux/uinput.h>
+
+#include "fakedev.h"
+
+static int multitouch_setup(struct uinput_user_dev* dev, int fd)
+{
+ if (ioctl(fd, UI_SET_EVBIT, EV_ABS) == -1) goto error;
+ if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error;
+ if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
+
+ /* buttons */
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
+
+ /* axes */
+ if (ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_X) == -1) goto error;
+ if (ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_Y) == -1) goto error;
+ if (ioctl(fd, UI_SET_ABSBIT, ABS_X) == -1) goto error;
+ if (ioctl(fd, UI_SET_ABSBIT, ABS_Y) == -1) goto error;
+
+ dev->absmin[ABS_X] = 0;
+ dev->absmax[ABS_X] = 120;
+
+ dev->absmin[ABS_Y] = 0;
+ dev->absmax[ABS_Y] = 120;
+
+ dev->absmin[ABS_MT_POSITION_X] = 0;
+ dev->absmax[ABS_MT_POSITION_X] = 120;
+
+ dev->absmin[ABS_MT_POSITION_Y] = 0;
+ dev->absmax[ABS_MT_POSITION_Y] = 120;
+
+ return 0;
+
+error:
+ perror("ioctl failed.");
+ return -1;
+}
+
+static int multitouch_run(int fd)
+{
+ send_event(fd, EV_ABS, ABS_MT_POSITION_X, 10);
+ send_event(fd, EV_ABS, ABS_MT_POSITION_Y, 10);
+ send_event(fd, EV_SYN, SYN_MT_REPORT, 0);
+ send_event(fd, EV_ABS, ABS_MT_POSITION_X, 110);
+ send_event(fd, EV_ABS, ABS_MT_POSITION_Y, 110);
+ send_event(fd, EV_SYN, SYN_MT_REPORT, 0);
+ syn(fd);
+ sleep(1);
+ send_event(fd, EV_ABS, ABS_MT_POSITION_X, 20);
+ send_event(fd, EV_ABS, ABS_MT_POSITION_Y, 20);
+ send_event(fd, EV_SYN, SYN_MT_REPORT, 0);
+ send_event(fd, EV_ABS, ABS_MT_POSITION_X, 120);
+ send_event(fd, EV_ABS, ABS_MT_POSITION_Y, 120);
+ send_event(fd, EV_SYN, SYN_MT_REPORT, 0);
+ syn(fd);
+ send_event(fd, EV_SYN, SYN_MT_REPORT, 0);
+ syn(fd);
+ sleep(1);
+ return 0;
+}
+
+static struct test_device multitouch_dev = {
+ .name = "multitouch test device",
+ .setup = multitouch_setup,
+ .run = multitouch_run,
+};
+
+
+struct test_device* get_device(void)
+{
+ return &multitouch_dev;
+}