Skip to content

Commit 32db6b6

Browse files
committed
pbio/sys: Move asynhronous reset handling to shutdown logic.
This logic only applies to shutting down, so it is easier to follow by including it in the shutdown code. Then we can see that the main function never gets to the normal power off.
1 parent 884b2a9 commit 32db6b6

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/pbio/sys/hmi.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,6 @@ void pbsys_hmi_init(void) {
176176
void pbsys_hmi_handle_status_change(pbsys_status_change_t event, pbio_pybricks_status_t data) {
177177
pbsys_status_light_handle_status_change(event, data);
178178
pbsys_hub_light_matrix_handle_status_change(event, data);
179-
180-
#if PBSYS_CONFIG_BATTERY_CHARGER
181-
// On the Technic Large hub, USB can keep the power on even though we are
182-
// "shutdown", so if the button is pressed again, we reset to turn back on
183-
if (
184-
pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)
185-
&& event == PBSYS_STATUS_CHANGE_SET
186-
&& data == PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED
187-
) {
188-
pbdrv_reset(PBDRV_RESET_ACTION_RESET);
189-
}
190-
#endif // PBSYS_CONFIG_BATTERY_CHARGER
191179
}
192180

193181
/**

lib/pbio/sys/main.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,24 @@ int main(int argc, char **argv) {
133133
pbsys_status_set(PBIO_PYBRICKS_STATUS_SHUTDOWN);
134134

135135
// The power could be held on due to someone pressing the center button
136-
// or USB being plugged in, so we have this loop to keep pumping events
137-
// to turn off most of the peripherals and keep the battery charger running.
138-
while (pbsys_status_test(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED) || pbdrv_usb_get_bcd() != PBDRV_USB_BCD_NONE) {
136+
// so we have this loop to keep handling events to drive processes that
137+
// turn off some of the peripherals.
138+
while (pbsys_status_test(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED)) {
139139
pbio_os_run_processes_and_wait_for_event();
140140
}
141141

142+
#if PBSYS_CONFIG_BATTERY_CHARGER
143+
// Similarly, run events to keep charging while the hub is "off".
144+
while (pbdrv_usb_get_bcd() != PBDRV_USB_BCD_NONE) {
145+
pbio_os_run_processes_and_wait_for_event();
146+
// If the button is pressed again, the user wants to turn the hub
147+
// "back on". We are still on, so do a full reset instead.
148+
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED)) {
149+
pbdrv_reset(PBDRV_RESET_ACTION_RESET);
150+
}
151+
}
152+
#endif
153+
142154
// Platform-specific power off.
143155
pbdrv_reset_power_off();
144156
}

0 commit comments

Comments
 (0)