more central hid code
This commit is contained in:
1 parent
98e69635ee
commit
a092479f60
4 files changed
+49
-15
No files matched your search
@@ -83,6 +83,15 @@ void connect_callback(uint16_t conn_handle)
|
||||
{
|
||||
Serial.println("Found it");
|
||||
|
||||
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.hid_information.xml
|
||||
uint8_t hidInfo[4];
|
||||
hid.getHidInfo(hidInfo);
|
||||
|
||||
Serial.printf("HID version: %d.%d\n", hidInfo[0], hidInfo[1]);
|
||||
Serial.print("Country code: "); Serial.println(hidInfo[2]);
|
||||
Serial.printf("HID Flags : 0x%02X\n", hidInfo[3]);
|
||||
|
||||
|
||||
// Serial.println("Enable TXD's notify");
|
||||
// clientUart.enableTXD();
|
||||
|
||||
|
||||
@@ -79,6 +79,8 @@ class BLEGap
|
||||
void configPrphConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
|
||||
void configCentralConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
|
||||
|
||||
// bool requestPairing (uint16_t conn_handle);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* INTERNAL USAGE ONLY
|
||||
* Although declare as public, it is meant to be invoked by internal
|
||||
@@ -108,6 +110,9 @@ class BLEGap
|
||||
|
||||
SemaphoreHandle_t indicate_confirm_sem;
|
||||
bool hvc_received;
|
||||
|
||||
// not really peer data
|
||||
// ble_gap_sec_params_t sec_param;
|
||||
} gap_peer_t;
|
||||
|
||||
gap_peer_t _peers[BLE_MAX_CONN];
|
||||
|
||||
@@ -36,16 +36,6 @@
|
||||
|
||||
#include "bluefruit.h"
|
||||
|
||||
void kbd_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void mouse_client_notify_cb(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BLEClientHidAdafruit::BLEClientHidAdafruit(void)
|
||||
: BLEClientService(UUID16_SVC_HUMAN_INTERFACE_DEVICE),
|
||||
_protcol_mode(UUID16_CHR_PROTOCOL_MODE),
|
||||
@@ -53,7 +43,6 @@ BLEClientHidAdafruit::BLEClientHidAdafruit(void)
|
||||
_mouse_boot_input(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT),
|
||||
_hid_info(UUID16_CHR_HID_INFORMATION), _hid_control(UUID16_CHR_HID_CONTROL_POINT)
|
||||
{
|
||||
_country = 0;
|
||||
}
|
||||
|
||||
bool BLEClientHidAdafruit::begin(void)
|
||||
@@ -61,15 +50,19 @@ bool BLEClientHidAdafruit::begin(void)
|
||||
// Invoke base class begin()
|
||||
BLEClientService::begin();
|
||||
|
||||
_protcol_mode.begin(this);
|
||||
_hid_info.begin(this);
|
||||
_hid_control.begin(this);
|
||||
|
||||
_kbd_boot_input.begin(this);
|
||||
_kbd_boot_output.begin(this);
|
||||
|
||||
_mouse_boot_input.begin(this);
|
||||
|
||||
// set notify callback
|
||||
_kbd_boot_input.setNotifyCallback(kbd_client_notify_cb);
|
||||
_mouse_boot_input.setNotifyCallback(mouse_client_notify_cb);
|
||||
|
||||
// set notify callback
|
||||
// _kbd_boot_input.setNotifyCallback(kbd_client_notify_cb);
|
||||
// _mouse_boot_input.setNotifyCallback(mouse_client_notify_cb);
|
||||
}
|
||||
|
||||
bool BLEClientHidAdafruit::discover(uint16_t conn_handle)
|
||||
@@ -88,6 +81,19 @@ bool BLEClientHidAdafruit::discover(uint16_t conn_handle)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLEClientHidAdafruit::getHidInfo(uint8_t info[4])
|
||||
{
|
||||
return 4 == _hid_info.read(info, 4);
|
||||
}
|
||||
|
||||
uint8_t BLEClientHidAdafruit::getCountryCode(void)
|
||||
{
|
||||
uint8_t info[4] = { 0 };
|
||||
getHidInfo(info);
|
||||
|
||||
return info[2];
|
||||
}
|
||||
|
||||
bool BLEClientHidAdafruit::keyboardPresent(void)
|
||||
{
|
||||
return _kbd_boot_input.discovered() && _kbd_boot_output.discovered();
|
||||
|
||||
@@ -46,22 +46,36 @@
|
||||
class BLEClientHidAdafruit : public BLEClientService
|
||||
{
|
||||
public:
|
||||
// Callback Signatures
|
||||
typedef void (*kbd_callback_t ) (uint8_t modifier, uint8_t keycode[6]);
|
||||
typedef void (*mouse_callback_t ) (uint8_t buttons, int8_t x, int8_t y, int8_t wheel, int8_t pan);
|
||||
|
||||
BLEClientHidAdafruit(void);
|
||||
|
||||
virtual bool begin(void);
|
||||
virtual bool discover(uint16_t conn_handle);
|
||||
|
||||
bool getHidInfo(uint8_t info[4]);
|
||||
uint8_t getCountryCode(void);
|
||||
|
||||
// Check if peripheral support keyboard/mouse
|
||||
bool keyboardPresent(void);
|
||||
bool mousePresent(void);
|
||||
|
||||
// Enable/Disable report notification for keyboard/mouse
|
||||
bool enableKeyboard(void);
|
||||
bool disableKeyboard(void);
|
||||
|
||||
bool enableMouse(void);
|
||||
bool disableMouse(void);
|
||||
|
||||
// Report callback
|
||||
void setKeyboardReportCallback(kbd_callback_t fp);
|
||||
void setMouseReportCallback(mouse_callback_t fp);
|
||||
|
||||
private:
|
||||
uint8_t _country;
|
||||
kbd_callback_t _kbd_cb;
|
||||
mouse_callback_t _mouse_cb;
|
||||
|
||||
// Only support Boot protocol for keyboard and Mouse
|
||||
BLEClientCharacteristic _protcol_mode;
|
||||
|
||||
Reference in new issue
Block a user