Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/share/examples/rump/ukbd_read Add an example program which r...



details:   https://anonhg.NetBSD.org/src/rev/e07f0e504bfa
branches:  trunk
changeset: 750696:e07f0e504bfa
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Jan 11 02:16:51 2010 +0000

description:
Add an example program which reads keypresses from the ukbd driver
(via wscons) and simply prints them on screen.

diffstat:

 share/examples/rump/ukbd_read/Makefile |  15 +++++
 share/examples/rump/ukbd_read/kbd.c    |  97 ++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+), 0 deletions(-)

diffs (120 lines):

diff -r 8f540dc6a03c -r e07f0e504bfa share/examples/rump/ukbd_read/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/rump/ukbd_read/Makefile    Mon Jan 11 02:16:51 2010 +0000
@@ -0,0 +1,15 @@
+#      $NetBSD: Makefile,v 1.1 2010/01/11 02:16:51 pooka Exp $
+#
+
+PROG=  kbd
+
+LDADD+=        -lrumpdev_ukbd -lrumpdev_wscons -lrumpdev_usb -lrumpdev_usbhc -lrumpdev
+LDADD+=        -lrumpvfs
+LDADD+=        -lrump
+LDADD+=        -lrumpuser -lpthread
+
+DBG=   -g
+NOMAN= 
+WARNS= 4
+
+.include <bsd.prog.mk>
diff -r 8f540dc6a03c -r e07f0e504bfa share/examples/rump/ukbd_read/kbd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/rump/ukbd_read/kbd.c       Mon Jan 11 02:16:51 2010 +0000
@@ -0,0 +1,97 @@
+/*      $NetBSD: kbd.c,v 1.1 2010/01/11 02:16:51 pooka Exp $   */
+
+/*
+ * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Experimental proof-of-concept program:
+ *
+ * Read keyboard events from a USB keyboard using rump drivers.
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <dev/wscons/wsconsio.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <err.h>
+#include <paths.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define SHIFT (-0x20)
+
+int
+main(int argc, char *argv[])
+{
+       struct wscons_event *wev;
+       int shift = 0;
+       char buf[128];
+       int fd;
+
+       rump_boot_sethowto(RUMP_AB_VERBOSE);
+       rump_init();
+
+       fd = rump_sys_open("/dev/wskbd", 0);
+       if (fd == -1)
+               err(1, "open");
+
+       while (rump_sys_read(fd, buf, sizeof(buf)) > 0) {
+               const char *typestr;
+
+               /* XXX: timespec in 5.0 vs. -current */
+               wev = (void *)buf;
+
+               switch (wev->type) {
+               case WSCONS_EVENT_KEY_UP:
+                       typestr = "up";
+                       if (wev->value == 0xe1 || wev->value == 0xe5)
+                               shift = 0;
+                       break;
+               case WSCONS_EVENT_KEY_DOWN:
+                       typestr = "down";
+                       if (wev->value == 0xe1 || wev->value == 0xe5)
+                               shift = SHIFT;
+                       break;
+               default:
+                       typestr = "unknown";
+                       break;
+               }
+               printf("event type: %d (%s)\n", wev->type, typestr);
+               printf("value 0x%x", wev->value);
+               /*
+                * There's probably a value-to-readable tool somewhere
+                * in the tree, but i'm not sure where or how to use it,
+                * so I'll just punt with the supersimple version for now.
+                */
+               if (wev->value >= 0x04 && wev->value <= 0x1d)
+                       printf(" (%c)", wev->value - 0x04 + 'a' + shift);
+               printf("\n");
+       }
+}



Home | Main Index | Thread Index | Old Index