add conn_hdl to all BLEHidAdafruit API
This commit is contained in:
1 parent
9b0bf8b817
commit
a3a2f87075
2 files changed
+149
-40
No files matched your search
@@ -219,9 +219,8 @@ err_t BLEHidAdafruit::begin(void)
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Keyboard
|
||||
/* Keyboard Multiple Connections
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
void BLEHidAdafruit::blehid_ada_keyboard_output_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len)
|
||||
{
|
||||
LOG_LV2("HID", "Keyboard LED : 0x%02X", data[0]);
|
||||
@@ -241,18 +240,18 @@ void BLEHidAdafruit::setKeyboardLedCallback(kbd_led_cb_t fp)
|
||||
_chr_boot_keyboard_output->setWriteCallback(fp ? blehid_ada_keyboard_output_cb : NULL);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keyboardReport(hid_keyboard_report_t* report)
|
||||
bool BLEHidAdafruit::keyboardReport(uint16_t conn_hdl, hid_keyboard_report_t* report)
|
||||
{
|
||||
if ( isBootMode() )
|
||||
{
|
||||
return bootKeyboardReport(report, sizeof(hid_keyboard_report_t));
|
||||
return bootKeyboardReport(conn_hdl, report, sizeof(hid_keyboard_report_t));
|
||||
}else
|
||||
{
|
||||
return inputReport( REPORT_ID_KEYBOARD, report, sizeof(hid_keyboard_report_t));
|
||||
return inputReport(conn_hdl, REPORT_ID_KEYBOARD, report, sizeof(hid_keyboard_report_t));
|
||||
}
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keyboardReport(uint8_t modifier, uint8_t keycode[6])
|
||||
bool BLEHidAdafruit::keyboardReport(uint16_t conn_hdl, uint8_t modifier, uint8_t keycode[6])
|
||||
{
|
||||
hid_keyboard_report_t report =
|
||||
{
|
||||
@@ -260,10 +259,10 @@ bool BLEHidAdafruit::keyboardReport(uint8_t modifier, uint8_t keycode[6])
|
||||
};
|
||||
memcpy(report.keycode, keycode, 6);
|
||||
|
||||
return keyboardReport(&report);
|
||||
return keyboardReport(conn_hdl, &report);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keyPress(char ch)
|
||||
bool BLEHidAdafruit::keyPress(uint16_t conn_hdl, char ch)
|
||||
{
|
||||
hid_keyboard_report_t report;
|
||||
varclr(&report);
|
||||
@@ -271,18 +270,18 @@ bool BLEHidAdafruit::keyPress(char ch)
|
||||
report.modifier = ( HID_ASCII_TO_KEYCODE[(uint8_t)ch].shift ) ? KEYBOARD_MODIFIER_LEFTSHIFT : 0;
|
||||
report.keycode[0] = HID_ASCII_TO_KEYCODE[(uint8_t)ch].keycode;
|
||||
|
||||
return keyboardReport(&report);
|
||||
return keyboardReport(conn_hdl, &report);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keyRelease(void)
|
||||
bool BLEHidAdafruit::keyRelease(uint16_t conn_hdl)
|
||||
{
|
||||
hid_keyboard_report_t report;
|
||||
varclr(&report);
|
||||
|
||||
return keyboardReport(&report);
|
||||
return keyboardReport(conn_hdl, &report);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keySequence(const char* str, int interal)
|
||||
bool BLEHidAdafruit::keySequence(uint16_t conn_hdl, const char* str, int interval)
|
||||
{
|
||||
// Send each key in sequence
|
||||
char ch;
|
||||
@@ -290,15 +289,15 @@ bool BLEHidAdafruit::keySequence(const char* str, int interal)
|
||||
{
|
||||
char lookahead = *str;
|
||||
|
||||
keyPress(ch);
|
||||
delay(interal);
|
||||
keyPress(conn_hdl, ch);
|
||||
delay(interval);
|
||||
|
||||
/* Only need to empty report if the next character is NULL or the same with
|
||||
* the current one, else no need to send */
|
||||
if ( lookahead == ch || lookahead == 0 )
|
||||
{
|
||||
keyRelease();
|
||||
delay(interal);
|
||||
keyRelease(conn_hdl);
|
||||
delay(interval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,37 +307,37 @@ bool BLEHidAdafruit::keySequence(const char* str, int interal)
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Consumer Media Key
|
||||
*------------------------------------------------------------------*/
|
||||
bool BLEHidAdafruit::consumerReport(uint16_t usage_code)
|
||||
bool BLEHidAdafruit::consumerReport(uint16_t conn_hdl, uint16_t usage_code)
|
||||
{
|
||||
return inputReport( REPORT_ID_CONSUMER_CONTROL, &usage_code, sizeof(usage_code));
|
||||
return inputReport(conn_hdl, REPORT_ID_CONSUMER_CONTROL, &usage_code, sizeof(usage_code));
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::consumerKeyPress(uint16_t usage_code)
|
||||
bool BLEHidAdafruit::consumerKeyPress(uint16_t conn_hdl, uint16_t usage_code)
|
||||
{
|
||||
return consumerReport(usage_code);
|
||||
return consumerReport(conn_hdl, usage_code);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::consumerKeyRelease(void)
|
||||
bool BLEHidAdafruit::consumerKeyRelease(uint16_t conn_hdl)
|
||||
{
|
||||
uint16_t usage = 0;
|
||||
return consumerReport(usage);
|
||||
return consumerReport(conn_hdl, usage);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Mouse
|
||||
*------------------------------------------------------------------*/
|
||||
bool BLEHidAdafruit::mouseReport(hid_mouse_report_t* report)
|
||||
bool BLEHidAdafruit::mouseReport(uint16_t conn_hdl, hid_mouse_report_t* report)
|
||||
{
|
||||
if ( isBootMode() )
|
||||
{
|
||||
return bootMouseReport(report, sizeof(hid_mouse_report_t));
|
||||
return bootMouseReport(conn_hdl, report, sizeof(hid_mouse_report_t));
|
||||
}else
|
||||
{
|
||||
return inputReport( REPORT_ID_MOUSE, report, sizeof(hid_mouse_report_t));
|
||||
return inputReport(conn_hdl, REPORT_ID_MOUSE, report, sizeof(hid_mouse_report_t));
|
||||
}
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseReport(uint8_t buttons, int8_t x, int8_t y, int8_t wheel, int8_t pan)
|
||||
bool BLEHidAdafruit::mouseReport(uint16_t conn_hdl, uint8_t buttons, int8_t x, int8_t y, int8_t wheel, int8_t pan)
|
||||
{
|
||||
hid_mouse_report_t report =
|
||||
{
|
||||
@@ -351,31 +350,114 @@ bool BLEHidAdafruit::mouseReport(uint8_t buttons, int8_t x, int8_t y, int8_t whe
|
||||
|
||||
_mse_buttons = buttons;
|
||||
|
||||
return mouseReport(&report);
|
||||
return mouseReport(conn_hdl, &report);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseButtonPress(uint16_t conn_hdl, uint8_t buttons)
|
||||
{
|
||||
_mse_buttons = buttons;
|
||||
return mouseReport(conn_hdl, buttons, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseButtonRelease(uint16_t conn_hdl)
|
||||
{
|
||||
return mouseReport(conn_hdl, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseMove(uint16_t conn_hdl, int8_t x, int8_t y)
|
||||
{
|
||||
return mouseReport(conn_hdl, _mse_buttons, x, y, 0, 0);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseScroll(uint16_t conn_hdl, int8_t scroll)
|
||||
{
|
||||
return mouseReport(conn_hdl, _mse_buttons, 0, 0, scroll, 0);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mousePan(uint16_t conn_hdl, int8_t pan)
|
||||
{
|
||||
return mouseReport(conn_hdl, _mse_buttons, 0, 0, 0, pan);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Single Connections
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
//------------- Keyboard -------------//
|
||||
bool BLEHidAdafruit::keyboardReport(hid_keyboard_report_t* report)
|
||||
{
|
||||
return keyboardReport(BLE_GATT_HANDLE_INVALID, report);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keyboardReport(uint8_t modifier, uint8_t keycode[6])
|
||||
{
|
||||
return keyboardReport(BLE_GATT_HANDLE_INVALID, modifier, keycode);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keyPress(char ch)
|
||||
{
|
||||
return keyPress(BLE_GATT_HANDLE_INVALID, ch);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keyRelease(void)
|
||||
{
|
||||
return keyRelease(BLE_GATT_HANDLE_INVALID);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::keySequence(const char* str, int interval)
|
||||
{
|
||||
return keySequence(BLE_GATT_HANDLE_INVALID, str, interval);
|
||||
}
|
||||
|
||||
//------------- Consumer Media Keys -------------//
|
||||
bool BLEHidAdafruit::consumerReport(uint16_t usage_code)
|
||||
{
|
||||
return consumerReport(BLE_GATT_HANDLE_INVALID, usage_code);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::consumerKeyPress(uint16_t usage_code)
|
||||
{
|
||||
return consumerKeyPress(BLE_GATT_HANDLE_INVALID, usage_code);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::consumerKeyRelease(void)
|
||||
{
|
||||
return consumerKeyRelease(BLE_GATT_HANDLE_INVALID);
|
||||
}
|
||||
|
||||
//------------- Mouse -------------//
|
||||
bool BLEHidAdafruit::mouseReport(hid_mouse_report_t* report)
|
||||
{
|
||||
return mouseReport(BLE_GATT_HANDLE_INVALID, report);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseReport(uint8_t buttons, int8_t x, int8_t y, int8_t wheel, int8_t pan)
|
||||
{
|
||||
return mouseReport(BLE_GATT_HANDLE_INVALID, buttons, x, y, wheel, pan);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseButtonPress(uint8_t buttons)
|
||||
{
|
||||
_mse_buttons = buttons;
|
||||
return mouseReport(buttons, 0, 0, 0, 0);
|
||||
return mouseButtonPress(BLE_GATT_HANDLE_INVALID, buttons);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseButtonRelease(void)
|
||||
{
|
||||
return mouseReport(0, 0, 0, 0, 0);
|
||||
return mouseButtonRelease(BLE_GATT_HANDLE_INVALID);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseMove(int8_t x, int8_t y)
|
||||
{
|
||||
return mouseReport(_mse_buttons, x, y, 0, 0);
|
||||
return mouseMove(BLE_GATT_HANDLE_INVALID, x, y);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mouseScroll(int8_t scroll)
|
||||
{
|
||||
return mouseReport(_mse_buttons, 0, 0, scroll, 0);
|
||||
return mouseScroll(BLE_GATT_HANDLE_INVALID, scroll);
|
||||
}
|
||||
|
||||
bool BLEHidAdafruit::mousePan(int8_t pan)
|
||||
{
|
||||
return mouseReport(_mse_buttons, 0, 0, 0, pan);
|
||||
return mousePan(BLE_GATT_HANDLE_INVALID, pan);
|
||||
}
|
||||
|
||||
@@ -46,29 +46,45 @@
|
||||
class BLEHidAdafruit : public BLEHidGeneric
|
||||
{
|
||||
public:
|
||||
/*--------- Callback Signatures ----------*/
|
||||
// Callback Signatures
|
||||
typedef void (*kbd_led_cb_t) (uint16_t conn_hdl, uint8_t leds_bitmap);
|
||||
|
||||
BLEHidAdafruit(void);
|
||||
|
||||
virtual err_t begin(void);
|
||||
|
||||
// Keyboard
|
||||
//------------- Keyboard -------------//
|
||||
// Single connection
|
||||
void setKeyboardLedCallback(kbd_led_cb_t fp);
|
||||
|
||||
bool keyboardReport(hid_keyboard_report_t* report);
|
||||
bool keyboardReport(uint8_t modifier, uint8_t keycode[6]);
|
||||
|
||||
void setKeyboardLedCallback(kbd_led_cb_t fp);
|
||||
|
||||
bool keyPress(char ch);
|
||||
bool keyRelease(void);
|
||||
bool keySequence(const char* str, int interal=5);
|
||||
bool keySequence(const char* str, int interval=5);
|
||||
|
||||
// Consumer Media Keys
|
||||
// Multiple connections
|
||||
bool keyboardReport(uint16_t conn_hdl, hid_keyboard_report_t* report);
|
||||
bool keyboardReport(uint16_t conn_hdl, uint8_t modifier, uint8_t keycode[6]);
|
||||
|
||||
bool keyPress(uint16_t conn_hdl, char ch);
|
||||
bool keyRelease(uint16_t conn_hdl);
|
||||
bool keySequence(uint16_t conn_hdl, const char* str, int interval=5);
|
||||
|
||||
//------------- Consumer Media Keys -------------//
|
||||
// Single connection
|
||||
bool consumerReport(uint16_t usage_code);
|
||||
bool consumerKeyPress(uint16_t usage_code);
|
||||
bool consumerKeyRelease(void);
|
||||
|
||||
// Mouse
|
||||
// Multiple connections
|
||||
bool consumerReport(uint16_t conn_hdl, uint16_t usage_code);
|
||||
bool consumerKeyPress(uint16_t conn_hdl, uint16_t usage_code);
|
||||
bool consumerKeyRelease(uint16_t conn_hdl);
|
||||
|
||||
//------------- Mouse -------------//
|
||||
// Single connection
|
||||
bool mouseReport(hid_mouse_report_t* report);
|
||||
bool mouseReport(uint8_t buttons, int8_t x, int8_t y, int8_t wheel=0, int8_t pan=0);
|
||||
|
||||
@@ -79,6 +95,17 @@ class BLEHidAdafruit : public BLEHidGeneric
|
||||
bool mouseScroll(int8_t scroll);
|
||||
bool mousePan(int8_t pan);
|
||||
|
||||
// Multiple connections
|
||||
bool mouseReport(uint16_t conn_hdl, hid_mouse_report_t* report);
|
||||
bool mouseReport(uint16_t conn_hdl, uint8_t buttons, int8_t x, int8_t y, int8_t wheel=0, int8_t pan=0);
|
||||
|
||||
bool mouseButtonPress(uint16_t conn_hdl, uint8_t buttons);
|
||||
bool mouseButtonRelease(uint16_t conn_hdl);
|
||||
|
||||
bool mouseMove(uint16_t conn_hdl, int8_t x, int8_t y);
|
||||
bool mouseScroll(uint16_t conn_hdl, int8_t scroll);
|
||||
bool mousePan(uint16_t conn_hdl, int8_t pan);
|
||||
|
||||
protected:
|
||||
uint8_t _mse_buttons;
|
||||
kbd_led_cb_t _kbd_led_cb;
|
||||
|
||||
Reference in new issue
Block a user