Skip to content

Commit 2cde8bd

Browse files
Avoid deadlock BT/LE HID send when disconnected (#2252)
Fixes #2251 The 2-phase send could get out of whack if transmission was attempted when no device was connected. Clear things up so if things aren't connected, then no data gets set as pending.
1 parent 99b32b8 commit 2cde8bd

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

libraries/HID_Bluetooth/src/PicoBluetoothBLEHID.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@ class PicoBluetoothBLEHID_ {
178178
while (connected() && _needToSend) {
179179
/* noop busy wait */
180180
}
181-
_needToSend = true;
182-
_sendReport = rpt;
183-
_sendReportLen = len;
184181
__lockBluetooth();
185-
hids_device_request_can_send_now_event(_con_handle);
182+
if (connected()) {
183+
_needToSend = true;
184+
_sendReport = rpt;
185+
_sendReportLen = len;
186+
hids_device_request_can_send_now_event(_con_handle);
187+
}
186188
__unlockBluetooth();
187189
while (connected() && _needToSend) {
188190
/* noop busy wait */

libraries/HID_Bluetooth/src/PicoBluetoothHID.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ class PicoBluetoothHID_ {
142142
}
143143

144144
bool send(int id, void *rpt, int len) {
145-
_needToSend = true;
146-
_sendReportID = id;
147-
_sendReport = rpt;
148-
_sendReportLen = len;
149145
__lockBluetooth();
150-
hid_device_request_can_send_now_event(getCID());
146+
if (connected()) {
147+
_needToSend = true;
148+
_sendReportID = id;
149+
_sendReport = rpt;
150+
_sendReportLen = len;
151+
hid_device_request_can_send_now_event(getCID());
152+
}
151153
__unlockBluetooth();
152154
while (connected() && _needToSend) {
153155
/* noop busy wait */

0 commit comments

Comments
 (0)