adding consumer key support
- correct Keyboard with 1 input & 1 output report - hidgeneric report ID starting from 1, (index is from 0)
This commit is contained in:
1 parent
ffae8db151
commit
d86127990a
5 files changed
+37
-26
No files matched your search
@@ -73,6 +73,8 @@ void loop()
|
||||
hasKeyPressed = false;
|
||||
blehid.keyRelease();
|
||||
|
||||
blehid.consumerKeyRelease();
|
||||
|
||||
// delay a bit after a report
|
||||
delay(5);
|
||||
}
|
||||
@@ -87,6 +89,8 @@ void loop()
|
||||
blehid.keyPress(ch);
|
||||
hasKeyPressed = true;
|
||||
|
||||
blehid.consumerKeyPress(HID_USAGE_CONSUMER_MUTE);
|
||||
|
||||
// delay a bit after a report
|
||||
delay(5);
|
||||
}
|
||||
|
||||
@@ -38,33 +38,19 @@
|
||||
|
||||
enum
|
||||
{
|
||||
REPORT_ID_KEYBOARD = 0,
|
||||
REPORT_ID_KEYBOARD = 1,
|
||||
REPORT_ID_CONSUMER_CONTROL,
|
||||
REPORT_ID_MOUSE,
|
||||
REPORT_ID_GAMEPAD
|
||||
};
|
||||
|
||||
// LED Indicator Kana | Compose | Scroll Lock | CapsLock | NumLock
|
||||
// HID_REPORT_ID ( REPORT_ID_KEYBOARD + 2 ),
|
||||
// HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
|
||||
// /* 5-bit Led report */
|
||||
// HID_USAGE_MIN ( 1 ),
|
||||
// HID_USAGE_MAX ( 5 ),
|
||||
// HID_REPORT_COUNT ( 5 ),
|
||||
// HID_REPORT_SIZE ( 1 ),
|
||||
// HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
|
||||
// /* led padding */
|
||||
// HID_REPORT_COUNT ( 1 ),
|
||||
// HID_REPORT_SIZE ( 3 ),
|
||||
// HID_OUTPUT ( HID_CONSTANT ),
|
||||
|
||||
uint8_t const hid_report_descriptor[] =
|
||||
{
|
||||
//------------- Keyboard Report -------------//
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
|
||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
||||
HID_REPORT_ID ( REPORT_ID_KEYBOARD + 0 ),
|
||||
HID_REPORT_ID ( REPORT_ID_KEYBOARD ),
|
||||
HID_USAGE_PAGE( HID_USAGE_PAGE_KEYBOARD ),
|
||||
// 8 bits Modifier Keys (Shfit, Control, Alt)
|
||||
HID_USAGE_MIN ( 224 ),
|
||||
@@ -219,11 +205,10 @@ BLEHidAdafruit::BLEHidAdafruit(void)
|
||||
|
||||
err_t BLEHidAdafruit::start(void)
|
||||
{
|
||||
uint16_t input_len[] = { sizeof(hid_keyboard_report_t), 2 };
|
||||
uint16_t input_len [] = { sizeof(hid_keyboard_report_t), sizeof(hid_consumer_control_report_t) };
|
||||
uint16_t output_len[] = { 1 };
|
||||
|
||||
setReportLen(input_len, output_len, NULL);
|
||||
|
||||
setBootProtocol(true, false);
|
||||
setReportMap(hid_report_descriptor, sizeof(hid_report_descriptor));
|
||||
|
||||
@@ -297,3 +282,19 @@ err_t BLEHidAdafruit::keySequence(const char* str, int interal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err_t BLEHidAdafruit::consumerReport(uint16_t usage_code)
|
||||
{
|
||||
return inputReport( REPORT_ID_CONSUMER_CONTROL, &usage_code, sizeof(usage_code));
|
||||
}
|
||||
|
||||
err_t BLEHidAdafruit::consumerKeyPress(uint16_t usage_code)
|
||||
{
|
||||
return consumerReport(usage_code);
|
||||
}
|
||||
|
||||
err_t BLEHidAdafruit::consumerKeyRelease(void)
|
||||
{
|
||||
uint16_t usage = 0;
|
||||
return consumerReport(usage);
|
||||
}
|
||||
@@ -62,6 +62,11 @@ class BLEHidAdafruit : public BLEHidGeneric
|
||||
err_t keyPress(char ch);
|
||||
err_t keyRelease(void);
|
||||
err_t keySequence(const char* str, int interal=5);
|
||||
|
||||
// Consumer Media Keys
|
||||
err_t consumerReport(uint16_t usage_code);
|
||||
err_t consumerKeyPress(uint16_t usage_code);
|
||||
err_t consumerKeyRelease(void);
|
||||
};
|
||||
|
||||
#endif /* BLEHIDADAFRUIT_H_ */
|
||||
@@ -149,7 +149,7 @@ err_t BLEHidGeneric::start(void)
|
||||
_chr_inputs[i].setUuid(UUID16_CHR_REPORT);
|
||||
_chr_inputs[i].setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
|
||||
_chr_inputs[i].setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS);
|
||||
_chr_inputs[i].setReportRefDescriptor(i+0, REPORT_TYPE_INPUT);
|
||||
_chr_inputs[i].setReportRefDescriptor(i+1, REPORT_TYPE_INPUT);
|
||||
|
||||
// Input report len is configured, else variable len up to 255
|
||||
if ( _input_len ) _chr_inputs[i].setFixedLen( _input_len[i] );
|
||||
@@ -163,7 +163,7 @@ err_t BLEHidGeneric::start(void)
|
||||
_chr_outputs[i].setUuid(UUID16_CHR_REPORT);
|
||||
_chr_outputs[i].setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE | CHR_PROPS_WRITE_WO_RESP);
|
||||
_chr_outputs[i].setPermission(SECMODE_ENC_NO_MITM, SECMODE_NO_ACCESS);
|
||||
_chr_outputs[i].setReportRefDescriptor(i+0, REPORT_TYPE_OUTPUT);
|
||||
_chr_outputs[i].setReportRefDescriptor(i+1, REPORT_TYPE_OUTPUT);
|
||||
// _chr_outputs[i].setWriteCallback(blehidgeneric_output_cb);
|
||||
|
||||
// Input report len is configured, else variable len up to 255
|
||||
@@ -231,7 +231,7 @@ err_t BLEHidGeneric::start(void)
|
||||
|
||||
err_t BLEHidGeneric::inputReport(uint8_t reportID, void const* data, int len)
|
||||
{
|
||||
return _chr_inputs[reportID].notify( (uint8_t const*) data, len);
|
||||
return _chr_inputs[reportID-1].notify( (uint8_t const*) data, len);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
@@ -66,6 +66,12 @@ typedef ATTR_PACKED_STRUCT(struct)
|
||||
uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
|
||||
} hid_keyboard_report_t;
|
||||
|
||||
/// HID Consumer Control Report
|
||||
typedef ATTR_PACKED_STRUCT(struct)
|
||||
{
|
||||
uint16_t usage_value; ///< Usage value of the pressed control
|
||||
} hid_consumer_control_report_t;
|
||||
|
||||
/// Gamepad report
|
||||
typedef ATTR_PACKED_STRUCT(struct)
|
||||
{
|
||||
@@ -149,11 +155,6 @@ typedef enum {
|
||||
//--------------------------------------------------------------------+
|
||||
// Keyboard
|
||||
//--------------------------------------------------------------------+
|
||||
/// HID Consumer Control Report
|
||||
typedef ATTR_PACKED_STRUCT(struct)
|
||||
{
|
||||
uint16_t usage_value; ///< Usage value of the pressed control
|
||||
} hid_consumer_control_report_t;
|
||||
|
||||
///// Keyboard modifier codes bitmap
|
||||
typedef enum {
|
||||
|
||||
Reference in new issue
Block a user