r4547 - in developers/zecke: . keytest

zecke at docs.openmoko.org zecke at docs.openmoko.org
Tue Jul 22 16:28:49 CEST 2008


Author: zecke
Date: 2008-07-22 16:28:48 +0200 (Tue, 22 Jul 2008)
New Revision: 4547

Added:
   developers/zecke/keytest/
   developers/zecke/keytest/GNUmakefile
   developers/zecke/keytest/keytest.c
Log:
Simple utility to set the keyboard in raw modus (unfinished as debugging ended there)


Added: developers/zecke/keytest/GNUmakefile
===================================================================
--- developers/zecke/keytest/GNUmakefile	                        (rev 0)
+++ developers/zecke/keytest/GNUmakefile	2008-07-22 14:28:48 UTC (rev 4547)
@@ -0,0 +1,4 @@
+all: keytest
+
+keytest: keytest.c
+	$(CC) -std=c99 -o $@ keytest.c

Added: developers/zecke/keytest/keytest.c
===================================================================
--- developers/zecke/keytest/keytest.c	                        (rev 0)
+++ developers/zecke/keytest/keytest.c	2008-07-22 14:28:48 UTC (rev 4547)
@@ -0,0 +1,92 @@
+/*
+ * Test the dev tty output, derived from my QtE keyboard patch
+ *
+ * Copyright (C) 2008 Openmoko Inc.
+ * 
+ * Author: Holger Hans Peter Freyther <zecke at openmoko.org>
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <linux/keyboard.h>
+#include <linux/kd.h>
+
+
+static void handle_key(int keycode, int press)
+{
+    printf("Key: %d press: %d\n", keycode, press);
+}
+
+static int s_highKey = 0;
+static unsigned int s_highKeyCode = 0;
+static unsigned int s_highNeedMoreKey = 0;
+static void read_keyboard(int keyboard)
+{
+    unsigned char buf[80];
+    unsigned char code;
+    int      release = 0;
+    int      release_bit;
+
+
+    int n = read(keyboard, buf, 80 );
+    printf("Read keyboard data: %d\n", n);
+    for (int loop = 0; loop < n; loop++ ) {
+        code = buf[loop] & 0x7f;
+        release_bit = buf[loop] & 0x80;
+
+        if ( s_highKey ) {
+            if ( s_highNeedMoreKey == 2 ) {
+                s_highNeedMoreKey--;
+                s_highKeyCode = code << 7;
+            }else if ( s_highNeedMoreKey == 1 ) {
+                s_highNeedMoreKey = 0;
+                s_highKeyCode |= code;
+                s_highKey = 0;
+                if ( s_highKeyCode > 127 && s_highKeyCode < NR_KEYS )
+                   handle_key( s_highKeyCode, release );
+            }
+        }else if (code == 0) {
+            s_highKey = 1;
+            s_highNeedMoreKey = 2;
+            release = release_bit;
+        }else {
+            release = release_bit;
+            handle_key(code, release);
+        }
+    }
+}
+
+int main(int argc, char** argv)
+{
+    int keyboard = open("/dev/tty0", O_RDWR);
+    if (keyboard < 0) {
+        perror("keyboard open");
+        return -1;
+    }
+
+    ioctl(keyboard, KDSKBMODE, K_MEDIUMRAW);
+
+    struct termios termdata;
+    tcgetattr( keyboard, &termdata );
+    termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+    termdata.c_oflag = 0;
+    termdata.c_cflag = CREAD | CS8;
+    termdata.c_lflag = 0;
+    termdata.c_cc[VTIME]=0;
+    termdata.c_cc[VMIN]=1;
+    cfsetispeed(&termdata, 9600);
+    cfsetospeed(&termdata, 9600);
+    tcsetattr(keyboard, TCSANOW, &termdata);
+
+    while (1) {
+        read_keyboard(keyboard);
+    }
+}


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





More information about the commitlog mailing list