From: ian Date: Thu, 5 Jun 2008 19:22:11 +0000 (+0000) Subject: evdev-manip builds but does not work X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=c6683327b74e6a9f2a516040072d9b1466f22298;p=trains.git evdev-manip builds but does not work --- diff --git a/hostside/.cvsignore b/hostside/.cvsignore index 89bed14..54662ce 100644 --- a/hostside/.cvsignore +++ b/hostside/.cvsignore @@ -25,3 +25,5 @@ record-y.[ch] +realtime.stderr *+dflags.h *.new +evdev-manip +input-codes.h diff --git a/hostside/Makefile b/hostside/Makefile index 3963d7c..cd51b26 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -4,11 +4,14 @@ TRAINS= santafe shinkansen AUTOINCS= auproto-pic.h layoutinfo.h selectors.h retransmit-table.h \ errorcodes.h stastate.h record-y.h record-l.h \ - realtime+dflags.h + realtime+dflags.h input-codes.h TARGETS= hostside-old gui-plan-bot realtime topology-dump \ + evdev-manip \ $(addsuffix .speeds.ps, $(TRAINS)) \ $(addsuffix .speeds.record, $(TRAINS)) +INPUT_H= /usr/include/linux/input.h + include ../common.make include ../cprogs.make @@ -73,9 +76,14 @@ realtime+dflags.h: debug-extractor $(addsuffix .c, $(REALTIME_CORE)) ./$^ >$@.new cmp $@ $@.new || mv -f $@.new $@ +evdev-manip: evdev-manip.o utils.o + safety: safety.o utils.o trackloc.o ../layout/ours.layout-data.o $(LINK) +input-codes.h: extract-input-codes $(INPUT_H) + ./$^ $o + %.speeds.ps %.speeds.record: ./analyse-speeds \ ../layout/ours.redacted.shellvars %.manual ./$< $* diff --git a/hostside/common.h b/hostside/common.h index 5c4208c..da3c8f9 100644 --- a/hostside/common.h +++ b/hostside/common.h @@ -9,8 +9,17 @@ #define COMMON_H #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include typedef struct ParseState ParseState; typedef struct CmdInfo CmdInfo; diff --git a/hostside/evdev-manip.c b/hostside/evdev-manip.c index b2651ac..6fa2c63 100644 --- a/hostside/evdev-manip.c +++ b/hostside/evdev-manip.c @@ -5,29 +5,71 @@ * --[no-]grab --nograb is default */ -#include - #include "common.h" -typedef struct { - void (*onevent)(); - void (*mainloop)(); -} ModeInfo; +#include +#include -typedef const ModeInfo *Mode; +#include +#include "input-codes.h" /* not really a header */ typedef struct { char *path; int fd; } Device; +typedef struct { + void (*event)(Device *d, const struct input_event *ie); + void (*mainloop)(void); +} ModeInfo; + +typedef const ModeInfo *Mode; + static int ndevices; static Device *devices; static Mode mode; static int grab; -static void mode_dump(void) { +static void pr_hexdec(unsigned long value) { printf("%#lx %ld",value,value); } + +#define PR_TABLE_STR(tab, val) (pr_table_str(iesis_##tab, iesin_##tab, (val))) +static void pr_table_str(const InputEventStringInfo *strings, int nstrings, + unsigned long value) { + const InputEventStringInfo *string; + if (value > nstrings) { pr_hexdec(value); return; } + string= &strings[value]; + if (!string->prefix) { pr_hexdec(value); return; } + printf("%s %s", string->prefix, string->main); +} + +static void dump_event(Device *d, const struct input_event *ie) { + const InputEventTypeInfo *t; + + printf("event "); + PR_TABLE_STR(ev, ie->type); + + printf(" "); + if (ie->type >= IETIN) { + t= 0; + } else { + t= &ietis[ie->type]; + if (!t->strings) t= 0; + } + if (t) pr_table_str(t->strings, t->nstrings, ie->code); + else pr_hexdec(ie->code); + + printf(" "); + switch (ie->type) { + case EV_ABS: + case EV_REL: + printf("%ld",(long)ie->value); + break; + default: + printf("%lx",(unsigned long)ie->value); + break; + } + printf("\n"); } static void process_device(Device *d) { @@ -38,7 +80,7 @@ static void process_device(Device *d) { printf("event-group-start device %s\n",d->path); for (;;) { - for (p=&ie, remain=sizeof(ie); + for (p=(void*)&ie, remain=sizeof(ie); remain; p+=r, remain-=r) { r= read(d->fd, &ie, remain); @@ -53,14 +95,18 @@ static void process_device(Device *d) { if (ie.type == EV_SYN) { printf("synchronised %ju.%06d\n", (uintmax_t)ie.time.tv_sec, - (int)ie.time_tv_usec); + (int)ie.time.tv_usec); break; } - + + mode->event(d, &ie); + } + mflushstdout(); } static void mainloop(void) { struct pollfd *polls; + int i, r; polls= mmalloc(sizeof(*polls)*ndevices); for (i=0; i0); for (i=0; ifd= 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); + printf("device %s bustype ", path); + PR_TABLE_STR(bus, iid.bustype); + printf(" vendor %#x product #%x version %#x\n", + iid.vendor, iid.product, iid.version); mflushstdout(); if (grab) @@ -116,11 +166,15 @@ int main(int argc, const char **argv) { if (arg[0] != '-') { getdevice(arg); } - else if (!strcmp(arg,"--dump")) { mode= mode_dump; } + 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); + else badusage("unknown option"); } mode->mainloop(); return 0; } + +const char *progname= "evdev-manip"; +void die_hook(void) { } +void die_vprintf_hook(const char *fmt, va_list al) { } diff --git a/hostside/extract-input-codes b/hostside/extract-input-codes index 7f6b645..f95b222 100755 --- a/hostside/extract-input-codes +++ b/hostside/extract-input-codes @@ -4,7 +4,7 @@ use strict 'vars'; # "/usr/include/linux/input.h -our (%strs, %checkunique); +our (%strs, %checkunique, %tabaliases, %evtypes); sub strs ($) { my ($t) = @_; @@ -12,6 +12,7 @@ sub strs ($) { } sub evtype ($) { my ($t) = @_; + $evtypes{$t}= 1; strs($t); } @@ -22,9 +23,9 @@ foreach $t (qw(EV BUS)) { foreach $t (qw(KEY REL ABS MSC LED)) { evtype($t); } -$strs{'BTN'}= $strs{'KEY'}; +$tabaliases{'BTN'}= 'KEY'; -our ($tab,$str,$val); +our ($tab,$str,$val,$s); while (<>) { if (m/^\#define (\w+)_(\w+)\s+(0|[1-9]\d+|0x[0-9a-f]+)\s*$/) { @@ -32,24 +33,89 @@ while (<>) { 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; + $t= $tabaliases{$tab} || $tab; + $s= $strs{$t}; + if (defined $s) { + die "$tab $str $val" if defined $s->[$val]; + $s->[$val]= [ $tab, $str ]; } - die "$tab $str $val" if $checkunique{$tab}{$str}++; + die "$tab $str $val" if $checkunique{$t}{"$tab $str"}++; } } -our ($s,$i); +our ($i,$iesis,$iesin,$n,$si); + +print <[$i] ? "\"$s->[$i]\"" : "0") - or die $!; + $si= $s->[$i]; + print_i(); + if (defined $si) { + printf " { %10s %-25s },\n", "\"$si->[0]\",", "\"$si->[1]\"" + or die $!; + } else { + print " { 0 },\n" + or die $!; + } } printf "};\n" or die $!; } + +for $tab (sort keys %tabaliases) { + $t= $tabaliases{$tab}; + print <[$i]; + $tab= defined $si ? $si->[1] : undef; + $tab= $tab && exists $evtypes{$tab} ? $tab : undef; + @sip= $tab ? ("IESIN_$tab", "iesis_\L$tab") : ("-1", "0"); + print_i(); + printf " { %-21s %-20s },\n", "$sip[0],", $sip[1] + or die $!; +} +print < -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include #include -#include #include #include +#include +#include + #include "../layout/layout-data.h" #include "realtime+dflags.h"