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