From 1884c6384f2b37217b2c99efaab5ce274a377826 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 8 Sep 2022 10:31:43 +0200 Subject: [PATCH] example/hid_keyboard_demo: queue keys via ringbuffer --- example/hid_keyboard_demo.c | 144 +++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 61 deletions(-) diff --git a/example/hid_keyboard_demo.c b/example/hid_keyboard_demo.c index ec42fc763..81d2503d0 100644 --- a/example/hid_keyboard_demo.c +++ b/example/hid_keyboard_demo.c @@ -62,6 +62,10 @@ // to enable demo text on POSIX systems // #undef HAVE_BTSTACK_STDIN +// timing of keypresses +#define TYPING_KEYDOWN_MS 20 +#define TYPING_DELAY_MS 20 + // When not set to 0xffff, sniff and sniff subrating are enabled static uint16_t host_max_latency = 1600; static uint16_t host_min_timeout = 3200; @@ -181,10 +185,18 @@ static uint8_t device_id_sdp_service_buffer[100]; static const char hid_device_name[] = "BTstack HID Keyboard"; static btstack_packet_callback_registration_t hci_event_callback_registration; static uint16_t hid_cid; -static bd_addr_t device_addr; static uint8_t hid_boot_device = 0; +// HID Report sending +static uint8_t send_buffer_storage[16]; +static btstack_ring_buffer_t send_buffer; +static btstack_timer_source_t send_timer; +static uint8_t send_modifier; +static uint8_t send_keycode; +static bool send_active; + #ifdef HAVE_BTSTACK_STDIN +static bd_addr_t device_addr; static const char * device_addr_string = "BC:EC:5D:E6:15:03"; #endif @@ -196,39 +208,29 @@ static enum { } app_state = APP_BOOTING; // HID Keyboard lookup -static int lookup_keycode(uint8_t character, const uint8_t * table, int size, uint8_t * keycode){ +static bool lookup_keycode(uint8_t character, const uint8_t * table, int size, uint8_t * keycode){ int i; for (i=0;i