Add gamepad functionality to BLEClientHidAdafruit
Has a couple issues that still need to be resolved in BLEClientHidAdafruit.cpp line 123 and line 138/139
This commit is contained in:
1 parent
10ed826056
commit
b3b3fe1ebc
2 files changed
+81
-4
No files matched your search
@@ -41,12 +41,15 @@ BLEClientHidAdafruit::BLEClientHidAdafruit(void)
|
||||
_protcol_mode(UUID16_CHR_PROTOCOL_MODE),
|
||||
_hid_info(UUID16_CHR_HID_INFORMATION), _hid_control(UUID16_CHR_HID_CONTROL_POINT),
|
||||
_kbd_boot_input(UUID16_CHR_BOOT_KEYBOARD_INPUT_REPORT), _kbd_boot_output(UUID16_CHR_BOOT_KEYBOARD_OUTPUT_REPORT),
|
||||
_mse_boot_input(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT)
|
||||
_mse_boot_input(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT),
|
||||
_gpd_report(UUID16_CHR_REPORT)
|
||||
{
|
||||
_kbd_cb = NULL;
|
||||
_mse_cb = NULL;
|
||||
_gpd_cb = NULL;
|
||||
varclr(&_last_kbd_report);
|
||||
varclr(&_last_mse_report);
|
||||
varclr(&_last_gpd_report);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +65,12 @@ void mse_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t
|
||||
svc._handle_mse_input(data, len);
|
||||
}
|
||||
|
||||
void gpd_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len)
|
||||
{
|
||||
BLEClientHidAdafruit& svc = (BLEClientHidAdafruit&) chr->parentService();
|
||||
svc._handle_gpd_input(data, len);
|
||||
}
|
||||
|
||||
|
||||
bool BLEClientHidAdafruit::begin(void)
|
||||
{
|
||||
@@ -77,10 +86,13 @@ bool BLEClientHidAdafruit::begin(void)
|
||||
|
||||
_mse_boot_input.begin(this);
|
||||
|
||||
_gpd_report.begin(this);
|
||||
|
||||
|
||||
// set notify callback
|
||||
_kbd_boot_input.setNotifyCallback(kbd_client_notify_cb);
|
||||
_mse_boot_input.setNotifyCallback(mse_client_notify_cb);
|
||||
_gpd_report.setNotifyCallback(gpd_client_notify_cb);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -95,6 +107,12 @@ void BLEClientHidAdafruit::setMouseReportCallback(mse_callback_t fp)
|
||||
_mse_cb = fp;
|
||||
}
|
||||
|
||||
void BLEClientHidAdafruit::setGamepadReportCallback(gpd_callback_t fp)
|
||||
{
|
||||
_gpd_cb = fp;
|
||||
}
|
||||
|
||||
|
||||
bool BLEClientHidAdafruit::discover(uint16_t conn_handle)
|
||||
{
|
||||
// Call Base class discover
|
||||
@@ -102,10 +120,23 @@ bool BLEClientHidAdafruit::discover(uint16_t conn_handle)
|
||||
_conn_hdl = BLE_CONN_HANDLE_INVALID; // make as invalid until we found all chars
|
||||
|
||||
// Discover all characteristics
|
||||
Bluefruit.Discovery.discoverCharacteristic(conn_handle, _protcol_mode, _kbd_boot_input, _kbd_boot_output, _mse_boot_input, _hid_info, _hid_control);
|
||||
Bluefruit.Discovery.discoverCharacteristic(conn_handle, _protcol_mode, _kbd_boot_input, _kbd_boot_output, _hid_info, _hid_control, _gpd_report);
|
||||
|
||||
VERIFY( _protcol_mode.discovered() && _hid_info.discovered() && _hid_control.discovered() );
|
||||
VERIFY ( keyboardPresent() || mousePresent() );
|
||||
Serial.print("_protcol_mode.discovered(): ");
|
||||
Serial.println(_protcol_mode.discovered());
|
||||
|
||||
Serial.print("_hid_info.discovered(): ");
|
||||
Serial.println(_hid_info.discovered());
|
||||
|
||||
Serial.print("_hid_control.discovered(): ");
|
||||
Serial.println(_hid_control.discovered());
|
||||
|
||||
Serial.print("_gpd_report.discovered(): ");
|
||||
Serial.println(_gpd_report.discovered());
|
||||
|
||||
|
||||
VERIFY( /*_protcol_mode.discovered() &&*/ _hid_info.discovered() && _hid_control.discovered() );
|
||||
// VERIFY ( keyboardPresent() || mousePresent() || gamepadPresent() );
|
||||
|
||||
_conn_hdl = conn_handle;
|
||||
return true;
|
||||
@@ -195,3 +226,34 @@ void BLEClientHidAdafruit::getMouseReport(hid_mouse_report_t* report)
|
||||
memcpy(report, &_last_mse_report, sizeof(hid_mouse_report_t));
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Gamepad
|
||||
*------------------------------------------------------------------*/
|
||||
bool BLEClientHidAdafruit::gamepadPresent(void)
|
||||
{
|
||||
return _gpd_report.discovered();
|
||||
}
|
||||
|
||||
bool BLEClientHidAdafruit::enableGamepad(void)
|
||||
{
|
||||
return _gpd_report.enableNotify();
|
||||
}
|
||||
|
||||
bool BLEClientHidAdafruit::disableGamepad(void)
|
||||
{
|
||||
return _gpd_report.disableNotify();
|
||||
}
|
||||
|
||||
void BLEClientHidAdafruit::_handle_gpd_input(uint8_t* data, uint16_t len)
|
||||
{
|
||||
varclr(&_last_gpd_report);
|
||||
memcpy(&_last_gpd_report, data, len);
|
||||
|
||||
if ( _gpd_cb ) _gpd_cb(&_last_gpd_report);
|
||||
}
|
||||
|
||||
void BLEClientHidAdafruit::getGamepadReport(hid_gamepad_report_t* report)
|
||||
{
|
||||
memcpy(report, &_last_gpd_report, sizeof(hid_gamepad_report_t));
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ class BLEClientHidAdafruit : public BLEClientService
|
||||
// Callback Signatures
|
||||
typedef void (*kbd_callback_t ) (hid_keyboard_report_t* report);
|
||||
typedef void (*mse_callback_t ) (hid_mouse_report_t* report);
|
||||
typedef void (*gpd_callback_t ) (hid_gamepad_report_t* report);
|
||||
|
||||
BLEClientHidAdafruit(void);
|
||||
|
||||
@@ -74,16 +75,26 @@ class BLEClientHidAdafruit : public BLEClientService
|
||||
|
||||
void getMouseReport(hid_mouse_report_t* report);
|
||||
|
||||
// Gamepad API
|
||||
bool gamepadPresent(void);
|
||||
bool enableGamepad(void);
|
||||
bool disableGamepad(void);
|
||||
|
||||
void getGamepadReport(hid_gamepad_report_t* report);
|
||||
|
||||
// Report callback
|
||||
void setKeyboardReportCallback(kbd_callback_t fp);
|
||||
void setMouseReportCallback(mse_callback_t fp);
|
||||
void setGamepadReportCallback(gpd_callback_t fp);
|
||||
|
||||
protected:
|
||||
kbd_callback_t _kbd_cb;
|
||||
mse_callback_t _mse_cb;
|
||||
gpd_callback_t _gpd_cb;
|
||||
|
||||
hid_keyboard_report_t _last_kbd_report;
|
||||
hid_mouse_report_t _last_mse_report;
|
||||
hid_gamepad_report_t _last_gpd_report;
|
||||
|
||||
// Only support Boot protocol for keyboard and Mouse
|
||||
BLEClientCharacteristic _protcol_mode;
|
||||
@@ -95,11 +106,15 @@ class BLEClientHidAdafruit : public BLEClientService
|
||||
|
||||
BLEClientCharacteristic _mse_boot_input;
|
||||
|
||||
BLEClientCharacteristic _gpd_report;
|
||||
|
||||
void _handle_kbd_input(uint8_t* data, uint16_t len);
|
||||
void _handle_mse_input(uint8_t* data, uint16_t len);
|
||||
void _handle_gpd_input(uint8_t* data, uint16_t len);
|
||||
|
||||
friend void kbd_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len);
|
||||
friend void mse_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len);
|
||||
friend void gpd_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user