Skip to content

Commit b005bfc

Browse files
committed
sys/supervisor: shutdown if no BLE connection within 30 seconds
This shuts down hubs if no BLE connection is made with 30 seconds. This is done to save battery. This is particularly important on SPIKE Prime/ MINDSTORMS Inventor since it is very easy to accidentally to press the power button without knowing it. Fixes pybricks/support#79
1 parent 7e1d461 commit b005bfc

File tree

5 files changed

+3
-5
lines changed

5 files changed

+3
-5
lines changed

lib/pbio/drv/bluetooth/bluetooth_btstack.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ PROCESS_THREAD(pbdrv_bluetooth_hci_process, ev, data) {
187187
init_advertising_data();
188188
gap_advertisements_enable(true);
189189

190-
// TODO: we should have a timeout and stop scanning eventually
191190
// TODO: allow user programs to initiate BLE connections
192191
pbsys_status_set(PBSYS_STATUS_BLE_ADVERTISING);
193192
PROCESS_WAIT_UNTIL(con_handle != HCI_CON_HANDLE_INVALID || pbsys_status_test(PBSYS_STATUS_USER_PROGRAM_RUNNING));

lib/pbio/drv/city_hub/bluetooth.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,6 @@ PROCESS_THREAD(pbdrv_bluetooth_hci_process, ev, data) {
12071207
PROCESS_PT_SPAWN(&child_pt, init_uart_service(&child_pt));
12081208
PROCESS_PT_SPAWN(&child_pt, set_discoverable(&child_pt));
12091209

1210-
// TODO: we should have a timeout and stop scanning eventually
12111210
// TODO: allow user programs to initiate BLE connections
12121211
pbsys_status_set(PBSYS_STATUS_BLE_ADVERTISING);
12131212
PROCESS_WAIT_UNTIL(conn_handle != NO_CONNECTION || pbsys_status_test(PBSYS_STATUS_USER_PROGRAM_RUNNING));

lib/pbio/drv/move_hub/bluetooth.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ PROCESS_THREAD(pbdrv_bluetooth_hci_process, ev, data) {
664664
PROCESS_PT_SPAWN(&child_pt, init_uart_service(&child_pt));
665665
PROCESS_PT_SPAWN(&child_pt, set_discoverable(&child_pt));
666666

667-
// TODO: we should have a timeout and stop scanning eventually
668667
// TODO: allow user programs to initiate BLE connections
669668
pbsys_status_set(PBSYS_STATUS_BLE_ADVERTISING);
670669
PROCESS_WAIT_UNTIL(conn_handle || pbsys_status_test(PBSYS_STATUS_USER_PROGRAM_RUNNING));

lib/pbio/drv/technic_hub/bluetooth.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,6 @@ PROCESS_THREAD(pbdrv_bluetooth_hci_process, ev, data) {
12041204
PROCESS_PT_SPAWN(&child_pt, init_uart_service(&child_pt));
12051205
PROCESS_PT_SPAWN(&child_pt, set_discoverable(&child_pt));
12061206

1207-
// TODO: we should have a timeout and stop scanning eventually
12081207
// TODO: allow user programs to initiate BLE connections
12091208
pbsys_status_set(PBSYS_STATUS_BLE_ADVERTISING);
12101209
PROCESS_WAIT_UNTIL(conn_handle != NO_CONNECTION || pbsys_status_test(PBSYS_STATUS_USER_PROGRAM_RUNNING));

lib/pbio/sys/supervisor.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*/
1919
void pbsys_supervisor_poll() {
2020
// Shut down on low voltage so we don't damage rechargeable batteries
21-
if (pbsys_status_test_debounce(PBSYS_STATUS_BATTERY_LOW_VOLTAGE_SHUTDOWN, true, 3000)) {
21+
// or if there is no BLE connection made whithin 30 seconds
22+
if (pbsys_status_test_debounce(PBSYS_STATUS_BATTERY_LOW_VOLTAGE_SHUTDOWN, true, 3000)
23+
|| pbsys_status_test_debounce(PBSYS_STATUS_BLE_ADVERTISING, true, 30000)) {
2224
// REVISIT: this assumes that the power button is not pressed and USB is
2325
// not plugged in so that the power will actually turn off here
2426
pbdrv_reset(PBDRV_RESET_ACTION_POWER_OFF);

0 commit comments

Comments
 (0)