forked from felis/USB_Host_Shield_2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllerEnums.h
271 lines (232 loc) · 6.54 KB
/
controllerEnums.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* Copyright (C) 2013 Kristian Lauszus, TKJ Electronics. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Kristian Lauszus, TKJ Electronics
Web : http://www.tkjelectronics.com
e-mail : [email protected]
*/
#ifndef _controllerenums_h
#define _controllerenums_h
#if defined(ESP32)
#undef PS
#endif
/**
* This header file is used to store different enums for the controllers,
* This is necessary so all the different libraries can be used at once.
*/
/** Enum used to turn on the LEDs on the different controllers. */
enum LEDEnum {
OFF = 0,
#ifndef RBL_NRF51822
LED1 = 1,
LED2 = 2,
LED3 = 3,
LED4 = 4,
#endif
LED5 = 5,
LED6 = 6,
LED7 = 7,
LED8 = 8,
LED9 = 9,
LED10 = 10,
/** Used to blink all LEDs on the Xbox controller */
ALL = 5,
};
/** Used to set the colors of the Move and PS4 controller. */
enum ColorsEnum {
/** r = 255, g = 0, b = 0 */
Red = 0xFF0000,
/** r = 0, g = 255, b = 0 */
Green = 0xFF00,
/** r = 0, g = 0, b = 255 */
Blue = 0xFF,
/** r = 255, g = 235, b = 4 */
Yellow = 0xFFEB04,
/** r = 0, g = 255, b = 255 */
Lightblue = 0xFFFF,
/** r = 255, g = 0, b = 255 */
Purple = 0xFF00FF,
Purble = 0xFF00FF,
/** r = 255, g = 255, b = 255 */
White = 0xFFFFFF,
/** r = 0, g = 0, b = 0 */
Off = 0x00,
};
enum RumbleEnum {
RumbleHigh = 0x10,
RumbleLow = 0x20,
};
/** This enum is used to read all the different buttons on the different controllers */
enum ButtonEnum {
/**@{*/
/** Directional Pad Buttons - available on most controllers */
UP = 0,
RIGHT = 1,
DOWN = 2,
LEFT = 3,
/**@}*/
/**@{*/
/** Playstation buttons */
TRIANGLE,
CIRCLE,
CROSS,
SQUARE,
SELECT,
START,
L3,
R3,
L1,
R1,
L2,
R2,
PS,
/**@}*/
/**@{*/
/** PS3 Move Controller */
MOVE, // Covers 12 bits - we only need to read the top 8
T, // Covers 12 bits - we only need to read the top 8
/**@}*/
/**@{*/
/** PS Buzz controllers */
RED,
YELLOW,
GREEN,
ORANGE,
BLUE,
/**@}*/
/**@{*/
/** PS4 buttons - SHARE and OPTIONS are present instead of SELECT and START */
SHARE,
OPTIONS,
TOUCHPAD,
/**@}*/
/**@{*/
/** PS5 buttons */
CREATE,
MICROPHONE,
/**@}*/
/**@{*/
/** Xbox buttons */
A,
B,
X,
Y,
BACK,
// START, // listed under Playstation buttons
LB,
RB,
LT,
RT,
XBOX,
SYNC,
BLACK, // Available on the original Xbox controller
WHITE, // Available on the original Xbox controller
/**@}*/
/**@{*/
/** Xbox One S buttons */
VIEW,
MENU,
/**@}*/
/**@{*/
/** Wii buttons */
PLUS,
TWO,
ONE,
MINUS,
HOME,
Z,
C,
// B, // listed under Xbox buttons
// A, // listed under Xbox buttons
/**@}*/
/**@{*/
/** Wii U Pro Controller */
L,
R,
ZL,
ZR,
/**@}*/
/**@{*/
/** Switch Pro Controller */
CAPTURE,
/**@}*/
};
inline constexpr int8_t ButtonIndex(ButtonEnum key) {
// using a chained ternary in place of a switch for constexpr on older compilers
return
(key == UP || key == RED) ? 0 :
(key == RIGHT || key == YELLOW) ? 1 :
(key == DOWN || key == GREEN) ? 2 :
(key == LEFT || key == ORANGE) ? 3 :
(key == SELECT || key == SHARE || key == BACK || key == VIEW || key == BLUE || key == CREATE || key == CAPTURE) ? 4 :
(key == START || key == OPTIONS || key == MENU || key == PLUS) ? 5 :
(key == L3 || key == TWO) ? 6 :
(key == R3 || key == ONE) ? 7 :
(key == L2 || key == LT || key == MINUS || key == BLACK) ? 8 :
(key == R2 || key == RT || key == HOME || key == WHITE) ? 9 :
(key == L1 || key == LB || key == Z) ? 10 :
(key == R1 || key == RB || key == C) ? 11 :
(key == TRIANGLE || key == B) ? 12 :
(key == CIRCLE || key == A) ? 13 :
(key == CROSS || key == X) ? 14 :
(key == SQUARE || key == Y) ? 15 :
(key == L || key == PS || key == XBOX) ? 16 :
(key == R || key == MOVE || key == TOUCHPAD || key == SYNC) ? 17 :
(key == ZL || key == T || key == MICROPHONE) ? 18 :
(key == ZR) ? 19 :
-1; // not a match
}
/** Joysticks on the PS3 and Xbox controllers. */
enum AnalogHatEnum {
/** Left joystick x-axis */
LeftHatX = 0,
/** Left joystick y-axis */
LeftHatY = 1,
/** Right joystick x-axis */
RightHatX = 2,
/** Right joystick y-axis */
RightHatY = 3,
};
/**
* Sensors inside the Sixaxis Dualshock 3, Move controller and PS4 controller.
* <B>Note:</B> that the location is shifted 9 when it's connected via USB on the PS3 controller.
*/
enum SensorEnum {
/** Accelerometer values */
aX = 50, aY = 52, aZ = 54,
/** Gyro z-axis */
gZ = 56,
gX, gY, // These are not available on the PS3 controller
/** Accelerometer x-axis */
aXmove = 28,
/** Accelerometer z-axis */
aZmove = 30,
/** Accelerometer y-axis */
aYmove = 32,
/** Gyro x-axis */
gXmove = 40,
/** Gyro z-axis */
gZmove = 42,
/** Gyro y-axis */
gYmove = 44,
/** Temperature sensor */
tempMove = 46,
/** Magnetometer x-axis */
mXmove = 47,
/** Magnetometer z-axis */
mZmove = 49,
/** Magnetometer y-axis */
mYmove = 50,
};
/** Used to get the angle calculated using the PS3 controller and PS4 controller. */
enum AngleEnum {
Pitch = 0x01,
Roll = 0x02,
};
#endif