r4550 - in developers/zecke: . uinput-sender

zecke at docs.openmoko.org zecke at docs.openmoko.org
Tue Jul 22 23:11:03 CEST 2008


Author: zecke
Date: 2008-07-22 23:11:02 +0200 (Tue, 22 Jul 2008)
New Revision: 4550

Added:
   developers/zecke/uinput-sender/
   developers/zecke/uinput-sender/uinput-sender.c
Log:
[uinput-sender] Not yet working uinput test app to send pcf50633 to test kdrive bugs...


Added: developers/zecke/uinput-sender/uinput-sender.c
===================================================================
--- developers/zecke/uinput-sender/uinput-sender.c	                        (rev 0)
+++ developers/zecke/uinput-sender/uinput-sender.c	2008-07-22 21:11:02 UTC (rev 4550)
@@ -0,0 +1,89 @@
+/* 
+ * GPLv2 or later 
+ *
+ * (C) 2008 Openmoko Inc.
+ *
+ * simple utility to send the pcf50633 keyboard events using uinput
+ */
+#include <linux/input.h>
+#include <linux/uinput.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static int key(const char* keyname)
+{
+    if (strcasecmp(keyname, "power2") == 0)
+        return KEY_POWER2;
+    else if (strcasecmp(keyname, "battery") == 0)
+        return KEY_BATTERY;
+    else if (strcasecmp(keyname, "power") == 0)
+        return KEY_POWER;
+    else if (strcasecmp(keyname, "a") == 0)
+        return KEY_A;
+
+    return -1;
+}
+
+static int value(const char* type)
+{
+    if (strcasecmp(type, "up") == 0 || strcasecmp(type, "release") == 0)
+        return 0;
+    else if (strcasecmp(type, "down") == 0 || strcasecmp(type, "press") == 0)
+        return 1;
+
+    return atoi(type);
+}
+
+int main(int argc, char** argv)
+{
+    int fd;
+    struct input_event event;
+
+    /* input checking */
+    if (argc < 3) {
+        fprintf(stderr, "%s (power2|power|battery) (1|0|release|press)\n", argv[0]);
+        exit(-1);
+    }
+
+    /* prepare params */
+    int keycode = key(argv[1]);
+    int press = value(argv[2]);
+
+    if (keycode < 0) {
+        fprintf(stderr, "Illegal keycode, try power2|power|battery\n");
+        exit(-1);
+    }
+
+    if (press != 0 && press != 1) {
+        fprintf(stderr, "Illgeal press...Come on that is not hard 0|1|press|release\n");
+        exit(-1);
+    }
+
+    /* now this can actually fail depending on permissions */
+    fd = open("/dev/input/uinput", O_WRONLY);    
+    if (fd < 0) {
+        perror("uinput open:");
+        exit(-1);
+    }
+
+    if (ioctl(fd, UI_SET_EVBIT, EV_KEY) != 0) {
+        perror("ev_key set bit");
+        exit(-1);
+    }
+
+    if (ioctl(fd, UI_SET_EVBIT, EV_PWR) != 0) {
+        perror("ev_pwr set bit");
+        exit(-1);
+    }
+
+
+    event.type = EV_KEY;
+    event.code = keycode;
+    event.value= press;
+    write(fd, &event, sizeof(event));
+}


Property changes on: developers/zecke/uinput-sender/uinput-sender.c
___________________________________________________________________
Name: svn:eol-style
   + native





More information about the commitlog mailing list