@@ -41,12 +41,15 @@ BLEClientHidAdafruit::BLEClientHidAdafruit(void)
41
41
_protcol_mode(UUID16_CHR_PROTOCOL_MODE),
42
42
_hid_info(UUID16_CHR_HID_INFORMATION), _hid_control(UUID16_CHR_HID_CONTROL_POINT),
43
43
_kbd_boot_input(UUID16_CHR_BOOT_KEYBOARD_INPUT_REPORT), _kbd_boot_output(UUID16_CHR_BOOT_KEYBOARD_OUTPUT_REPORT),
44
- _mse_boot_input(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT)
44
+ _mse_boot_input(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT),
45
+ _gpd_report(UUID16_CHR_REPORT)
45
46
{
46
47
_kbd_cb = NULL ;
47
48
_mse_cb = NULL ;
49
+ _gpd_cb = NULL ;
48
50
varclr (&_last_kbd_report);
49
51
varclr (&_last_mse_report);
52
+ varclr (&_last_gpd_report);
50
53
}
51
54
52
55
@@ -62,6 +65,12 @@ void mse_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t
62
65
svc._handle_mse_input (data, len);
63
66
}
64
67
68
+ void gpd_client_notify_cb (BLEClientCharacteristic* chr, uint8_t * data, uint16_t len)
69
+ {
70
+ BLEClientHidAdafruit& svc = (BLEClientHidAdafruit&) chr->parentService ();
71
+ svc._handle_gpd_input (data, len);
72
+ }
73
+
65
74
66
75
bool BLEClientHidAdafruit::begin (void )
67
76
{
@@ -77,10 +86,13 @@ bool BLEClientHidAdafruit::begin(void)
77
86
78
87
_mse_boot_input.begin (this );
79
88
89
+ _gpd_report.begin (this );
90
+
80
91
81
92
// set notify callback
82
93
_kbd_boot_input.setNotifyCallback (kbd_client_notify_cb);
83
94
_mse_boot_input.setNotifyCallback (mse_client_notify_cb);
95
+ _gpd_report.setNotifyCallback (gpd_client_notify_cb);
84
96
85
97
return true ;
86
98
}
@@ -95,17 +107,36 @@ void BLEClientHidAdafruit::setMouseReportCallback(mse_callback_t fp)
95
107
_mse_cb = fp;
96
108
}
97
109
110
+ void BLEClientHidAdafruit::setGamepadReportCallback (gpd_callback_t fp)
111
+ {
112
+ _gpd_cb = fp;
113
+ }
114
+
115
+
98
116
bool BLEClientHidAdafruit::discover (uint16_t conn_handle)
99
117
{
100
118
// Call Base class discover
101
119
VERIFY ( BLEClientService::discover (conn_handle) );
102
120
_conn_hdl = BLE_CONN_HANDLE_INVALID; // make as invalid until we found all chars
103
121
104
122
// Discover all characteristics
105
- Bluefruit.Discovery .discoverCharacteristic (conn_handle, _protcol_mode, _kbd_boot_input, _kbd_boot_output, _mse_boot_input, _hid_info, _hid_control);
123
+ Bluefruit.Discovery .discoverCharacteristic (conn_handle, _protcol_mode, _kbd_boot_input, _kbd_boot_output, _hid_info, _hid_control, _gpd_report);
124
+
125
+ Serial.print (" _protcol_mode.discovered(): " );
126
+ Serial.println (_protcol_mode.discovered ());
127
+
128
+ Serial.print (" _hid_info.discovered(): " );
129
+ Serial.println (_hid_info.discovered ());
130
+
131
+ Serial.print (" _hid_control.discovered(): " );
132
+ Serial.println (_hid_control.discovered ());
106
133
107
- VERIFY ( _protcol_mode.discovered () && _hid_info.discovered () && _hid_control.discovered () );
108
- VERIFY ( keyboardPresent () || mousePresent () );
134
+ Serial.print (" _gpd_report.discovered(): " );
135
+ Serial.println (_gpd_report.discovered ());
136
+
137
+
138
+ VERIFY ( /* _protcol_mode.discovered() &&*/ _hid_info.discovered () && _hid_control.discovered () );
139
+ // VERIFY ( keyboardPresent() || mousePresent() || gamepadPresent() );
109
140
110
141
_conn_hdl = conn_handle;
111
142
return true ;
@@ -195,3 +226,34 @@ void BLEClientHidAdafruit::getMouseReport(hid_mouse_report_t* report)
195
226
memcpy (report, &_last_mse_report, sizeof (hid_mouse_report_t ));
196
227
}
197
228
229
+ /* ------------------------------------------------------------------*/
230
+ /* Gamepad
231
+ *------------------------------------------------------------------*/
232
+ bool BLEClientHidAdafruit::gamepadPresent (void )
233
+ {
234
+ return _gpd_report.discovered ();
235
+ }
236
+
237
+ bool BLEClientHidAdafruit::enableGamepad (void )
238
+ {
239
+ return _gpd_report.enableNotify ();
240
+ }
241
+
242
+ bool BLEClientHidAdafruit::disableGamepad (void )
243
+ {
244
+ return _gpd_report.disableNotify ();
245
+ }
246
+
247
+ void BLEClientHidAdafruit::_handle_gpd_input (uint8_t * data, uint16_t len)
248
+ {
249
+ varclr (&_last_gpd_report);
250
+ memcpy (&_last_gpd_report, data, len);
251
+
252
+ if ( _gpd_cb ) _gpd_cb (&_last_gpd_report);
253
+ }
254
+
255
+ void BLEClientHidAdafruit::getGamepadReport (hid_gamepad_report_t * report)
256
+ {
257
+ memcpy (report, &_last_gpd_report, sizeof (hid_gamepad_report_t ));
258
+ }
259
+
0 commit comments