diff --git a/src/Makefile.am b/src/Makefile.am index b86bdf6..ad0838b 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 +noinst_PROGRAMS=btn0 absrel abs pen dummy synaptics synaptics_central_edges elantech allbtn wacom powermate waltop barcode btn0_left hdaps noinst_LIBRARIES=$(LIBNAME) libfakedev_a_SOURCES=fakedev.c fakedev.h diff --git a/src/elantech.c b/src/elantech.c new file mode 100644 index 0000000..cd45d0d --- /dev/null +++ b/src/elantech.c @@ -0,0 +1,131 @@ +/* + * 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) + * Alberto Milone (alberto.milone@canonical.com) + */ + + +/* creates a device that looks like my elantech touchpad */ + +#include +#include +#include +#include + +#include "fakedev.h" + +static int elantech_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_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; + if (ioctl(fd, UI_SET_KEYBIT, BTN_TOOL_DOUBLETAP) == -1) goto error; + if (ioctl(fd, UI_SET_KEYBIT, BTN_TOOL_TRIPLETAP) == -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_ABSBIT, ABS_TOOL_WIDTH) == -1) goto error; + + dev->absmin[ABS_X] = 8; + dev->absmax[ABS_X] = 1144; + + dev->absmin[ABS_Y] = 8; + dev->absmax[ABS_Y] = 760; + + /* Elantech doesn't report pressure */ + dev->absmin[ABS_PRESSURE] = 0; + dev->absmax[ABS_PRESSURE] = 0; + + dev->absmin[ABS_TOOL_WIDTH] = 0; + dev->absmax[ABS_TOOL_WIDTH] = 0; + + dev->id.bustype = 0x11; + dev->id.vendor = 0x2; + dev->id.product = 0xe; + + return 0; + +error: + perror("ioctl failed."); + return -1; +} + +static int elantech_run(int fd) +{ +#define xmin 0 +#define xmax 2000 +#define ymin 0 +#define ymax 1000 + + static int x = xmin, y = ymin, direction = 10; + + send_event(fd, EV_KEY, BTN_TOOL_FINGER, 1); + send_event(fd, EV_KEY, BTN_TOUCH, 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 elantech_dev = { + .name = "ETPS/2 Elantech TouchPad", + .setup = elantech_setup, + .run = elantech_run, +}; + + +struct test_device* get_device(void) +{ + return &elantech_dev; +} + diff --git a/src/synaptics_central_edges.c b/src/synaptics_central_edges.c new file mode 100644 index 0000000..2f6ea7b --- /dev/null +++ b/src/synaptics_central_edges.c @@ -0,0 +1,129 @@ +/* + * 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 synaptics touchpad */ + +#include +#include +#include +#include + +#include "fakedev.h" + +static int synaptics_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_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; + if (ioctl(fd, UI_SET_KEYBIT, BTN_TOOL_DOUBLETAP) == -1) goto error; + if (ioctl(fd, UI_SET_KEYBIT, BTN_TOOL_TRIPLETAP) == -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_ABSBIT, ABS_TOOL_WIDTH) == -1) goto error; + + dev->absmin[ABS_X] = 1472; + dev->absmax[ABS_X] = 5472; + + dev->absmin[ABS_Y] = 1408; + dev->absmax[ABS_Y] = 4448; + + dev->absmin[ABS_PRESSURE] = 0; + dev->absmax[ABS_PRESSURE] = 255; + + dev->absmin[ABS_TOOL_WIDTH] = 0; + dev->absmax[ABS_TOOL_WIDTH] = 0; /* was 1 */ + + dev->id.bustype = 0x11; + dev->id.vendor = 0x2; + dev->id.product = 0x7; + + return 0; + +error: + perror("ioctl failed."); + return -1; +} + +static int synaptics_run(int fd) +{ +#define xmin 1000 +#define xmax 7000 +#define ymin 1000 +#define ymax 5000 + + static int x = xmin, y = ymin, direction = 10; + + send_event(fd, EV_KEY, BTN_TOOL_FINGER, 1); + send_event(fd, EV_KEY, BTN_TOUCH, 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 synaptics_dev = { + .name = "SynPS/2 Synaptics TouchPad", + .setup = synaptics_setup, + .run = synaptics_run, +}; + + +struct test_device* get_device(void) +{ + return &synaptics_dev; +} +