bluekitchen / btstack

Dual-mode Bluetooth stack, with small memory footprint.
http://bluekitchen-gmbh.com
Other
1.74k stars 613 forks source link

hids_device: propagate result of request_can_send_now_event #621

Closed zehnm closed 4 months ago

zehnm commented 4 months ago

While investigating a stuck HID report request in my application, I've noticed that internal error conditions of hids_device_request_can_send_now_event are not propagated back to the caller.

This PR adds a return status code, so the caller can react accordingly and doesn't expect the HIDS_SUBEVENT_CAN_SEND_NOW event to happen.

mringwal commented 4 months ago

Good point. What was the reason that the request to send failed? Was the connection already disconnected? I've applied the patch on the develop branch - 8e7b544

zehnm commented 4 months ago

The main reason it failed was the client state-machine being stuck in W4_CAN_SEND_FROM_BUFFER without an HIDS_SUBEVENT_CAN_SEND_NOW event happening. (I'm using a similar logic as in the hog_keyboard_demo example). Can't say for sure the cause was hids_device_request_can_send_now_event, because I've also found an invalid control flow in my logic, which didn't reset the state to W4_INPUT for an other error condition. But yes, there were lots of central disconnects during my testing.