chiark / gitweb /
hostside: hidrawconv: factor out most of the reporter functions' bodies into macros
[trains.git] / hostside / hidrawconv.h
1 #ifndef HIDRAWCONV_H
2 #define HIDRAWCONV_H
3
4 #include <stdio.h>
5 #include <stdint.h>
6
7 #include <sys/ioctl.h>
8 #include <sys/types.h>
9
10 #include <linux/types.h>
11
12 #include "hidraw.h"
13
14 #include "common.h"
15
16 #define MAXREPORTLEN 256
17 #define MAXREPORTS 256
18
19 typedef struct { int len; uint8_t *msg; } Last;
20 typedef struct { Last lasts[MAXREPORTS]; } LastReports;
21 typedef void ProcessReport(const uint8_t *msg, int msglen, const uint8_t *last);
22
23 extern const char *const descriptor;
24 extern ProcessReport *const report_processors[MAXREPORTS];
25
26 void dispatch(LastReports *lasts, const char *message_prefix,
27               ProcessReport *const report_processors[MAXREPORTS],
28               const uint8_t *msg, int l);
29
30 /*---------- specific reporters ----------*/
31
32 typedef struct {
33   const char *str;
34   int pos;
35   uint8_t mask;
36 } KeyBit;
37
38 void reportbits(const uint8_t msg[], const uint8_t last[],
39                 int len, const KeyBit bits[]);
40
41
42 typedef struct {
43   const char *str;
44   int pos, rshift, sign; /* mask is applied before rshift */
45   uint8_t mask, zero;
46 } ValLoc;
47
48 void reportlocs(const uint8_t msg[], const uint8_t last[],
49                 int len, const ValLoc locs[]);
50
51
52 #endif /*HIDRAWCONV_H*/