Add Keyboard LED callback for USB and BT (not BLE) (#1265)
BLE seems to require some kind of characteristic callback that is not yeet implemented here. USB and BT tested and examples updated.
This commit was merged in pull request #1265.
This commit is contained in:
@@ -36,6 +36,15 @@ KeyboardBT_::KeyboardBT_(void) {
|
||||
|
||||
static const uint8_t desc_keyboard[] = {TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID))};
|
||||
|
||||
static void _hidReportCB(uint16_t cid, hid_report_type_t report_type, uint16_t report_id, int report_size, uint8_t *report) {
|
||||
(void) cid;
|
||||
(void) report_id;
|
||||
if ((report_type == HID_REPORT_TYPE_OUTPUT) && (report_size > 0) && (KeyboardBT._ledCB)) {
|
||||
uint8_t const kbd_leds = report[0];
|
||||
KeyboardBT._ledCB(kbd_leds & KEYBOARD_LED_NUMLOCK, kbd_leds & KEYBOARD_LED_CAPSLOCK, kbd_leds & KEYBOARD_LED_SCROLLLOCK, kbd_leds & KEYBOARD_LED_COMPOSE, kbd_leds & KEYBOARD_LED_KANA, KeyboardBT._ledCBdata);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardBT_::begin(const char *localName, const char *hidName, const uint8_t *layout) {
|
||||
if (!localName) {
|
||||
localName = "PicoW BT Keyboard";
|
||||
@@ -44,6 +53,9 @@ void KeyboardBT_::begin(const char *localName, const char *hidName, const uint8_
|
||||
hidName = localName;
|
||||
}
|
||||
_asciimap = layout;
|
||||
// Required because the hid_report_type_t overlap in BTStack and TUSB
|
||||
auto *fcn = (void (*)(short unsigned int, hid_report_type_t_bt, short unsigned int, int, unsigned char*))_hidReportCB;
|
||||
hid_device_register_report_data_callback(fcn);
|
||||
PicoBluetoothHID.startHID(localName, hidName, 0x2540, 33, desc_keyboard, sizeof(desc_keyboard));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user