Skip to content

Commit 155f995

Browse files
committed
pbio/sys/light: Fix light animation while USB connected.
The guard for PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH was only active for the BLE light, but not USB. Move it to one place to make it clearer. Also rename the symbols consistently while we are touching this.
1 parent b45b272 commit 155f995

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lib/pbio/sys/light.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ static pbsys_status_light_t pbsys_status_light_instance_main;
150150
pbio_color_light_t *pbsys_status_light_main = &pbsys_status_light_instance_main.color_light;
151151

152152
#if PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH
153-
static pbsys_status_light_t pbsys_status_light_instance_ble;
154-
static pbsys_status_light_pattern_state_t *ble_pattern_state = &pbsys_status_light_instance_ble.pattern_state;
153+
static pbsys_status_light_t pbsys_status_light_instance_usb_ble;
154+
static pbsys_status_light_pattern_state_t *usb_ble_pattern_state = &pbsys_status_light_instance_usb_ble.pattern_state;
155155
static pbsys_status_light_pattern_state_t *warning_pattern_state = &pbsys_status_light_instance_main.pattern_state;
156156
#else
157-
static pbsys_status_light_pattern_state_t *ble_pattern_state = &pbsys_status_light_instance_main.pattern_state;
157+
static pbsys_status_light_pattern_state_t *usb_ble_pattern_state = &pbsys_status_light_instance_main.pattern_state;
158158
static pbsys_status_light_pattern_state_t *warning_pattern_state = &pbsys_status_light_instance_main.pattern_overlay_state;
159159
#endif
160160

@@ -183,8 +183,8 @@ void pbsys_status_light_init(void) {
183183
pbdrv_led_get_dev(0, &pbsys_status_light_instance_main.led);
184184
pbio_color_light_init(pbsys_status_light_main, &pbsys_status_light_funcs);
185185
#if PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH
186-
pbdrv_led_get_dev(2, &pbsys_status_light_instance_ble.led);
187-
pbio_color_light_init(&pbsys_status_light_instance_ble.color_light, &pbsys_status_light_funcs);
186+
pbdrv_led_get_dev(2, &pbsys_status_light_instance_usb_ble.led);
187+
pbio_color_light_init(&pbsys_status_light_instance_usb_ble.color_light, &pbsys_status_light_funcs);
188188
#endif
189189
}
190190

@@ -210,20 +210,22 @@ void pbsys_status_light_handle_status_change(void) {
210210
usb_ble_indication = PBSYS_STATUS_LIGHT_INDICATION_USB_ACTIVE_BLE_ANY;
211211
} else if (pbsys_status_test(PBIO_PYBRICKS_STATUS_BLE_ADVERTISING)) {
212212
usb_ble_indication = PBSYS_STATUS_LIGHT_INDICATION_USB_NONE_BLE_ADVERTISING;
213-
} else if (pbsys_status_test(PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED)
214-
#if !PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH
215-
// Hubs without Bluetooth light show idle state only when program not running.
216-
&& !pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING)
217-
#endif
218-
) {
213+
} else if (pbsys_status_test(PBIO_PYBRICKS_STATUS_BLE_HOST_CONNECTED)) {
219214
usb_ble_indication = PBSYS_STATUS_LIGHT_INDICATION_USB_NONE_BLE_CONNECTED;
220215
}
221216

217+
#if !PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH
218+
// Hubs without Bluetooth light don't show connectivity state if program is running.
219+
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING)) {
220+
usb_ble_indication = PBSYS_STATUS_LIGHT_INDICATION_USB_NONE_BLE_NONE;
221+
}
222+
#endif
223+
222224
// If the indication changed, then reset the indication pattern to the
223225
// beginning. Reset both so that patterns with the same length stay in sync.
224-
if (ble_pattern_state->indication != usb_ble_indication || warning_pattern_state->indication != warning_indication) {
225-
ble_pattern_state->indication = usb_ble_indication;
226-
ble_pattern_state->pattern_index = ble_pattern_state->pattern_count = 0;
226+
if (usb_ble_pattern_state->indication != usb_ble_indication || warning_pattern_state->indication != warning_indication) {
227+
usb_ble_pattern_state->indication = usb_ble_indication;
228+
usb_ble_pattern_state->pattern_index = usb_ble_pattern_state->pattern_count = 0;
227229

228230
warning_pattern_state->indication = warning_indication;
229231
warning_pattern_state->pattern_index = warning_pattern_state->pattern_count = 0;
@@ -347,7 +349,7 @@ void pbsys_status_light_poll(void) {
347349
warning_pattern_state, pbsys_status_light_indication_pattern_warning);
348350

349351
pbio_color_t new_ble_color = pbsys_status_light_pattern_next(
350-
ble_pattern_state, pbsys_status_light_indication_pattern_ble);
352+
usb_ble_pattern_state, pbsys_status_light_indication_pattern_ble);
351353

352354

353355
pbio_color_t new_main_color = new_warning_color;
@@ -366,7 +368,7 @@ void pbsys_status_light_poll(void) {
366368

367369
pbsys_status_light_set_pattern_or_user_color(&pbsys_status_light_instance_main, new_main_color);
368370
#if PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH
369-
pbsys_status_light_set_pattern_or_user_color(&pbsys_status_light_instance_ble, new_ble_color);
371+
pbsys_status_light_set_pattern_or_user_color(&pbsys_status_light_instance_usb_ble, new_ble_color);
370372
#endif
371373

372374
// REVISIT: We should be able to make updating the state event driven instead of polled.

0 commit comments

Comments
 (0)