Skip to content

Commit

Permalink
pbio/sys/light: Tweak light patterns.
Browse files Browse the repository at this point in the history
The Prime Hub Bluetooth LED is not very bright, so
the short blink is hardly visible. This makes it
longer. Also change other warning patterns to
match.

Also stop advertising on shutdown request instead
of shutdown, so that the Bluetooth light does not
keep blinking during shutdown. This also gives
a more intuitive response when connected, since
Pybricks Code now becomes disconnected
relatively sooner, matching hun shutdown.
  • Loading branch information
laurensvalk committed Sep 2, 2024
1 parent 8fc935b commit 44c734a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 6 additions & 5 deletions lib/pbio/sys/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ PROCESS_THREAD(pbsys_bluetooth_process, ev, data) {
pbdrv_bluetooth_set_on_event(pbsys_bluetooth_process_poll);
pbdrv_bluetooth_set_receive_handler(handle_receive);

while (!pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)) {
while (!pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {

// make sure the Bluetooth chip is in reset long enough to actually reset
etimer_set(&timer, 150);
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer));

// Wait until Bluetooth enabled requested by user, but stop waiting on shutdown.
// If storage is not yet loaded, this will wait for that too.
PROCESS_WAIT_UNTIL(pbsys_storage_settings_bluetooth_enabled() || pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN));
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)) {
PROCESS_WAIT_UNTIL(pbsys_storage_settings_bluetooth_enabled() || pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST));
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {
break;
}

Expand All @@ -320,7 +320,7 @@ PROCESS_THREAD(pbsys_bluetooth_process, ev, data) {
PROCESS_WAIT_UNTIL(
pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_LE)
|| pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING)
|| pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)
|| pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)
|| !pbsys_storage_settings_bluetooth_enabled());

// Now change the state depending on which of the above was triggered.
Expand All @@ -345,7 +345,7 @@ PROCESS_THREAD(pbsys_bluetooth_process, ev, data) {
// Bluetooth loop below and go directly to the disable step below it.
while (pbsys_storage_settings_bluetooth_enabled()
&& pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_LE)
&& !pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)) {
&& !pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {

if (pbdrv_bluetooth_is_connected(PBDRV_BLUETOOTH_CONNECTION_PYBRICKS)) {
// Since pbsys status events are broadcast to all processes, this
Expand Down Expand Up @@ -380,6 +380,7 @@ PROCESS_THREAD(pbsys_bluetooth_process, ev, data) {
}

pbsys_status_clear(PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED);
pbsys_status_clear(PBIO_PYBRICKS_STATUS_BLE_ADVERTISING);

reset_all();
PROCESS_WAIT_WHILE(pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING));
Expand Down
14 changes: 8 additions & 6 deletions lib/pbio/sys/light.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ pbsys_status_light_indication_pattern_warning[] = {
// Two red blinks, pause, then repeat. Overlays on lower priority signal.
[PBSYS_STATUS_LIGHT_INDICATION_WARNING_HIGH_CURRENT] =
(const pbsys_status_light_indication_pattern_element_t[]) {
{ .color = PBIO_COLOR_RED, .duration = 1 },
{ .color = PBIO_COLOR_RED, .duration = 2 },
{ .color = PBIO_COLOR_NONE, .duration = 2 },
{ .color = PBIO_COLOR_RED, .duration = 1 },
{ .color = PBIO_COLOR_RED, .duration = 2 },
{ .color = PBIO_COLOR_NONE, .duration = 22 },
PBSYS_STATUS_LIGHT_INDICATION_PATTERN_REPEAT
},
// Two orange blinks, pause, then repeat. Overlays on lower priority signal.
[PBSYS_STATUS_LIGHT_INDICATION_WARNING_LOW_VOLTAGE] =
(const pbsys_status_light_indication_pattern_element_t[]) {
{ .color = PBIO_COLOR_ORANGE, .duration = 1 },
{ .color = PBIO_COLOR_ORANGE, .duration = 2 },
{ .color = PBIO_COLOR_NONE, .duration = 2 },
{ .color = PBIO_COLOR_ORANGE, .duration = 1 },
{ .color = PBIO_COLOR_ORANGE, .duration = 2 },
{ .color = PBIO_COLOR_NONE, .duration = 22 },
PBSYS_STATUS_LIGHT_INDICATION_PATTERN_REPEAT
},
Expand All @@ -103,9 +103,9 @@ pbsys_status_light_indication_pattern_ble[] = {
// Two blue blinks, pause, then repeat.
[PBSYS_STATUS_LIGHT_INDICATION_BLUETOOTH_BLE_ADVERTISING] =
(const pbsys_status_light_indication_pattern_element_t[]) {
{ .color = PBIO_COLOR_BLUE, .duration = 1 },
{ .color = PBIO_COLOR_BLUE, .duration = 2 },
{ .color = PBIO_COLOR_BLACK, .duration = 2 },
{ .color = PBIO_COLOR_BLUE, .duration = 1 },
{ .color = PBIO_COLOR_BLUE, .duration = 2 },
{ .color = PBIO_COLOR_BLACK, .duration = 22 },
PBSYS_STATUS_LIGHT_INDICATION_PATTERN_REPEAT
},
Expand Down Expand Up @@ -189,8 +189,10 @@ static void pbsys_status_light_handle_status_change(void) {
pbsys_status_light_indication_warning_t warning_indication = PBSYS_STATUS_LIGHT_INDICATION_WARNING_NONE;
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)) {
warning_indication = PBSYS_STATUS_LIGHT_INDICATION_WARNING_SHUTDOWN;
#if PBSYS_CONFIG_STATUS_LIGHT_STATE_ANIMATIONS
} else if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {
warning_indication = PBSYS_STATUS_LIGHT_INDICATION_WARNING_SHUTDOWN_REQUESTED;
#endif
} else if (pbsys_status_test(PBIO_PYBRICKS_STATUS_BATTERY_HIGH_CURRENT)) {
warning_indication = PBSYS_STATUS_LIGHT_INDICATION_WARNING_HIGH_CURRENT;
} else if (pbsys_status_test(PBIO_PYBRICKS_STATUS_BATTERY_LOW_VOLTAGE_WARNING)) {
Expand Down

0 comments on commit 44c734a

Please sign in to comment.