Skip to content

Commit

Permalink
drv/bluetooth_btstack: Avoid broadcast in tight loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Oct 26, 2023
1 parent a50ff18 commit cf73380
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
- Fixed `surface=False` not working in `ColorSensor` ([support#1232]).
- Fixed `PUPDevice.write` not selecting correct mode ([support#1213]).
- Fixed City Hub turning back on after shutdown ([support#1195]).
- Fixed SPIKE hubs not broadcasting at all when attempting to broadcast in a
tight loop ([support#1151]).

[pybricks-micropython#104]: https://github.com/pybricks/pybricks-micropython/pull/104
[support#1054]: https://github.com/pybricks/support/issues/1054
[support#1140]: https://github.com/pybricks/support/issues/1140
[support#1151]: https://github.com/pybricks/support/issues/1151
[support#1189]: https://github.com/pybricks/support/issues/1189
[support#1195]: https://github.com/pybricks/support/issues/1195
[support#1213]: https://github.com/pybricks/support/issues/1213
Expand Down
9 changes: 9 additions & 0 deletions lib/pbio/drv/bluetooth/bluetooth_btstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ 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 @@ -760,6 +762,13 @@ 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));

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

Expand Down

0 comments on commit cf73380

Please sign in to comment.