diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-03-05 09:17:46 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2009-03-26 10:17:01 +1000 |
commit | 97a846ac4c7acdd7ec79d3e630bbec72fcd70bf4 (patch) | |
tree | 44c5f9dcf53d89da972c93e73dd7039d4f59dbc8 | |
parent | d991e85b97d654ccc187f7c38cb5415916494b47 (diff) |
Add synaptics test device.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/synaptics.c | 129 |
2 files changed, 133 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7e4f127..7235bd6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -noinst_PROGRAMS=fakedev btn0 absrel abs dummy +noinst_PROGRAMS=fakedev btn0 absrel abs dummy synaptics fakedev_SOURCES=fakedev.c fakedev.h fakedev_LDFLAGS=$(DLOPEN_LIBS) -rdynamic @@ -36,3 +36,6 @@ abs_LDFLAGS=$(LFLAGS) dummy_SOURCES=dummy.c dummy_LDFLAGS=$(LFLAGS) + +synaptics_SOURCES=synaptics.c +synaptics_LDFLAGS=$(LFLAGS) diff --git a/src/synaptics.c b/src/synaptics.c new file mode 100644 index 0000000..54271cb --- /dev/null +++ b/src/synaptics.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 <stdio.h> +#include <unistd.h> +#include <linux/input.h> +#include <linux/uinput.h> + +#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] = 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 2000 +#define xmax 5000 +#define ymin 2000 +#define ymax 4000 + + 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; +} + |