From f2f0c6ec84441815e84f7455dadf5296e19fb44d Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 1 Aug 2018 18:14:42 +0700 Subject: [PATCH] add set led to hid_keyscan example as well --- .../Peripheral/hid_keyscan/hid_keyscan.ino | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyscan/hid_keyscan.ino b/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyscan/hid_keyscan.ino index c58aa823..be5b2bb4 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyscan/hid_keyscan.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/hid_keyscan/hid_keyscan.ino @@ -73,6 +73,9 @@ void setup() */ blehid.begin(); + // Set callback for set LED from central + blehid.setKeyboardLedCallback(set_keyboard_led); + /* Set connection interval (min, max) to your perferred value. * Note: It is already set by BLEHidAdafruit::begin() to 11.25ms - 15ms * min = 9*1.25=11.25 ms, max = 12*1.25= 15 ms @@ -168,3 +171,23 @@ void loop() // Poll interval delay(10); } + +/** + * Callback invoked when received Set LED from central. + * Must be set previously with setKeyboardLedCallback() + * + * The LED bit map is as follows: (also defined by KEYBOARD_LED_* ) + * Kana (4) | Compose (3) | ScrollLock (2) | CapsLock (1) | Numlock (0) + */ +void set_keyboard_led(uint8_t led_bitmap) +{ + // light up Red Led if any bits is set + if ( led_bitmap ) + { + ledOn( LED_RED ); + } + else + { + ledOff( LED_RED ); + } +}