3 * .../hidrawconv-<controller> -d
4 * .../hidrawconv-<controller> -e </dev/hidrawN
5 * where -a means all, and the other letters are:
6 * -d print expected descriptor (as for hidraw-ioctl -d)
7 * -e pretend to be evdev-manip
10 * other some other problem
13 #include "hidrawconv.h"
15 void die_vprintf_hook(const char *fmt, va_list al) { }
16 void die_hook(void) { }
18 typedef struct { int len; uint8_t *msg; } Last;
19 static Last lasts[MAXREPORTS];
21 void reportbits(const uint8_t msg[], const uint8_t last[],
22 int len, const KeyBit *bit) {
23 for (; bit->str; bit++) {
24 if (bit->pos >= len) continue;
25 uint8_t m= msg[bit->pos] & bit->mask;
26 uint8_t l= last[bit->pos] & bit->mask;
28 printf("%s %d\n", bit->str, !!m);
32 void reportlocs(const uint8_t msg[], const uint8_t last[],
33 int len, const ValLoc *loc) {
34 for (; loc->str; loc++) {
35 if (loc->pos >= len) continue;
36 uint8_t mb= msg[loc->pos] & loc->mask;
37 uint8_t lb= last[loc->pos] & loc->mask;
41 printf("%s %d\n", loc->str, loc->sign * (int8_t)mb);
45 static void events(void) {
46 uint8_t msg[MAXREPORTLEN];
48 int l= read(0, msg, sizeof(msg));
50 if (l<0) { perror("hidrawconv: read"); exit(-1); }
51 ProcessReport *pr= report_processors[msg[0]];
52 Last *last= &lasts[msg[0]];
55 fprintf(stderr,"%s: unexpected report 0x%02x", progname, msg[0]);
60 last->msg= mrealloc(last->msg, l);
61 memset(last->msg + last->len, 0, l - last->len);
64 pr(msg, l, last->msg);
65 if (ferror(stdout) || fflush(stdout))
66 diee("failed flushing event to stdout");
67 memcpy(last->msg, msg, l);
71 int main(int argc, char **argv) {
74 if (!*argv || !(how=*++argv) || *how++!='-' || !*how || how[1] || *++argv)
75 badusage("need exactly one argument, -d or -e");
87 badusage("unknown option/mode");
90 if (ferror(stdout) || fflush(stdout))
91 diee("write/flush stdout");