Skip to content

Commit

Permalink
drv/bluetooth_btstack: finish TODO to wait for setting advertising data
Browse files Browse the repository at this point in the history
This finishes up the REVISIT comment in start_broadcasting_task() to
actually wait for the set advertising data command to complete before
the task completes.

This fixes issues with calling the task too fast while the commands
from the previous call are still pending.

The timer was used to work around the issue but is no longer needed.

Fixes: pybricks/support#1151
  • Loading branch information
dlech committed Nov 4, 2023
1 parent e025dce commit 90872ab
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/pbio/drv/bluetooth/bluetooth_btstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,6 @@ void pbdrv_bluetooth_disconnect_remote(void) {
static PT_THREAD(start_broadcasting_task(struct pt *pt, pbio_task_t *task)) {
pbdrv_bluetooth_value_t *value = task->context;

static struct timer broadcast_delay;

PT_BEGIN(pt);

if (value->size > LE_ADVERTISING_DATA_SIZE) {
Expand All @@ -761,14 +759,9 @@ static PT_THREAD(start_broadcasting_task(struct pt *pt, pbio_task_t *task)) {
is_broadcasting = true;
}

// Delay to allow for advertising to start. FIXME: This is technically only
// needed if a previous broadcast was started sooner than this. It would be
// better to conditionally await just before the broadcast so we can avoid
// unnecessary delays.
timer_set(&broadcast_delay, 10);
PT_WAIT_UNTIL(pt, timer_expired(&broadcast_delay));
// Wait advertising enable command to complete.
PT_WAIT_UNTIL(pt, event_packet && HCI_EVENT_IS_COMMAND_COMPLETE(event_packet, hci_le_set_advertising_data));

// REVISIT: use callback to actually wait for start?
task->status = PBIO_SUCCESS;

PT_END(pt);
Expand Down

0 comments on commit 90872ab

Please sign in to comment.