@@ -41,12 +41,15 @@ BLEClientHidAdafruit::BLEClientHidAdafruit(void)
4141 _protcol_mode(UUID16_CHR_PROTOCOL_MODE),
4242 _hid_info(UUID16_CHR_HID_INFORMATION), _hid_control(UUID16_CHR_HID_CONTROL_POINT),
4343 _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)
4546{
4647 _kbd_cb = NULL ;
4748 _mse_cb = NULL ;
49+ _gpd_cb = NULL ;
4850 varclr (&_last_kbd_report);
4951 varclr (&_last_mse_report);
52+ varclr (&_last_gpd_report);
5053}
5154
5255
@@ -62,6 +65,12 @@ void mse_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t
6265 svc._handle_mse_input (data, len);
6366}
6467
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+
6574
6675bool BLEClientHidAdafruit::begin (void )
6776{
@@ -77,10 +86,13 @@ bool BLEClientHidAdafruit::begin(void)
7786
7887 _mse_boot_input.begin (this );
7988
89+ _gpd_report.begin (this );
90+
8091
8192 // set notify callback
8293 _kbd_boot_input.setNotifyCallback (kbd_client_notify_cb);
8394 _mse_boot_input.setNotifyCallback (mse_client_notify_cb);
95+ _gpd_report.setNotifyCallback (gpd_client_notify_cb);
8496
8597 return true ;
8698}
@@ -95,17 +107,36 @@ void BLEClientHidAdafruit::setMouseReportCallback(mse_callback_t fp)
95107 _mse_cb = fp;
96108}
97109
110+ void BLEClientHidAdafruit::setGamepadReportCallback (gpd_callback_t fp)
111+ {
112+ _gpd_cb = fp;
113+ }
114+
115+
98116bool BLEClientHidAdafruit::discover (uint16_t conn_handle)
99117{
100118 // Call Base class discover
101119 VERIFY ( BLEClientService::discover (conn_handle) );
102120 _conn_hdl = BLE_CONN_HANDLE_INVALID; // make as invalid until we found all chars
103121
104122 // 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 ());
106133
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() );
109140
110141 _conn_hdl = conn_handle;
111142 return true ;
@@ -195,3 +226,34 @@ void BLEClientHidAdafruit::getMouseReport(hid_mouse_report_t* report)
195226 memcpy (report, &_last_mse_report, sizeof (hid_mouse_report_t ));
196227}
197228
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