Skip to content

Commit 352bb8f

Browse files
committed
pbio/drv/bluetooth: Fix error propagation to user space.
On completion of an operation, the function was unset, so errors were not being returned to user space.
1 parent 8ca28cd commit 352bb8f

3 files changed

Lines changed: 5 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
off after driving 3 meters, depending on configuration parameters ([support#2500]).
2828
- Fixed Powered Up remote light getting the wrong color ([support#2497]).
2929
- Fix shutdown animation not visible when shutting down due to Bluetooth glitches.
30+
- Fixed Powered Up remote raising the wrong exception on timeout.
3031

3132
[support#1962]: https://github.com/pybricks/support/issues/1962
3233
[support#2468]: https://github.com/pybricks/support/issues/2468

lib/pbio/drv/bluetooth/bluetooth.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ pbio_error_t pbdrv_bluetooth_await_peripheral_command(pbio_os_state_t *state, vo
280280
// of interest and will be cancelled if the active function supports it.
281281
pbio_os_timer_set(&peri->watchdog, 10);
282282

283-
return peri->func ? peri->err : PBIO_SUCCESS;
283+
return peri->err;
284284
}
285285

286286
void pbdrv_bluetooth_cancel_operation_request(void) {
@@ -427,7 +427,7 @@ void pbdrv_bluetooth_restart_observing_request(void) {
427427
}
428428

429429
pbio_error_t pbdrv_bluetooth_await_advertise_or_scan_command(pbio_os_state_t *state, void *context) {
430-
return advertising_or_scan_func ? advertising_or_scan_err : PBIO_SUCCESS;
430+
return advertising_or_scan_err;
431431
}
432432

433433
/**
@@ -617,10 +617,7 @@ void pbdrv_bluetooth_deinit(void) {
617617
// Under normal operation ::pbdrv_bluetooth_close_user_tasks completes
618618
// normally and there should be no user activity at this point. If there
619619
// is, a task got stuck, so exit forcefully.
620-
pbio_os_state_t unused;
621-
if (pbdrv_bluetooth_await_advertise_or_scan_command(&unused, NULL) != PBIO_SUCCESS ||
622-
pbdrv_bluetooth_await_peripheral_command(&unused, NULL) != PBIO_SUCCESS) {
623-
620+
if (advertising_or_scan_err == PBIO_ERROR_AGAIN || peripheral_singleton.err == PBIO_ERROR_AGAIN) {
624621
// Hard reset without waiting on completion of any process.
625622
pbdrv_bluetooth_controller_reset_hard();
626623
return;

pybricks/iodevices/pb_type_iodevices_lwp3device.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,7 @@ static pbio_error_t pb_lwp3device_connect_thread(pbio_os_state_t *state, mp_obj_
279279
PBIO_OS_ASYNC_BEGIN(state);
280280

281281
// Scan and connect with timeout.
282-
err = pbdrv_bluetooth_peripheral_scan_and_connect(&scan_config);
283-
if (err != PBIO_SUCCESS) {
284-
return err;
285-
}
282+
pb_assert(pbdrv_bluetooth_peripheral_scan_and_connect(&scan_config));
286283
PBIO_OS_AWAIT(state, &unused, err = pbdrv_bluetooth_await_peripheral_command(&unused, NULL));
287284
if (err != PBIO_SUCCESS) {
288285
return err;

0 commit comments

Comments
 (0)