diff options
| author | hathach <[email protected]> | 2021-07-01 22:46:39 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-07-01 22:46:39 +0700 |
| commit | ca98996e1f9ac802c60d9da4c28ab0e16ca640d6 (patch) | |
| tree | e231ef0be071290e5cb8819f7d67b17811e5236a /examples/device/hid_composite/src | |
| parent | 3b539fdd8d8e9d48756cf5f6e0d605af3972651c (diff) | |
better support for hid device set/get protocol
add caplock detection for hid_composite
Diffstat (limited to 'examples/device/hid_composite/src')
| -rw-r--r-- | examples/device/hid_composite/src/main.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c index 512f6f9d9..6ddad5aae 100644 --- a/examples/device/hid_composite/src/main.c +++ b/examples/device/hid_composite/src/main.c @@ -255,12 +255,30 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t // received data on OUT endpoint ( Report ID = 0, Type = 0 ) void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { - // TODO set LED based on CAPLOCK, NUMLOCK etc... (void) itf; - (void) report_id; - (void) report_type; - (void) buffer; - (void) bufsize; + + if (report_type == HID_REPORT_TYPE_OUTPUT) + { + // Set keyboard LED e.g Capslock, Numlock etc... + if (report_id == REPORT_ID_KEYBOARD) + { + // bufsize should be (at least) 1 + if ( bufsize < 1 ) return; + + uint8_t const kbd_leds = buffer[0]; + + if (kbd_leds & KEYBOARD_LED_CAPSLOCK) + { + // Capslock On: disable blink, turn led on + blink_interval_ms = 0; + board_led_write(true); + }else + { + // Caplocks Off: back to normal link + blink_interval_ms = BLINK_MOUNTED; + } + } + } } //--------------------------------------------------------------------+ @@ -271,6 +289,9 @@ void led_blinking_task(void) static uint32_t start_ms = 0; static bool led_state = false; + // blink is disabled + if (!blink_interval_ms) return; + // Blink every interval ms if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time start_ms += blink_interval_ms; |
