diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-05-11 10:36:25 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2009-05-11 10:56:00 +1000 |
commit | c772f59886f884661ab46fa67ade692831fa392a (patch) | |
tree | ffdef9b88d72557b8b57984b3e27ee7419bb7497 | |
parent | 4e28cb3200d1bcde5f0c2003d4eca636df8f60e3 (diff) |
Add testdevice for Griffin Powermate
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/powermate.c | 78 |
2 files changed, 79 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ee4a3c7..786e1d5 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 +noinst_PROGRAMS=btn0 absrel abs pen dummy synaptics allbtn wacom powermate noinst_LIBRARIES=$(LIBNAME) libfakedev_a_SOURCES=fakedev.c fakedev.h diff --git a/src/powermate.c b/src/powermate.c new file mode 100644 index 0000000..30bc27b --- /dev/null +++ b/src/powermate.c @@ -0,0 +1,78 @@ +/* + * 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 Griffin Powermate, or something that looks like it anyway */ + +#include <stdio.h> +#include <unistd.h> +#include <linux/input.h> +#include <linux/uinput.h> + +#include "fakedev.h" + +static int powermate_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_REL) == -1) goto error; + if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error; + + /* buttons */ + if (ioctl(fd, UI_SET_KEYBIT, BTN_0) == -1) goto error; + + /* axes */ + if (ioctl(fd, UI_SET_RELBIT, REL_DIAL) == -1) goto error; + + return 0; +error: + perror("ioctl failed."); + return -1; +} + +static int powermate_run(int fd) +{ + send_event(fd, EV_REL, REL_DIAL, -1); + sleep(1); + send_event(fd, EV_REL, REL_DIAL, 1); + sleep(1); + send_event(fd, EV_KEY, BTN_0, 1); + usleep(200); + send_event(fd, EV_KEY, BTN_0, 0); + sleep(1); + return 0; +} + +static struct test_device powermate_dev = { + .name = "Griffin PowerMate", + .setup = powermate_setup, + .run = powermate_run, +}; + + +struct test_device* get_device(void) +{ + return &powermate_dev; +} |