16
16
class BleGamepad
17
17
{
18
18
private:
19
+ uint8_t _buttons[16 ]; // 8 bits x 16 bytes = 128 bits --> 128 button max
20
+ uint8_t _specialButtons;
21
+
22
+ int16_t _x, _y, _z, _rX, _rY, _rZ, _slider1, _slider2;
23
+ int16_t _rudder, _throttle, _accelerator, _brake, _steering;
24
+ int16_t _hat1, _hat2, _hat3, _hat4;
25
+ int16_t _gX, _gY, _gZ, _aX, _aY, _aZ;
26
+
27
+ uint8_t _batteryPowerInformation, _dischargingState, _chargingState, _powerLevel;
28
+
29
+ NimBLEHIDDevice *hid;
30
+ NimBLECharacteristic *pCharacteristic_Power_State;
31
+
32
+ NimBLEServer *pServer;
33
+ BleNUS *nus;
34
+
19
35
std::string deviceManufacturer;
20
36
std::string deviceName;
37
+
21
38
uint8_t tempHidReportDescriptor[150 ];
22
39
int hidReportDescriptorSize;
23
40
uint8_t hidReportSize;
24
41
uint8_t numOfButtonBytes;
25
42
bool enableOutputReport;
26
43
uint16_t outputReportLength;
27
- uint8_t _buttons[16 ]; // 8 bits x 16 bytes = 128 bits --> 128 button max
28
- uint8_t _specialButtons;
29
- int16_t _x;
30
- int16_t _y;
31
- int16_t _z;
32
- int16_t _rX;
33
- int16_t _rY;
34
- int16_t _rZ;
35
- int16_t _slider1;
36
- int16_t _slider2;
37
- int16_t _rudder;
38
- int16_t _throttle;
39
- int16_t _accelerator;
40
- int16_t _brake;
41
- int16_t _steering;
42
- int16_t _hat1;
43
- int16_t _hat2;
44
- int16_t _hat3;
45
- int16_t _hat4;
46
- int16_t _gX;
47
- int16_t _gY;
48
- int16_t _gZ;
49
- int16_t _aX;
50
- int16_t _aY;
51
- int16_t _aZ;
52
- uint8_t _batteryPowerInformation;
53
- uint8_t _dischargingState;
54
- uint8_t _chargingState;
55
- uint8_t _powerLevel;
56
44
bool nusInitialized;
57
45
58
- // BleGamepadConfiguration configuration;
59
-
60
46
BleConnectionStatus *connectionStatus;
61
-
62
47
BleOutputReceiver *outputReceiver;
63
-
64
- NimBLEServer *pServer;
65
- BleNUS* nus;
66
48
67
- NimBLEHIDDevice *hid;
68
49
NimBLECharacteristic *inputGamepad;
69
50
NimBLECharacteristic *outputGamepad;
70
- NimBLECharacteristic *pCharacteristic_Power_State;
71
-
72
51
uint8_t *outputBackupBuffer;
73
52
74
53
void rawAction (uint8_t msg[], char msgSize);
@@ -77,16 +56,21 @@ class BleGamepad
77
56
78
57
public:
79
58
BleGamepadConfiguration configuration;
80
-
59
+
81
60
BleGamepad (std::string deviceName = " ESP32 BLE Gamepad" , std::string deviceManufacturer = " Espressif" , uint8_t batteryLevel = 100 , bool delayAdvertising = false );
61
+
82
62
void begin (BleGamepadConfiguration *config = new BleGamepadConfiguration());
83
63
void end (void );
64
+
84
65
void setAxes (int16_t x = 0 , int16_t y = 0 , int16_t z = 0 , int16_t rX = 0 , int16_t rY = 0 , int16_t rZ = 0 , int16_t slider1 = 0 , int16_t slider2 = 0 );
85
66
void setHIDAxes (int16_t x = 0 , int16_t y = 0 , int16_t z = 0 , int16_t rZ = 0 , int16_t rX = 0 , int16_t rY = 0 , int16_t slider1 = 0 , int16_t slider2 = 0 );
86
- void press (uint8_t b = BUTTON_1); // press BUTTON_1 by default
87
- void release (uint8_t b = BUTTON_1); // release BUTTON_1 by default
67
+
68
+ void press (uint8_t b = BUTTON_1);
69
+ void release (uint8_t b = BUTTON_1);
70
+
88
71
void pressSpecialButton (uint8_t b);
89
72
void releaseSpecialButton (uint8_t b);
73
+
90
74
void pressStart ();
91
75
void releaseStart ();
92
76
void pressSelect ();
@@ -103,61 +87,73 @@ class BleGamepad
103
87
void releaseVolumeDec ();
104
88
void pressVolumeMute ();
105
89
void releaseVolumeMute ();
90
+
106
91
void setLeftThumb (int16_t x = 0 , int16_t y = 0 );
107
92
void setRightThumb (int16_t z = 0 , int16_t rZ = 0 );
108
93
void setRightThumbAndroid (int16_t z = 0 , int16_t rX = 0 );
109
94
void setLeftTrigger (int16_t rX = 0 );
110
95
void setRightTrigger (int16_t rY = 0 );
111
96
void setTriggers (int16_t rX = 0 , int16_t rY = 0 );
97
+
112
98
void setHats (signed char hat1 = 0 , signed char hat2 = 0 , signed char hat3 = 0 , signed char hat4 = 0 );
113
99
void setHat (signed char hat = 0 );
114
100
void setHat1 (signed char hat1 = 0 );
115
101
void setHat2 (signed char hat2 = 0 );
116
102
void setHat3 (signed char hat3 = 0 );
117
103
void setHat4 (signed char hat4 = 0 );
104
+
118
105
void setX (int16_t x = 0 );
119
106
void setY (int16_t y = 0 );
120
107
void setZ (int16_t z = 0 );
121
108
void setRZ (int16_t rZ = 0 );
122
109
void setRX (int16_t rX = 0 );
123
110
void setRY (int16_t rY = 0 );
111
+
124
112
void setSliders (int16_t slider1 = 0 , int16_t slider2 = 0 );
125
113
void setSlider (int16_t slider = 0 );
126
114
void setSlider1 (int16_t slider1 = 0 );
127
115
void setSlider2 (int16_t slider2 = 0 );
116
+
128
117
void setRudder (int16_t rudder = 0 );
129
118
void setThrottle (int16_t throttle = 0 );
130
119
void setAccelerator (int16_t accelerator = 0 );
131
120
void setBrake (int16_t brake = 0 );
132
121
void setSteering (int16_t steering = 0 );
122
+
133
123
void setSimulationControls (int16_t rudder = 0 , int16_t throttle = 0 , int16_t accelerator = 0 , int16_t brake = 0 , int16_t steering = 0 );
124
+
134
125
void sendReport ();
135
- bool isPressed (uint8_t b = BUTTON_1); // check BUTTON_1 by default
126
+ bool isPressed (uint8_t b = BUTTON_1);
136
127
bool isConnected (void );
137
128
void resetButtons ();
129
+
138
130
void setBatteryLevel (uint8_t level);
139
131
void setPowerStateAll (uint8_t batteryPowerInformation, uint8_t dischargingState, uint8_t chargingState, uint8_t powerLevel);
140
132
void setBatteryPowerInformation (uint8_t batteryPowerInformation);
141
133
void setDischargingState (uint8_t dischargingState);
142
134
void setChargingState (uint8_t chargingState);
143
135
void setPowerLevel (uint8_t powerLevel);
136
+
144
137
void setTXPowerLevel (int8_t level = 9 );
145
138
int8_t getTXPowerLevel ();
146
- uint8_t batteryLevel;
147
- bool delayAdvertising;
139
+
148
140
bool isOutputReceived ();
149
141
uint8_t * getOutputBuffer ();
142
+
150
143
bool deleteBond (bool resetBoard = false );
151
144
bool deleteAllBonds (bool resetBoard = false );
152
145
bool enterPairingMode ();
146
+
153
147
NimBLEAddress getAddress ();
154
148
String getStringAddress ();
155
149
NimBLEConnInfo getPeerInfo ();
156
150
String getDeviceName ();
157
151
String getDeviceManufacturer ();
152
+
158
153
void setGyroscope (int16_t gX = 0 , int16_t gY = 0 , int16_t gZ = 0 );
159
154
void setAccelerometer (int16_t aX = 0 , int16_t aY = 0 , int16_t aZ = 0 );
160
155
void setMotionControls (int16_t gX = 0 , int16_t gY = 0 , int16_t gZ = 0 , int16_t aX = 0 , int16_t aY = 0 , int16_t aZ = 0 );
156
+
161
157
void beginNUS ();
162
158
void sendDataOverNUS (const uint8_t * data, size_t length);
163
159
void setNUSDataReceivedCallback (void (*callback)(const uint8_t * data, size_t length));
@@ -169,4 +165,4 @@ class BleGamepad
169
165
170
166
#endif // CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
171
167
#endif // CONFIG_BT_ENABLED
172
- #endif // ESP32_BLE_GAMEPAD_H
168
+ #endif // ESP32_BLE_GAMEPAD_H
0 commit comments