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
12 * joystick values are always doubles from -1 to 0 to +1
15 #include "hidrawconv.h"
17 void die_vprintf_hook(const char *fmt, va_list al) { }
18 void die_hook(void) { }
20 static LastReports lasts;
22 void reportbits(const uint8_t msg[], const uint8_t last[],
23 int len, const KeyBit *bit) {
24 for (; bit->str; bit++) {
25 if (bit->pos >= len) continue;
26 uint8_t m= msg[bit->pos] & bit->mask;
27 uint8_t l= last[bit->pos] & bit->mask;
29 printf("%s %d\n", bit->str, !!m);
33 void reportlocs(const uint8_t msg[], const uint8_t last[],
34 int len, const ValLoc *loc) {
35 for (; loc->str; loc++) {
36 if (loc->pos >= len) continue;
37 uint8_t mb= msg[loc->pos] & loc->mask;
38 uint8_t lb= last[loc->pos] & loc->mask;
42 double val= (int8_t)mb;
43 val /= (val >= 0 ? 127 : 128);
44 printf("%s %.5f\n", loc->str, loc->sign * val);
48 void dispatch(LastReports *lasts, const char *message_prefix,
49 ProcessReport *const report_processors[MAXREPORTS],
50 const uint8_t *msg, int l) {
51 ProcessReport *pr= report_processors[msg[0]];
52 Last *last= &lasts->lasts[msg[0]];
55 fprintf(stderr,"%s:%s unexpected report 0x%02x\n",
56 progname, message_prefix, msg[0]);
61 last->msg= mrealloc(last->msg, l);
62 memset(last->msg + last->len, 0, l - last->len);
65 pr(msg, l, last->msg);
66 memcpy(last->msg, msg, l);
69 static void events(void) {
70 uint8_t msg[MAXREPORTLEN];
73 int l= read(0, msg, sizeof(msg));
75 if (l<0) { perror("hidrawconv: read"); exit(-1); }
76 dispatch(&lasts,"",report_processors, msg,l);
77 if (ferror(stdout) || fflush(stdout))
78 diee("failed flushing event to stdout");
82 int main(int argc, char **argv) {
85 if (!*argv || !(how=*++argv) || *how++!='-' || !*how || how[1] || *++argv)
86 badusage("need exactly one argument, -d or -e");
98 badusage("unknown option/mode");
101 if (ferror(stdout) || fflush(stdout))
102 diee("write/flush stdout");