Skip to content

Commit 7cead72

Browse files
committed
enhance hid service
1 parent e1c7840 commit 7cead72

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

libraries/Bluefruit52Lib/src/services/BLEHidAdafruit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ err_t BLEHidAdafruit::begin(void)
205205
uint16_t output_len[] = { 1 };
206206

207207
setReportLen(input_len, output_len, NULL);
208-
enableBootProtocol(true, true);
208+
enableKeyboard(true);
209+
enableMouse(true);
209210
setReportMap(hid_report_descriptor, sizeof(hid_report_descriptor));
210211

211212
VERIFY_STATUS( BLEHidGeneric::begin() );

libraries/Bluefruit52Lib/src/services/BLEHidGeneric.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum {
4545
BLEHidGeneric::BLEHidGeneric(uint8_t num_input, uint8_t num_output, uint8_t num_feature)
4646
: BLEService(UUID16_SVC_HUMAN_INTERFACE_DEVICE), _chr_control(UUID16_CHR_HID_CONTROL_POINT)
4747
{
48-
_boot_keyboard = _boot_mouse = false;
48+
_has_keyboard = _has_mouse = false;
4949
_report_map = NULL;
5050
_report_map_len = 0;
5151

@@ -88,12 +88,17 @@ BLEHidGeneric::BLEHidGeneric(uint8_t num_input, uint8_t num_output, uint8_t num_
8888
}
8989
}
9090

91-
void BLEHidGeneric::enableBootProtocol(bool bootKeyboard, bool bootMouse)
91+
void BLEHidGeneric::enableKeyboard(bool enable)
9292
{
93-
_boot_keyboard = bootKeyboard;
94-
_boot_mouse = bootMouse;
93+
_has_keyboard = enable;
9594
}
9695

96+
void BLEHidGeneric::enableMouse(bool enable)
97+
{
98+
_has_mouse = enable;
99+
}
100+
101+
97102
void BLEHidGeneric::setHidInfo(uint16_t bcd, uint8_t country, uint8_t flags)
98103
{
99104
memcpy(_hid_info, &bcd, 2);
@@ -137,7 +142,7 @@ err_t BLEHidGeneric::begin(void)
137142
VERIFY_STATUS( BLEService::begin() );
138143

139144
// Protocol Mode
140-
if ( _boot_keyboard || _boot_mouse )
145+
if ( _has_keyboard || _has_mouse )
141146
{
142147
_chr_protocol = new BLECharacteristic(UUID16_CHR_PROTOCOL_MODE);
143148
VERIFY(_chr_protocol, NRF_ERROR_NO_MEM);
@@ -192,7 +197,7 @@ err_t BLEHidGeneric::begin(void)
192197
report_map.write(_report_map, _report_map_len);
193198

194199
// Boot Keyboard Input & Output Report
195-
if ( _boot_keyboard )
200+
if ( _has_keyboard )
196201
{
197202
_chr_boot_keyboard_input = new BLECharacteristic(UUID16_CHR_BOOT_KEYBOARD_INPUT_REPORT);
198203
_chr_boot_keyboard_input->setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
@@ -209,7 +214,7 @@ err_t BLEHidGeneric::begin(void)
209214
}
210215

211216
// Boot Mouse Input Report
212-
if ( _boot_mouse )
217+
if ( _has_mouse )
213218
{
214219
_chr_boot_mouse_input = new BLECharacteristic(UUID16_CHR_BOOT_MOUSE_INPUT_REPORT);
215220
_chr_boot_mouse_input->setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);

libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class BLEHidGeneric : public BLEService
9191

9292
BLEHidGeneric(uint8_t num_input, uint8_t num_output = 0, uint8_t num_feature = 0);
9393

94-
void enableBootProtocol(bool bootKeyboard, bool bootMouse);
94+
void enableKeyboard(bool enable);
95+
void enableMouse(bool enable);
96+
9597
void setHidInfo(uint16_t bcd, uint8_t country, uint8_t flags);
9698

9799
void setReportLen(uint16_t input_len[], uint16_t output_len[] = NULL, uint16_t feature_len[] = NULL);
@@ -108,8 +110,8 @@ class BLEHidGeneric : public BLEService
108110
uint8_t _num_output;
109111
uint8_t _num_feature;
110112

111-
bool _boot_keyboard;
112-
bool _boot_mouse;
113+
bool _has_keyboard;
114+
bool _has_mouse;
113115

114116
uint8_t _hid_info[4];
115117
const uint8_t* _report_map;

0 commit comments

Comments
 (0)