reportlocs(msg, last, msglen, vallocs);
}
+ProcessReport *const nested_processors[MAXREPORTS]= {
+ [0x4a] = pr
+};
+
const char *progname= "hidrawconv-joytechneos";
const char *const descriptor=
"05010904a101854a0901a1000501093009311580257f350045ff660000750895028102c0050209ba150026ff00750895018102050209bb150026ff007508950181020501093915012508360000463b016514750895018102950c7501050945013500150025011901290c810295040605ff09018102c005140924a101854d150026ff000931750895079182c005010906a101854b050719e029e71500250175019508810295017508810195057501050819012905910295017503910195057508150025680507190029688100c0";
+static LastReports inner_lasts;
+
+static void pr_outer(const uint8_t *msg, int msglen, const uint8_t *last) {
+ dispatch(&inner_lasts,"inner message: ",nested_processors, msg+1,msglen-1);
+}
+
ProcessReport *const report_processors[MAXREPORTS]= {
- [0x4a] = pr
+ [0x00] = pr_outer
};
* where -a means all, and the other letters are:
* -d print expected descriptor (as for hidraw-ioctl -d)
* -e pretend to be evdev-manip
+ * -E pretend to be evdev-manip, print to stderr about the device at start
* exit status:
* 0 all ok
* other some other problem
void dispatch(LastReports *lasts, const char *message_prefix,
ProcessReport *const report_processors[MAXREPORTS],
const uint8_t *msg, int l) {
+ if (!l) {
+ fprintf(stderr,"%s:%s report too short\n", progname, message_prefix);
+ return;
+ }
+
ProcessReport *pr= report_processors[msg[0]];
Last *last= &lasts->lasts[msg[0]];
if (!pr) {
memcpy(last->msg, msg, l);
}
-static void events(void) {
- uint8_t msg[MAXREPORTLEN];
+static void events(int verbose) {
+ uint8_t msg[MAXREPORTLEN+1];
+ char phys[PATH_MAX], name[PATH_MAX];
+ int rphys, errnophys=0, rname, errnoname=0;
+ int reportnumbug;
+
+ rphys= ioctl(0, HIDIOCGRAWPHYS(PATH_MAX), phys); errnophys=errno;
+ rname= ioctl(0, HIDIOCGRAWNAME(PATH_MAX), name); errnoname=errno;
+ if (rphys>=0 && rname>=0) {
+ reportnumbug= 0;
+ if (verbose)
+ fprintf(stderr,"%s: %.*s %.*s\n",progname,rphys,phys,rname,name);
+ } else if (rphys<0 && errnophys==EINVAL &&
+ rname<0 && errnoname==EINVAL) {
+ fprintf(stderr,"%s: warning, HIDIOCGRAWPHYS/NAME gave EINVAL,"
+ " assuming kernel eats report number, assuming reports are 00\n",
+ progname);
+ reportnumbug= 1;
+ } else {
+ die("HIDIOCGRAWPHYS %s / HIDIOCGRAWNAME %s",
+ rphys<0 ? strerror(errnophys) : "ok",
+ rname<0 ? strerror(errnoname) : "ok");
+ }
+
+ if (reportnumbug) msg[0]=0;
for (;;) {
- int l= read(0, msg, sizeof(msg));
+ int l= read(0, msg+reportnumbug, sizeof(msg)-reportnumbug);
if (!l) break;
if (l<0) { perror("hidrawconv: read"); exit(-1); }
+ l += reportnumbug;
dispatch(&lasts,"",report_processors, msg,l);
if (ferror(stdout) || fflush(stdout))
diee("failed flushing event to stdout");
const char *how;
if (!*argv || !(how=*++argv) || *how++!='-' || !*how || how[1] || *++argv)
- badusage("need exactly one argument, -d or -e");
+ badusage("need exactly one argument, -d, -e or -E");
switch (how[0]) {
case 'd':
puts(descriptor);
break;
+ case 'E':
+ events(1);
+ break;
+
case 'e':
- events();
+ events(0);
break;
default: