-
Notifications
You must be signed in to change notification settings - Fork 4
/
xbox360.c
99 lines (90 loc) · 4.19 KB
/
xbox360.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "xbox360.h"
#include "message.h"
int xbox360_ev_map(
const dev_in_settings_t *const conf,
const evdev_collected_t *const coll,
in_message_t *const messages,
size_t messages_len,
void* user_data
) {
int written_msg = 0;
for (uint32_t i = 0; i < coll->ev_count; ++i) {
if (coll->ev[i].type == EV_KEY) {
in_message_t current_message = {
.type = GAMEPAD_SET_ELEMENT
};
if (coll->ev[i].code == BTN_EAST) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_CIRCLE;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_NORTH) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_SQUARE;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_SOUTH) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_CROSS;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_WEST) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_TRIANGLE;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_SELECT) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_OPTION;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_START) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_SHARE;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_TR) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_R1;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_TL) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_L1;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_THUMBR) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_R3;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_THUMBL) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_L3;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_MODE) {
current_message.type = GAMEPAD_ACTION;
current_message.data.action = GAMEPAD_ACTION_PRESS_AND_RELEASE_CENTER;
}
if (written_msg == (messages_len-1)) {
return -ENOMEM;
}
messages[written_msg++] = current_message;
} else if (coll->ev[i].type == EV_ABS) {
in_message_t current_message = {
.type = GAMEPAD_SET_ELEMENT,
};
if (coll->ev[i].code == ABS_X) {
current_message.data.gamepad_set.element = GAMEPAD_LEFT_JOYSTICK_X;
current_message.data.gamepad_set.status.joystick_pos = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_Y) {
current_message.data.gamepad_set.element = GAMEPAD_LEFT_JOYSTICK_Y;
current_message.data.gamepad_set.status.joystick_pos = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_RX) {
current_message.data.gamepad_set.element = GAMEPAD_RIGHT_JOYSTICK_X;
current_message.data.gamepad_set.status.joystick_pos = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_RY) {
current_message.data.gamepad_set.element = GAMEPAD_RIGHT_JOYSTICK_Y;
current_message.data.gamepad_set.status.joystick_pos = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_Z) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_L2_TRIGGER;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == ABS_RZ) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_R2_TRIGGER;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == ABS_HAT0X) {
current_message.data.gamepad_set.element = GAMEPAD_DPAD_X;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
} else if (coll->ev[i].code == ABS_HAT0Y) {
current_message.data.gamepad_set.element = GAMEPAD_DPAD_Y;
current_message.data.gamepad_set.status.btn = coll->ev[i].value;
}
if (written_msg == (messages_len-1)) {
return -ENOMEM;
}
messages[written_msg++] = current_message;
}
}
return written_msg;
}