Skip to content

Commit ea54ebc

Browse files
committed
pbio/sys/hmi: Refactor program start logic.
Currently, the UI is split between sys/hmi and sys/bluetooth. This is the first step towards bringing the UI to one place and eliminating the pbsys/bluetooth layer. This will in turn support the clearer separation of the sys/host and ble/usb layers, which will be needed for proper USB support. This intermediate result works but isn't identical yet to previous behavior. It currently toggles the advertising state but does not fully turn it off or save it persistently.
1 parent 9933ede commit ea54ebc

File tree

5 files changed

+176
-177
lines changed

5 files changed

+176
-177
lines changed

lib/pbio/include/pbdrv/bluetooth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ static inline void pbdrv_bluetooth_queue_noop(pbio_task_t *task) {
417417
static inline void pbdrv_bluetooth_start_advertising(void) {
418418
}
419419

420+
static inline void pbdrv_bluetooth_stop_advertising(void) {
421+
}
422+
420423
static inline bool pbdrv_bluetooth_is_connected(pbdrv_bluetooth_connection_t connection) {
421424
return false;
422425
}

lib/pbio/sys/bluetooth.c

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -311,52 +311,23 @@ PROCESS_THREAD(pbsys_bluetooth_process, ev, data) {
311311
etimer_set(&timer, 150);
312312
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer));
313313

314-
// Wait until Bluetooth enabled requested by user, but stop waiting on shutdown.
315-
// If storage is not yet loaded, this will wait for that too.
316-
PROCESS_WAIT_UNTIL(pbsys_storage_settings_bluetooth_enabled() || pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST));
317-
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {
318-
break;
319-
}
320-
321314
// Enable Bluetooth.
322315
pbdrv_bluetooth_power_on(true);
323316
PROCESS_WAIT_UNTIL(pbdrv_bluetooth_is_ready());
324317

325-
// Start advertising, and show visual indicator on status light.
326-
pbdrv_bluetooth_start_advertising();
327-
pbsys_status_set(PBIO_PYBRICKS_STATUS_BLE_ADVERTISING);
328-
329318
// Now we are idle. We need to change the Bluetooth state and
330319
// indicators if a host connects to us, or a user program starts, or we
331320
// shut down, or Bluetooth is disabled by the user.
332321
PROCESS_WAIT_UNTIL(
333322
pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_LE)
334-
|| pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING)
335-
|| pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)
336-
|| !pbsys_storage_settings_bluetooth_enabled());
337-
338-
// Now change the state depending on which of the above was triggered.
339-
340-
// If connected, advertising stops automatically. Otherwise manually
341-
// stop advertising (if the user code started using the button or we
342-
// are shutting down or or BLE became disabled).
343-
if (pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_LE)) {
344-
pbsys_status_set(PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED);
345-
} else {
346-
pbdrv_bluetooth_stop_advertising();
347-
pbsys_status_clear(PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED); // REVISIT: also via state...
348-
}
349-
350-
// In all cases, clear the advertising flag to stop blinking.
351-
pbsys_status_clear(PBIO_PYBRICKS_STATUS_BLE_ADVERTISING);
323+
);
352324

353325
PT_INIT(&status_monitor_pt);
354326

355327
// The Bluetooth enabled flag can only change while disconnected and
356328
// while no program is running. So here it just serves to skip the
357329
// Bluetooth loop below and go directly to the disable step below it.
358-
while (pbsys_storage_settings_bluetooth_enabled()
359-
&& pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_LE)
330+
while (pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_LE)
360331
&& !pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {
361332

362333
if (pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_PYBRICKS)) {
@@ -391,9 +362,6 @@ PROCESS_THREAD(pbsys_bluetooth_process, ev, data) {
391362
PROCESS_WAIT_EVENT();
392363
}
393364

394-
pbsys_status_clear(PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED);
395-
pbsys_status_clear(PBIO_PYBRICKS_STATUS_BLE_ADVERTISING);
396-
397365
reset_all();
398366
PROCESS_WAIT_WHILE(pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING));
399367

0 commit comments

Comments
 (0)