Skip to content

Commit b658ce9

Browse files
committed
Only start BLE for workflow when desired
The previous implementation would always start BLE and rely on advertising logic to make the workflow not available when on USB. This change removes the "always enable" call in favor of a default value that is on if 1) we determine we should be discoverable or 2) we're already bonded over BLE.
1 parent ecb399a commit b658ce9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

supervisor/shared/bluetooth/bluetooth.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ void supervisor_bluetooth_init(void) {
212212
boot_in_discovery_mode = true;
213213
reset_state = 0x0;
214214
}
215+
bool bonded = common_hal_bleio_adapter_is_bonded_to_central(&common_hal_bleio_adapter_obj);
215216
#if !CIRCUITPY_USB_DEVICE
216217
// Boot into discovery if USB isn't available and we aren't bonded already.
217218
// Checking here allows us to have the status LED solidly on even if no button was
218219
// pressed.
219-
bool bonded = common_hal_bleio_adapter_is_bonded_to_central(&common_hal_bleio_adapter_obj);
220220
bool wifi_workflow_active = false;
221221
#if CIRCUITPY_WEB_WORKFLOW && CIRCUITPY_WIFI && CIRCUITPY_OS_GETENV
222222
char _api_password[64];
@@ -255,6 +255,11 @@ void supervisor_bluetooth_init(void) {
255255
if (boot_in_discovery_mode) {
256256
common_hal_bleio_adapter_erase_bonding(&common_hal_bleio_adapter_obj);
257257
}
258+
if (boot_in_discovery_mode || bonded) {
259+
workflow_state = WORKFLOW_ENABLED;
260+
} else {
261+
workflow_state = WORKFLOW_DISABLED;
262+
}
258263
#if CIRCUITPY_STATUS_LED
259264
new_status_color(BLACK);
260265
status_led_deinit();
@@ -358,7 +363,7 @@ void supervisor_bluetooth_disable_workflow(void) {
358363

359364
bool supervisor_bluetooth_workflow_is_enabled(void) {
360365
#if CIRCUITPY_BLE_FILE_SERVICE || CIRCUITPY_SERIAL_BLE
361-
if (workflow_state == 1) {
366+
if (workflow_state == WORKFLOW_ENABLED) {
362367
return true;
363368
}
364369
#endif

supervisor/shared/workflow.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ void supervisor_workflow_start(void) {
8383

8484
#if CIRCUITPY_BLEIO
8585
bleio_reset();
86-
supervisor_bluetooth_enable_workflow();
8786
supervisor_start_bluetooth();
8887
#endif
8988

0 commit comments

Comments
 (0)