From: ian Date: Thu, 5 Jun 2008 00:19:08 +0000 (+0000) Subject: wip extract-input-codes etc. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=71310cc0e094d5a2396826859781c38d3742131d;p=trains.git wip extract-input-codes etc. --- diff --git a/hostside/evdev-manip.c b/hostside/evdev-manip.c new file mode 100644 index 0000000..b2651ac --- /dev/null +++ b/hostside/evdev-manip.c @@ -0,0 +1,126 @@ +/* + * evdev-manip [ ...] + * options: + * --dump default + * --[no-]grab --nograb is default + */ + +#include + +#include "common.h" + +typedef struct { + void (*onevent)(); + void (*mainloop)(); +} ModeInfo; + +typedef const ModeInfo *Mode; + +typedef struct { + char *path; + int fd; +} Device; + +static int ndevices; +static Device *devices; + +static Mode mode; +static int grab; + +static void mode_dump(void) { +} + +static void process_device(Device *d) { + struct input_event ie; + int r, remain; + char *p; + + printf("event-group-start device %s\n",d->path); + + for (;;) { + for (p=&ie, remain=sizeof(ie); + remain; + p+=r, remain-=r) { + r= read(d->fd, &ie, remain); + if (r<0) { + if (errno==EINTR) continue; + diee("%s: error reading", d->path); + } + if (r==0) + die("%s: eof ?!", d->path); + assert(r <= remain); + } + if (ie.type == EV_SYN) { + printf("synchronised %ju.%06d\n", + (uintmax_t)ie.time.tv_sec, + (int)ie.time_tv_usec); + break; + } + +} + +static void mainloop(void) { + struct pollfd *polls; + + polls= mmalloc(sizeof(*polls)*ndevices); + for (i=0; i0); + + for (i=0; ipath= mstrdup(path); + d->fd= open(path, O_RDONLY); if (d->fd<0) diee("%s: failed to open",path); + + r= ioctl(d->fd, EVIOCGID, &iid); if (r) diee("%s: failed to get id",path); + printf("device %s bustype %#x vendor %#x product #%x version %#x\n" + path, iid.bustype, iid.vendor, iid.product, iid.version); + mflushstdout(); + + if (grab) + r= ioctl(d->fd, EVIOCGRAB, 1); if (r) diee("%s: failed to grab",path); +} + +int main(int argc, const char **argv) { + const char *arg; + + while ((arg= *++argv)) { + if (arg[0] != '-') { + getdevice(arg); + } + else if (!strcmp(arg,"--dump")) { mode= mode_dump; } + else if (!strcmp(arg,"--grab")) { grab= 1; } + else if (!strcmp(arg,"--no-grab")) { grab= 0; } + else badusage("unknown option `%s'",arg); + } + mode->mainloop(); + return 0; +} diff --git a/hostside/extract-input-codes b/hostside/extract-input-codes new file mode 100755 index 0000000..7f6b645 --- /dev/null +++ b/hostside/extract-input-codes @@ -0,0 +1,55 @@ +#!/usr/bin/perl -w + +use strict 'vars'; + +# "/usr/include/linux/input.h + +our (%strs, %checkunique); + +sub strs ($) { + my ($t) = @_; + $strs{$t}= [ ]; +} +sub evtype ($) { + my ($t) = @_; + strs($t); +} + +our ($t); +foreach $t (qw(EV BUS)) { + strs($t); +} +foreach $t (qw(KEY REL ABS MSC LED)) { + evtype($t); +} +$strs{'BTN'}= $strs{'KEY'}; + +our ($tab,$str,$val); + +while (<>) { + if (m/^\#define (\w+)_(\w+)\s+(0|[1-9]\d+|0x[0-9a-f]+)\s*$/) { + ($tab,$str,$val)=($1,$2, eval $3); + next if "${tab}_${str}" =~ + m/^BTN_(?:MISC|MOUSE|JOYSTICK|GAMEPAD|DIGI)$|^EV_VERSION$/; + next if $str eq 'MAX'; + if (exists($strs{$tab})) { + die "$tab $str $val" if defined $strs{$tab}[$val]; + $strs{$tab}[$val]= $str; + } + die "$tab $str $val" if $checkunique{$tab}{$str}++; + } +} + +our ($s,$i); + +for $t (sort keys %strs) { + printf "static const char *iesis_%s[]= {\n", lc $t + or die $!; + $s= $strs{$t}; + for ($i=0; $i<@$s; $i++) { + printf " %s,\n", (defined $s->[$i] ? "\"$s->[$i]\"" : "0") + or die $!; + } + printf "};\n" + or die $!; +}