-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathBleGamepadConfiguration.cpp
More file actions
336 lines (315 loc) · 19.2 KB
/
Copy pathBleGamepadConfiguration.cpp
File metadata and controls
336 lines (315 loc) · 19.2 KB
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include "BleGamepadConfiguration.h"
BleGamepadConfiguration::BleGamepadConfiguration() : _controllerType(CONTROLLER_TYPE_GAMEPAD),
_autoReport(true),
_hidReportId(3),
_buttonCount(16),
_hatSwitchCount(1),
_whichSpecialButtons{false, false, false, false, false, false, false, false},
_whichAxes{true, true, true, true, true, true, true, true},
_whichSimulationControls{false, false, false, false, false},
_includeGyroscope(false),
_includeAccelerometer(false),
_vid(0xe502),
_pid(0xbbab),
_guidVersion(0x0110),
_axesMin(0x8000),
_axesMax(0x7FFF),
_simulationMin(0x0000),
_simulationMax(0x7FFF),
_motionMin(0x0000),
_motionMax(0x7FFF),
_modelNumber("1.0.0"),
_softwareRevision("1.0.0"),
_serialNumber("0123456789"),
_firmwareRevision("0.8.0"),
_hardwareRevision("1.0.0"),
_enableOutputReport(false),
_enableFeatureReport(false),
_enableRumble(false),
_enablePlayerLED(false),
_enableSInput(false),
_enableSInputIMU(false),
_enableSInputRGB(false),
_gamepadMode(GamepadMode::Generic),
_outputReportLength(64),
_featureReportLength(64),
_transmitPowerLevel(9),
_sinputGamepadType(1),
_sinputFaceStyle(1),
_enableTouchpad(false),
_touchpadCount(0),
_touchpadFingerCount(1)
{
}
uint8_t BleGamepadConfiguration::getTotalSpecialButtonCount() const
{
int count = 0;
for (int i = 0; i < POSSIBLESPECIALBUTTONS; i++)
{
count += (int)_whichSpecialButtons[i];
}
return count;
}
uint8_t BleGamepadConfiguration::getDesktopSpecialButtonCount() const
{
int count = 0;
for (int i = 0; i < 3; i++)
{
count += (int)_whichSpecialButtons[i];
}
return count;
}
uint8_t BleGamepadConfiguration::getConsumerSpecialButtonCount() const
{
int count = 0;
for (int i = 3; i < 8; i++)
{
count += (int)_whichSpecialButtons[i];
}
return count;
}
uint8_t BleGamepadConfiguration::getAxisCount() const
{
int count = 0;
for (int i = 0; i < POSSIBLEAXES; i++)
{
count += (int)_whichAxes[i];
}
return count;
}
uint8_t BleGamepadConfiguration::getSimulationCount() const
{
int count = 0;
for (int i = 0; i < POSSIBLESIMULATIONCONTROLS; i++)
{
count += (int)_whichSimulationControls[i];
}
return count;
}
uint16_t BleGamepadConfiguration::getVid() const { return _vid; }
uint16_t BleGamepadConfiguration::getPid() const { return _pid; }
uint16_t BleGamepadConfiguration::getGuidVersion() const { return _guidVersion; }
int16_t BleGamepadConfiguration::getAxesMin() const { return _axesMin; }
int16_t BleGamepadConfiguration::getAxesMax() const { return _axesMax; }
int16_t BleGamepadConfiguration::getSimulationMin() const { return _simulationMin; }
int16_t BleGamepadConfiguration::getSimulationMax() const { return _simulationMax; }
int16_t BleGamepadConfiguration::getMotionMin() const { return _motionMin; }
int16_t BleGamepadConfiguration::getMotionMax() const { return _motionMax; }
uint8_t BleGamepadConfiguration::getControllerType() const { return _controllerType; }
uint8_t BleGamepadConfiguration::getHidReportId() const { return _hidReportId; }
uint16_t BleGamepadConfiguration::getButtonCount() const { return _buttonCount; }
uint8_t BleGamepadConfiguration::getHatSwitchCount() const { return _hatSwitchCount; }
bool BleGamepadConfiguration::getAutoReport() const { return _autoReport; }
bool BleGamepadConfiguration::getIncludeStart() const { return _whichSpecialButtons[START_BUTTON]; }
bool BleGamepadConfiguration::getIncludeSelect() const { return _whichSpecialButtons[SELECT_BUTTON]; }
bool BleGamepadConfiguration::getIncludeMenu() const { return _whichSpecialButtons[MENU_BUTTON]; }
bool BleGamepadConfiguration::getIncludeHome() const { return _whichSpecialButtons[HOME_BUTTON]; }
bool BleGamepadConfiguration::getIncludeBack() const { return _whichSpecialButtons[BACK_BUTTON]; }
bool BleGamepadConfiguration::getIncludeVolumeInc() const { return _whichSpecialButtons[VOLUME_INC_BUTTON]; }
bool BleGamepadConfiguration::getIncludeVolumeDec() const { return _whichSpecialButtons[VOLUME_DEC_BUTTON]; }
bool BleGamepadConfiguration::getIncludeVolumeMute() const { return _whichSpecialButtons[VOLUME_MUTE_BUTTON]; }
const bool *BleGamepadConfiguration::getWhichSpecialButtons() const { return _whichSpecialButtons; }
bool BleGamepadConfiguration::getIncludeXAxis() const { return _whichAxes[X_AXIS]; }
bool BleGamepadConfiguration::getIncludeYAxis() const { return _whichAxes[Y_AXIS]; }
bool BleGamepadConfiguration::getIncludeZAxis() const { return _whichAxes[Z_AXIS]; }
bool BleGamepadConfiguration::getIncludeRxAxis() const { return _whichAxes[RX_AXIS]; }
bool BleGamepadConfiguration::getIncludeRyAxis() const { return _whichAxes[RY_AXIS]; }
bool BleGamepadConfiguration::getIncludeRzAxis() const { return _whichAxes[RZ_AXIS]; }
bool BleGamepadConfiguration::getIncludeSlider1() const { return _whichAxes[SLIDER1]; }
bool BleGamepadConfiguration::getIncludeSlider2() const { return _whichAxes[SLIDER2]; }
const bool *BleGamepadConfiguration::getWhichAxes() const { return _whichAxes; }
bool BleGamepadConfiguration::getIncludeRudder() const { return _whichSimulationControls[RUDDER]; }
bool BleGamepadConfiguration::getIncludeThrottle() const { return _whichSimulationControls[THROTTLE]; }
bool BleGamepadConfiguration::getIncludeAccelerator() const { return _whichSimulationControls[ACCELERATOR]; }
bool BleGamepadConfiguration::getIncludeBrake() const { return _whichSimulationControls[BRAKE]; }
bool BleGamepadConfiguration::getIncludeSteering() const { return _whichSimulationControls[STEERING]; }
const bool *BleGamepadConfiguration::getWhichSimulationControls() const { return _whichSimulationControls; }
bool BleGamepadConfiguration::getIncludeGyroscope() const { return _includeGyroscope; }
bool BleGamepadConfiguration::getIncludeAccelerometer() const { return _includeAccelerometer; }
const char *BleGamepadConfiguration::getModelNumber() const { return _modelNumber; }
const char *BleGamepadConfiguration::getSoftwareRevision() const { return _softwareRevision; }
const char *BleGamepadConfiguration::getSerialNumber() const { return _serialNumber; }
const char *BleGamepadConfiguration::getFirmwareRevision() const { return _firmwareRevision; }
const char *BleGamepadConfiguration::getHardwareRevision() const { return _hardwareRevision; }
bool BleGamepadConfiguration::getEnableOutputReport() const { return _enableOutputReport; }
bool BleGamepadConfiguration::getEnableFeatureReport() const { return _enableFeatureReport; }
bool BleGamepadConfiguration::getEnableRumble() const { return _enableRumble; }
bool BleGamepadConfiguration::getEnablePlayerLED() const { return _enablePlayerLED; }
bool BleGamepadConfiguration::getEnableSInput() const { return _enableSInput; }
bool BleGamepadConfiguration::getEnableSInputIMU() const { return _enableSInputIMU; }
bool BleGamepadConfiguration::getEnableSInputRGB() const { return _enableSInputRGB; }
GamepadMode BleGamepadConfiguration::getGamepadMode() const { return _gamepadMode; }
uint16_t BleGamepadConfiguration::getOutputReportLength() const { return _outputReportLength; }
uint16_t BleGamepadConfiguration::getFeatureReportLength() const { return _featureReportLength; }
int8_t BleGamepadConfiguration::getTXPowerLevel() const { return _transmitPowerLevel; } // Returns the power level that was set as the server started
void BleGamepadConfiguration::setWhichSpecialButtons(bool start, bool select, bool menu, bool home, bool back, bool volumeInc, bool volumeDec, bool volumeMute)
{
_whichSpecialButtons[START_BUTTON] = start;
_whichSpecialButtons[SELECT_BUTTON] = select;
_whichSpecialButtons[MENU_BUTTON] = menu;
_whichSpecialButtons[HOME_BUTTON] = home;
_whichSpecialButtons[BACK_BUTTON] = back;
_whichSpecialButtons[VOLUME_INC_BUTTON] = volumeInc;
_whichSpecialButtons[VOLUME_DEC_BUTTON] = volumeDec;
_whichSpecialButtons[VOLUME_MUTE_BUTTON] = volumeMute;
}
void BleGamepadConfiguration::setWhichAxes(bool xAxis, bool yAxis, bool zAxis, bool rxAxis, bool ryAxis, bool rzAxis, bool slider1, bool slider2)
{
_whichAxes[X_AXIS] = xAxis;
_whichAxes[Y_AXIS] = yAxis;
_whichAxes[Z_AXIS] = zAxis;
_whichAxes[RZ_AXIS] = rzAxis;
_whichAxes[RX_AXIS] = rxAxis;
_whichAxes[RY_AXIS] = ryAxis;
_whichAxes[SLIDER1] = slider1;
_whichAxes[SLIDER2] = slider2;
}
void BleGamepadConfiguration::setWhichSimulationControls(bool rudder, bool throttle, bool accelerator, bool brake, bool steering)
{
_whichSimulationControls[RUDDER] = rudder;
_whichSimulationControls[THROTTLE] = throttle;
_whichSimulationControls[ACCELERATOR] = accelerator;
_whichSimulationControls[BRAKE] = brake;
_whichSimulationControls[STEERING] = steering;
}
void BleGamepadConfiguration::setControllerType(uint8_t value) { _controllerType = value; }
void BleGamepadConfiguration::setHidReportId(uint8_t value) { _hidReportId = value; }
void BleGamepadConfiguration::setButtonCount(uint16_t value) { _buttonCount = value; }
void BleGamepadConfiguration::setHatSwitchCount(uint8_t value) { _hatSwitchCount = value; }
void BleGamepadConfiguration::setAutoReport(bool value) { _autoReport = value; }
void BleGamepadConfiguration::setIncludeStart(bool value) { _whichSpecialButtons[START_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeSelect(bool value) { _whichSpecialButtons[SELECT_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeMenu(bool value) { _whichSpecialButtons[MENU_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeHome(bool value) { _whichSpecialButtons[HOME_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeBack(bool value) { _whichSpecialButtons[BACK_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeVolumeInc(bool value) { _whichSpecialButtons[VOLUME_INC_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeVolumeDec(bool value) { _whichSpecialButtons[VOLUME_DEC_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeVolumeMute(bool value) { _whichSpecialButtons[VOLUME_MUTE_BUTTON] = value; }
void BleGamepadConfiguration::setIncludeXAxis(bool value) { _whichAxes[X_AXIS] = value; }
void BleGamepadConfiguration::setIncludeYAxis(bool value) { _whichAxes[Y_AXIS] = value; }
void BleGamepadConfiguration::setIncludeZAxis(bool value) { _whichAxes[Z_AXIS] = value; }
void BleGamepadConfiguration::setIncludeRzAxis(bool value) { _whichAxes[RZ_AXIS] = value; }
void BleGamepadConfiguration::setIncludeRxAxis(bool value) { _whichAxes[RX_AXIS] = value; }
void BleGamepadConfiguration::setIncludeRyAxis(bool value) { _whichAxes[RY_AXIS] = value; }
void BleGamepadConfiguration::setIncludeSlider1(bool value) { _whichAxes[SLIDER1] = value; }
void BleGamepadConfiguration::setIncludeSlider2(bool value) { _whichAxes[SLIDER2] = value; }
void BleGamepadConfiguration::setIncludeRudder(bool value) { _whichSimulationControls[RUDDER] = value; }
void BleGamepadConfiguration::setIncludeThrottle(bool value) { _whichSimulationControls[THROTTLE] = value; }
void BleGamepadConfiguration::setIncludeAccelerator(bool value) { _whichSimulationControls[ACCELERATOR] = value; }
void BleGamepadConfiguration::setIncludeBrake(bool value) { _whichSimulationControls[BRAKE] = value; }
void BleGamepadConfiguration::setIncludeSteering(bool value) { _whichSimulationControls[STEERING] = value; }
void BleGamepadConfiguration::setIncludeGyroscope(bool value) { _includeGyroscope = value; }
void BleGamepadConfiguration::setIncludeAccelerometer(bool value) { _includeAccelerometer = value; }
void BleGamepadConfiguration::setVid(uint16_t value) { _vid = value; }
void BleGamepadConfiguration::setPid(uint16_t value) { _pid = value; }
void BleGamepadConfiguration::setGuidVersion(uint16_t value) { _guidVersion = value; }
void BleGamepadConfiguration::setAxesMin(int16_t value) { _axesMin = value; }
void BleGamepadConfiguration::setAxesMax(int16_t value) { _axesMax = value; }
void BleGamepadConfiguration::setSimulationMin(int16_t value) { _simulationMin = value; }
void BleGamepadConfiguration::setSimulationMax(int16_t value) { _simulationMax = value; }
void BleGamepadConfiguration::setMotionMin(int16_t value) { _motionMin = value; }
void BleGamepadConfiguration::setMotionMax(int16_t value) { _motionMax = value; }
void BleGamepadConfiguration::setModelNumber(const char *value) { _modelNumber = value; }
void BleGamepadConfiguration::setSoftwareRevision(const char *value) { _softwareRevision = value; }
void BleGamepadConfiguration::setSerialNumber(const char *value) { _serialNumber = value; }
void BleGamepadConfiguration::setFirmwareRevision(const char *value) { _firmwareRevision = value; }
void BleGamepadConfiguration::setHardwareRevision(const char *value) { _hardwareRevision = value; }
void BleGamepadConfiguration::setEnableOutputReport(bool value) { _enableOutputReport = value; }
void BleGamepadConfiguration::setEnableFeatureReport(bool value) { _enableFeatureReport = value; }
void BleGamepadConfiguration::setEnableRumble(bool value) { _enableRumble = value; }
void BleGamepadConfiguration::setEnablePlayerLED(bool value) { _enablePlayerLED = value; }
void BleGamepadConfiguration::setEnableSInput(bool value)
{
_enableSInput = value;
if (value)
{
_gamepadMode = GamepadMode::SInput;
// SDL's SInput hidapi driver only matches this exact VID/PID pair (see the
// SINPUT_USB_VID/SINPUT_USB_PID_GENERIC comment above) -- default to it so
// SInput mode works out of the box. Call setVid()/setPid() after this to override.
_vid = SINPUT_USB_VID;
_pid = SINPUT_USB_PID_GENERIC;
_buttonCount = 25;
}
else if (_gamepadMode == GamepadMode::SInput)
{
_gamepadMode = GamepadMode::Generic;
}
}
void BleGamepadConfiguration::setGamepadMode(GamepadMode mode)
{
_gamepadMode = mode;
if (mode == GamepadMode::SInput)
{
_enableSInput = true;
_vid = SINPUT_USB_VID;
_pid = SINPUT_USB_PID_GENERIC;
_buttonCount = 25;
_hatSwitchCount = 1;
_whichSimulationControls[RUDDER] = false;
_whichSimulationControls[THROTTLE] = false;
_whichSimulationControls[ACCELERATOR] = false;
_whichSimulationControls[BRAKE] = false;
_whichSimulationControls[STEERING] = false;
_whichAxes[SLIDER1] = false;
_whichAxes[SLIDER2] = false;
_includeGyroscope = false;
_includeAccelerometer = false;
_enableOutputReport = false;
_enableFeatureReport = false;
_enableRumble = true;
_enableTouchpad = true;
_touchpadCount = 1;
_touchpadFingerCount = 2;
_whichSpecialButtons[START_BUTTON] = true;
_whichSpecialButtons[SELECT_BUTTON] = true;
_whichSpecialButtons[HOME_BUTTON] = true;
}
else if (mode == GamepadMode::XInputOneS || mode == GamepadMode::XInputSeriesX)
{
_enableSInput = false;
_vid = XINPUT_USB_VID;
_pid = (mode == GamepadMode::XInputSeriesX) ? XINPUT_PID_XBOX_SERIES_X : XINPUT_PID_XBOX_ONE_S;
_guidVersion = (mode == GamepadMode::XInputSeriesX) ? 0x0509 : 0x0408;
_buttonCount = 11;
_hatSwitchCount = 1;
_whichSimulationControls[RUDDER] = false;
_whichSimulationControls[THROTTLE] = false;
_whichSimulationControls[ACCELERATOR] = false;
_whichSimulationControls[BRAKE] = false;
_whichSimulationControls[STEERING] = false;
_whichAxes[SLIDER1] = false;
_whichAxes[SLIDER2] = false;
_includeGyroscope = false;
_includeAccelerometer = false;
_enableOutputReport = false;
_enableFeatureReport = false;
_whichSpecialButtons[START_BUTTON] = true;
_whichSpecialButtons[SELECT_BUTTON] = true;
_whichSpecialButtons[HOME_BUTTON] = true;
// Both variants have a share byte in the main input report:
// Series X = Record (Share), One S 1708 = AC Back. BACK must stay
// enabled or report.share can never be set (matches Mystfit, whose
// pressShare() works on both variants).
_whichSpecialButtons[BACK_BUTTON] = true;
}
else if (mode == GamepadMode::Generic)
{
_enableSInput = false;
}
}
void BleGamepadConfiguration::setEnableSInputIMU(bool value) { _enableSInputIMU = value; }
void BleGamepadConfiguration::setEnableSInputRGB(bool value) { _enableSInputRGB = value; }
void BleGamepadConfiguration::setOutputReportLength(uint16_t value) { _outputReportLength = value; }
void BleGamepadConfiguration::setFeatureReportLength(uint16_t value) { _featureReportLength = value; }
void BleGamepadConfiguration::setTXPowerLevel(int8_t value) { _transmitPowerLevel = value; }
uint8_t BleGamepadConfiguration::getSInputGamepadType() const { return _sinputGamepadType; }
uint8_t BleGamepadConfiguration::getSInputFaceStyle() const { return _sinputFaceStyle; }
void BleGamepadConfiguration::setSInputGamepadType(uint8_t value) { _sinputGamepadType = value; }
void BleGamepadConfiguration::setSInputFaceStyle(uint8_t value) { _sinputFaceStyle = value; }
bool BleGamepadConfiguration::getEnableTouchpad() const { return _enableTouchpad; }
uint8_t BleGamepadConfiguration::getTouchpadCount() const { return _touchpadCount; }
uint8_t BleGamepadConfiguration::getTouchpadFingerCount() const { return _touchpadFingerCount; }
void BleGamepadConfiguration::setEnableTouchpad(bool value) { _enableTouchpad = value; }
void BleGamepadConfiguration::setTouchpadCount(uint8_t value) { _touchpadCount = value; }
void BleGamepadConfiguration::setTouchpadFingerCount(uint8_t value) { _touchpadFingerCount = value; }