summaryrefslogtreecommitdiffstats
path: root/toolbox/sendevent.c
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:32:55 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:32:55 -0800
commitdd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0 (patch)
tree2ba8d1a0846d69b18f623515e8d9b5d9fe38b590 /toolbox/sendevent.c
parente54eebbf1a908d65ee8cf80bab62821c05666d70 (diff)
downloadsystem_core-dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0.tar.gz
system_core-dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0.tar.bz2
system_core-dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0.zip
auto import from //depot/cupcake/@135843
Diffstat (limited to 'toolbox/sendevent.c')
-rw-r--r--toolbox/sendevent.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/toolbox/sendevent.c b/toolbox/sendevent.c
new file mode 100644
index 000000000..1608e6c77
--- /dev/null
+++ b/toolbox/sendevent.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+//#include <linux/input.h> // this does not compile
+#include <errno.h>
+
+
+// from <linux/input.h>
+
+struct input_event {
+ struct timeval time;
+ __u16 type;
+ __u16 code;
+ __s32 value;
+};
+
+#define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */
+#define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */
+#define EVIOCGKEYCODE _IOR('E', 0x04, int[2]) /* get keycode */
+#define EVIOCSKEYCODE _IOW('E', 0x04, int[2]) /* set keycode */
+
+#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */
+#define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */
+#define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */
+
+#define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global keystate */
+#define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */
+#define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */
+#define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */
+
+#define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */
+#define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */
+#define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */
+
+#define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */
+#define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */
+#define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */
+
+#define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */
+
+// end <linux/input.h>
+
+
+
+int sendevent_main(int argc, char *argv[])
+{
+ int i;
+ int fd;
+ int ret;
+ int version;
+ struct input_event event;
+
+ if(argc != 5) {
+ fprintf(stderr, "use: %s device type code value\n", argv[0]);
+ return 1;
+ }
+
+ fd = open(argv[1], O_RDWR);
+ if(fd < 0) {
+ fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
+ return 1;
+ }
+ if (ioctl(fd, EVIOCGVERSION, &version)) {
+ fprintf(stderr, "could not get driver version for %s, %s\n", argv[optind], strerror(errno));
+ return 1;
+ }
+ memset(&event, 0, sizeof(event));
+ event.type = atoi(argv[2]);
+ event.code = atoi(argv[3]);
+ event.value = atoi(argv[4]);
+ ret = write(fd, &event, sizeof(event));
+ if(ret < sizeof(event)) {
+ fprintf(stderr, "write event failed, %s\n", strerror(errno));
+ return -1;
+ }
+ return 0;
+}