-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoyjoy_app.cpp
59 lines (55 loc) · 1.57 KB
/
joyjoy_app.cpp
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
59
#include "joyjoy.h"
int main()
{
// The joyjoy class:
joyjoy myjoyjoy;
myjoyjoy.init();
struct input_event ev;
while (1)
{
int ret = myjoyjoy.poll(ev);
if (ret == 1 || ret == 0)
{
switch (ev.type) {
case EV_KEY:
if (ev.code >= BTN_MISC) {
printf("Button %d\n", myjoyjoy.key_map[ev.code - BTN_MISC]);
}
break;
case EV_ABS:
switch (ev.code) {
case ABS_HAT0X:
case ABS_HAT0Y:
case ABS_HAT1X:
case ABS_HAT1Y:
case ABS_HAT2X:
case ABS_HAT2Y:
case ABS_HAT3X:
case ABS_HAT3Y:
ev.code -= ABS_HAT0X;
printf("Hat %d Axis %d Value %d\n", ev.code / 2, ev.code % 2, ev.value);
break;
default:
printf("Axis %d Value %d\n", myjoyjoy.abs_map[ev.code], ev.value);
break;
}
break;
case EV_REL:
switch (ev.code) {
case REL_X:
case REL_Y:
ev.code -= REL_X;
printf("Ball %d Axis %d Value %d\n", ev.code / 2, ev.code % 2, ev.value);
break;
default:
break;
}
break;
}
}
else if (ret == -EAGAIN)
{
sleep(0.02);
}
}
}