chiark / gitweb /
hostside: more length for bavarian
[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 /*----- "bits", ie keys and buttons -----*/
33
34 typedef struct {
35   const char *str;
36   int pos;
37   uint8_t mask;
38 } KeyBit;
39
40 void reportbits(const uint8_t msg[], const uint8_t last[],
41                 int len, const KeyBit keybits[]);
42
43 /*----- "vals", ie absolute values -----*/
44
45 typedef struct {
46   const char *str;
47   int pos, rshift, sign; /* mask is applied before rshift */
48   uint8_t mask, zero;
49 } ValLoc;
50
51 void reportvals(const uint8_t msg[], const uint8_t last[],
52                 int len, const ValLoc vallocs[]);
53
54
55 /*----- "hats", ie hatswitches -----*/
56
57 typedef struct {
58   int x, y;
59 } HatPosn;
60
61 typedef struct {
62   const char *str; /* base; reporter will append "X" and "Y" to this */
63   int pos, rshift, max; /* mask is applied before rshift */
64   uint8_t mask;
65   const HatPosn *posns;
66 } HatLoc;
67
68 void reporthats(const uint8_t msg[], const uint8_t last[],
69                 int len, const HatLoc hatlocs[]);
70
71 #endif /*HIDRAWCONV_H*/