diff options
| author | hathach <[email protected]> | 2021-02-08 19:08:16 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-02-08 19:08:16 +0700 |
| commit | 72bcc0685c142c512f1d04ff18eaa13b99f62e93 (patch) | |
| tree | b36872f041eaf75cda5dc4723745f01938fc729b /examples/device/hid_composite/src/main.c | |
| parent | b2019e4d719a8b4560714081e5764525308b2924 (diff) | |
add tud_hid_n_gamepad_report() helper for gamepad report
- Add gamepad to hid_composite example. Though it needs a bit of extra
work but it will come later as separated PR.
Diffstat (limited to 'examples/device/hid_composite/src/main.c')
| -rw-r--r-- | examples/device/hid_composite/src/main.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c index 6a9b6445d..45b8ba674 100644 --- a/examples/device/hid_composite/src/main.c +++ b/examples/device/hid_composite/src/main.c @@ -183,6 +183,35 @@ void hid_task(void) if (has_consumer_key) tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2); has_consumer_key = false; } + + // delay a bit before sending next report + board_delay(10); + } + + /*------------- Gamepad -------------*/ + if ( tud_hid_ready() ) + { + // use to avoid send multiple consecutive zero report for keyboard + static bool has_gamepad_key = false; + + hid_gamepad_report_t report = + { + .x = 0, .y = 0, .z = 0, .rz = 0, .rx = 0, .ry = 0, + .hat = 0, .buttons = 0 + }; + + if ( btn ) + { + report.hat = GAMEPAD_HAT_UP; + tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report)); + + has_gamepad_key = true; + }else + { + report.hat = GAMEPAD_HAT_CENTERED; + if (has_gamepad_key) tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report)); + has_gamepad_key = false; + } } } |
