enhance hid service
This commit is contained in:
1 parent
e1c78409c2
commit
7cead72726
3 files changed
+19
-11
No files matched your search
@@ -205,7 +205,8 @@ err_t BLEHidAdafruit::begin(void)
|
||||
uint16_t output_len[] = { 1 };
|
||||
|
||||
setReportLen(input_len, output_len, NULL);
|
||||
enableBootProtocol(true, true);
|
||||
enableKeyboard(true);
|
||||
enableMouse(true);
|
||||
setReportMap(hid_report_descriptor, sizeof(hid_report_descriptor));
|
||||
|
||||
VERIFY_STATUS( BLEHidGeneric::begin() );
|
||||
|
||||
@@ -45,7 +45,7 @@ enum {
|
||||
BLEHidGeneric::BLEHidGeneric(uint8_t num_input, uint8_t num_output, uint8_t num_feature)
|
||||
: BLEService(UUID16_SVC_HUMAN_INTERFACE_DEVICE), _chr_control(UUID16_CHR_HID_CONTROL_POINT)
|
||||
{
|
||||
_boot_keyboard = _boot_mouse = false;
|
||||
_has_keyboard = _has_mouse = false;
|
||||
_report_map = NULL;
|
||||
_report_map_len = 0;
|
||||
|
||||
@@ -88,12 +88,17 @@ BLEHidGeneric::BLEHidGeneric(uint8_t num_input, uint8_t num_output, uint8_t num_
|
||||
}
|
||||
}
|
||||
|
||||
void BLEHidGeneric::enableBootProtocol(bool bootKeyboard, bool bootMouse)
|
||||
void BLEHidGeneric::enableKeyboard(bool enable)
|
||||
{
|
||||
_boot_keyboard = bootKeyboard;
|
||||
_boot_mouse = bootMouse;
|
||||
_has_keyboard = enable;
|
||||
}
|
||||
|
||||
void BLEHidGeneric::enableMouse(bool enable)
|
||||
{
|
||||
_has_mouse = enable;
|
||||
}
|
||||
|
||||
|
||||
void BLEHidGeneric::setHidInfo(uint16_t bcd, uint8_t country, uint8_t flags)
|
||||
{
|
||||
memcpy(_hid_info, &bcd, 2);
|
||||
@@ -137,7 +142,7 @@ err_t BLEHidGeneric::begin(void)
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
// Protocol Mode
|
||||
if ( _boot_keyboard || _boot_mouse )
|
||||
if ( _has_keyboard || _has_mouse )
|
||||
{
|
||||
_chr_protocol = new BLECharacteristic(UUID16_CHR_PROTOCOL_MODE);
|
||||
VERIFY(_chr_protocol, NRF_ERROR_NO_MEM);
|
||||
@@ -192,7 +197,7 @@ err_t BLEHidGeneric::begin(void)
|
||||
report_map.write(_report_map, _report_map_len);
|
||||
|
||||
// Boot Keyboard Input & Output Report
|
||||
if ( _boot_keyboard )
|
||||
if ( _has_keyboard )
|
||||
{
|
||||
_chr_boot_keyboard_input = new BLECharacteristic(UUID16_CHR_BOOT_KEYBOARD_INPUT_REPORT);
|
||||
_chr_boot_keyboard_input->setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
@@ -209,7 +214,7 @@ err_t BLEHidGeneric::begin(void)
|
||||
}
|
||||
|
||||
// Boot Mouse Input Report
|
||||
if ( _boot_mouse )
|
||||
if ( _has_mouse )
|
||||
{
|
||||
_chr_boot_mouse_input = new BLECharacteristic(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT);
|
||||
_chr_boot_mouse_input->setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
|
||||
@@ -91,7 +91,9 @@ class BLEHidGeneric : public BLEService
|
||||
|
||||
BLEHidGeneric(uint8_t num_input, uint8_t num_output = 0, uint8_t num_feature = 0);
|
||||
|
||||
void enableBootProtocol(bool bootKeyboard, bool bootMouse);
|
||||
void enableKeyboard(bool enable);
|
||||
void enableMouse(bool enable);
|
||||
|
||||
void setHidInfo(uint16_t bcd, uint8_t country, uint8_t flags);
|
||||
|
||||
void setReportLen(uint16_t input_len[], uint16_t output_len[] = NULL, uint16_t feature_len[] = NULL);
|
||||
@@ -108,8 +110,8 @@ class BLEHidGeneric : public BLEService
|
||||
uint8_t _num_output;
|
||||
uint8_t _num_feature;
|
||||
|
||||
bool _boot_keyboard;
|
||||
bool _boot_mouse;
|
||||
bool _has_keyboard;
|
||||
bool _has_mouse;
|
||||
|
||||
uint8_t _hid_info[4];
|
||||
const uint8_t* _report_map;
|
||||
|
||||
Reference in new issue
Block a user