summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2009-10-13 13:12:21 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2009-10-13 13:12:32 +1000
commit365a8a07507011f7c2e7ae4de69963aaa0d7706c (patch)
treeebb2a488b127a22aae40c6b4bce2983af7c87114
parent7d34a581e79a496e4b734637aee0d40fc0ddfed2 (diff)
Add rumblepad joystick device.
-rw-r--r--src/Makefile.am3
-rw-r--r--src/rumblepad.c112
2 files changed, 114 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 240f038..3869e84 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,7 +39,8 @@ noinst_PROGRAMS=btn0 \
alps \
trackpoint \
keyboardmouse \
- void
+ void \
+ rumblepad
noinst_LIBRARIES=$(LIBNAME)
libfakedev_a_SOURCES=fakedev.c fakedev.h
diff --git a/src/rumblepad.c b/src/rumblepad.c
new file mode 100644
index 0000000..93cd3d8
--- /dev/null
+++ b/src/rumblepad.c
@@ -0,0 +1,112 @@
+/*
+ * 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 the Saitek PLC Cyborg Force Rumble Pad
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <linux/input.h>
+#include <linux/uinput.h>
+
+#include "fakedev.h"
+
+static int rumblepad_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;
+ if (ioctl(fd, UI_SET_EVBIT, EV_MSC) == -1) goto error;
+
+ /* buttons */
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_TRIGGER) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_THUMB) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_THUMB2) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_TOP) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_TOP2) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_PINKIE) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_BASE) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_BASE2) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_BASE3) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_BASE4) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_BASE5) == -1) goto error;
+ if (ioctl(fd, UI_SET_KEYBIT, BTN_BASE6) == -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_THROTTLE) == -1) goto error;
+ if (ioctl(fd, UI_SET_ABSBIT, ABS_RUDDER) == -1) goto error;
+ if (ioctl(fd, UI_SET_ABSBIT, ABS_HAT0X) == -1) goto error;
+ if (ioctl(fd, UI_SET_ABSBIT, ABS_HAT0Y) == -1) goto error;
+
+ dev->absmin[ABS_X] = 0;
+ dev->absmax[ABS_X] = 255;
+ dev->absmin[ABS_Y] = 0;
+ dev->absmax[ABS_Y] = 255;
+ dev->absmin[ABS_THROTTLE] = 0;
+ dev->absmax[ABS_THROTTLE] = 255;
+ dev->absmin[ABS_RUDDER] = 0;
+ dev->absmax[ABS_RUDDER] = 255;
+ dev->absmin[ABS_HAT0X] = -1;
+ dev->absmax[ABS_HAT0X] = 1;
+ dev->absmin[ABS_HAT0Y] = -1;
+ dev->absmax[ABS_HAT0Y] = 1;
+
+ return 0;
+error:
+ perror("ioctl failed.");
+ return -1;
+}
+
+static int rumblepad_run(int fd)
+{
+ static int x = -1;
+ send_event(fd, EV_ABS, ABS_X, 100 + x);
+ send_event(fd, EV_ABS, ABS_Y, 100 + x);
+ send_event(fd, EV_ABS, ABS_THROTTLE, 100 + x);
+ send_event(fd, EV_ABS, ABS_RUDDER, 100 + x);
+ send_event(fd, EV_ABS, ABS_HAT0X, 0 + x);
+ send_event(fd, EV_ABS, ABS_HAT0Y, 0 + x);
+ send_event(fd, EV_SYN, SYN_REPORT, 0);
+
+ x = -x;
+
+ usleep(50000);
+ return 0;
+}
+
+static struct test_device rumblepad_dev = {
+ .name = "Saitek PLC Cyborg Force Rumble Pad",
+ .setup = rumblepad_setup,
+ .run = rumblepad_run,
+};
+
+
+struct test_device* get_device(void)
+{
+ return &rumblepad_dev;
+}