diff options
| author | Ha Thach <[email protected]> | 2021-02-01 15:17:00 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-01 15:17:00 +0700 |
| commit | f4e2f88e89fcebdb5b73041027fa274da2743286 (patch) | |
| tree | 40b1dbdcb811ec898171818b2214b5d434e14128 /examples/device/hid_composite/src/main.c | |
| parent | 26caddae239a9b2657121a8da81337cf14d85bc0 (diff) | |
| parent | 3d95835f2238f581669a1ff129a20ce8237649e1 (diff) | |
Merge pull request #622 from hathach/add-consume-control-to-hid-composite-example
add consumer control to hid_composite examples
Diffstat (limited to 'examples/device/hid_composite/src/main.c')
| -rw-r--r-- | examples/device/hid_composite/src/main.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c index 7207e4d4c..6a9b6445d 100644 --- a/examples/device/hid_composite/src/main.c +++ b/examples/device/hid_composite/src/main.c @@ -133,7 +133,7 @@ void hid_task(void) // no button, right + down, no scroll pan tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0); - // delay a bit before attempt to send keyboard report + // delay a bit before sending keyboard report board_delay(10); } } @@ -158,9 +158,33 @@ void hid_task(void) if (has_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL); has_key = false; } + + // delay a bit before sending consumer report + board_delay(10); } -} + /*------------- Consume Control -------------*/ + if ( tud_hid_ready() ) + { + // use to avoid send multiple consecutive zero report + static bool has_consumer_key = false; + + if ( btn ) + { + // volume down + uint16_t volume_down = HID_USAGE_CONSUMER_VOLUME_DECREMENT; + tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &volume_down, 2); + + has_consumer_key = true; + }else + { + // send empty key report (release key) if previously has key pressed + uint16_t empty_key = 0; + if (has_consumer_key) tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2); + has_consumer_key = false; + } + } +} // Invoked when received GET_REPORT control request // Application must fill buffer report's content and return its length. |
