diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-08-05 13:09:43 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2009-08-26 09:25:15 +1000 |
commit | 76ae794b4fe85e820b7548f2d0dd3498c86556ce (patch) | |
tree | d8f3180f3a01933fae66a2ef1eff84e54d2ce315 | |
parent | 0dbbf0806fcf1a56341e1d4c96d7438fd5c021ba (diff) |
Add Alps touchpad test device.
Same thing as synaptics, basically but a few different values.
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/alps.c | 126 |
2 files changed, 127 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index e6a6a7c..b392536 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,7 @@ LIBNAME=libfakedev.a AM_LDFLAGS = $(LIBNAME) -noinst_PROGRAMS=btn0 absrel abs pen dummy synaptics allbtn wacom powermate waltop barcode btn0_left hdaps mouse +noinst_PROGRAMS=btn0 absrel abs pen dummy synaptics allbtn wacom powermate waltop barcode btn0_left hdaps mouse alps noinst_LIBRARIES=$(LIBNAME) libfakedev_a_SOURCES=fakedev.c fakedev.h diff --git a/src/alps.c b/src/alps.c new file mode 100644 index 0000000..7144c05 --- /dev/null +++ b/src/alps.c @@ -0,0 +1,126 @@ +/* + * Copyright © 2009 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) + */ + + +/* creates a device that looks like my alps touchpad */ + +#include <stdio.h> +#include <unistd.h> +#include <linux/input.h> +#include <linux/uinput.h> + +#include "fakedev.h" + +static int alps_setup(struct uinput_user_dev* dev, int fd) +{ + + if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error; + if (ioctl(fd, UI_SET_EVBIT, EV_ABS) == -1) goto error; + if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -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; + if (ioctl(fd, UI_SET_KEYBIT, BTN_TOOL_FINGER) == -1) goto error; + if (ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH) == -1) goto error; + + /* axes */ + if (ioctl(fd, UI_SET_ABSBIT, ABS_X) == -1) goto error; + if (ioctl(fd, UI_SET_ABSBIT, ABS_Y) == -1) goto error; + if (ioctl(fd, UI_SET_ABSBIT, ABS_PRESSURE) == -1) goto error; + if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error; + if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error; + + dev->absmin[ABS_X] = 0; + dev->absmax[ABS_X] = 1023; + + dev->absmin[ABS_Y] = 0; + dev->absmax[ABS_Y] = 767; + + dev->absmin[ABS_PRESSURE] = 0; + dev->absmax[ABS_PRESSURE] = 127; + + dev->id.bustype = 0x11; + dev->id.vendor = 0x2; + dev->id.product = 0x8; + + return 0; + +error: + perror("ioctl failed."); + return -1; +} + +static int alps_run(int fd) +{ +#define xmin 0 +#define xmax 1000 +#define ymin 0 +#define ymax 767 + + static int x = xmin, y = ymin, direction = 10; + + send_event(fd, EV_KEY, BTN_TOUCH, 1); + send_event(fd, EV_KEY, BTN_TOOL_FINGER, 1); + send_event(fd, EV_ABS, ABS_PRESSURE, 75); + absmove(fd, x, y); + + while(x >= xmin && x <= xmax && y >= ymin && y <= ymax) + { + x += direction; + y += direction; + absmove(fd, x, y); + usleep(200); + } + + x -= direction * 2; + y -= direction * 2; + + direction *= -1; + + send_event(fd, EV_KEY, BTN_TOOL_FINGER, 0); + send_event(fd, EV_KEY, BTN_TOUCH, 0); + send_event(fd, EV_ABS, ABS_PRESSURE, 0); + send_event(fd, EV_SYN, SYN_REPORT, 0); + + sleep(1); + return 0; +} + +struct test_device alps_dev = { + .name = "AlpsPS/2 ALPS DualPoint TouchPad", + .setup = alps_setup, + .run = alps_run, +}; + + +struct test_device* get_device(void) +{ + return &alps_dev; +} + |