Skip to content

Commit 136126d

Browse files
committed
pbio/drv/bluetooth: Always set background function error state.
Some functions have an early exit because no changes are needed. In these cases, we'll want to set their error state to success so that asserting their error does not raise if an error was set and raised previously.
1 parent 040e398 commit 136126d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/pbio/drv/bluetooth/bluetooth.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ pbio_error_t pbdrv_bluetooth_peripheral_disconnect(void) {
225225

226226
// Pass silently for already disconnected.
227227
if (!pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_PERIPHERAL)) {
228+
peri->err = PBIO_SUCCESS;
228229
return PBIO_SUCCESS;
229230
}
230231

@@ -345,6 +346,7 @@ pbio_error_t pbdrv_bluetooth_start_advertising(bool start) {
345346
// Already in requested state. This makes it safe to call stop advertising
346347
// even if it already stopped on becoming connected;
347348
if (start == is_advertising) {
349+
advertising_or_scan_err = PBIO_SUCCESS;
348350
return PBIO_SUCCESS;
349351
}
350352

@@ -389,6 +391,7 @@ pbio_error_t pbdrv_bluetooth_start_broadcasting(const uint8_t *data, size_t size
389391

390392
if (!is_broadcasting) {
391393
// Already stopped.
394+
advertising_or_scan_err = PBIO_SUCCESS;
392395
return PBIO_SUCCESS;
393396
}
394397
advertising_or_scan_err = PBIO_ERROR_AGAIN;
@@ -400,6 +403,7 @@ pbio_error_t pbdrv_bluetooth_start_broadcasting(const uint8_t *data, size_t size
400403
// Avoid I/O operations if the user tries to broadcast the same data
401404
// over and over in a tight loop.
402405
if (is_broadcasting && pbdrv_bluetooth_broadcast_data_size == size && !memcmp(pbdrv_bluetooth_broadcast_data, data, size)) {
406+
advertising_or_scan_err = PBIO_SUCCESS;
403407
return PBIO_SUCCESS;
404408
}
405409
pbdrv_bluetooth_broadcast_data_size = size;
@@ -431,6 +435,7 @@ pbio_error_t pbdrv_bluetooth_start_observing(pbdrv_bluetooth_start_observing_cal
431435
bool should_observe = callback ? true : false;
432436

433437
if (should_observe == pbdrv_bluetooth_is_observing) {
438+
advertising_or_scan_err = PBIO_SUCCESS;
434439
return PBIO_SUCCESS;
435440
}
436441

0 commit comments

Comments
 (0)