-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput_list.c
58 lines (46 loc) · 1.43 KB
/
input_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "input_list.h"
InputList_t *axis = NULL, *button = NULL;
USBemani_Input_t Report;
void InputList_RegisterAxis(uint16_t *input, uint16_t mask, int8_t *dest, int8_t value) {
InputList_t *child = calloc(1, sizeof(InputList_t));
child->input = input;
child->mask = mask;
child->axis = dest;
child->axis_value = value;
child->parent = axis;
axis = child;
}
void InputList_RegisterButton(uint16_t *input, uint16_t mask, uint16_t *dest, uint16_t value) {
InputList_t *child = calloc(1, sizeof(InputList_t));
child->input = input;
child->mask = mask;
child->buttons = dest;
child->button_mask = value;
child->parent = button;
button = child;
}
USBemani_Input_t *InputList_BuildReport(void) {
InputList_t *map;
// Clear report
memset(&Report, 0, sizeof(USBemani_Input_t));
Report.Slider = Input_GetRotaryLogicalPosition(0);
Report.Dial = Input_GetRotaryLogicalPosition(1);
Report.Wheel = Input_GetRotaryLogicalPosition(2);
Report.Z = Input_GetRotaryLogicalPosition(3);
Report.RZ = Input_GetRotaryLogicalPosition(4);
// Axis
map = axis;
while(map) {
if (!map->input || (*map->input & map->mask))
(*map->axis) = map->axis_value;
map = map->parent;
}
// Buttons
map = button;
while(map) {
if (!map->input || (*map->input & map->mask))
(*map->buttons) |= map->button_mask;
map = map->parent;
}
return &Report;
}