Skip to content

Commit 8ca28cd

Browse files
committed
pbio/sys/main: Fix shutdown animation sometimes not visible.
When shutting down due to Bluetooth getting stuck, we were not showing the shutdown animation because the shutdown request state was never set, and the program run state was not cleared. This made it look like a full system crash, when it was still a clean shutdown.
1 parent d991f6d commit 8ca28cd

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Fixed internal rounding error that could could cause a Drive Base to be 1 mm
2727
off after driving 3 meters, depending on configuration parameters ([support#2500]).
2828
- Fixed Powered Up remote light getting the wrong color ([support#2497]).
29+
- Fix shutdown animation not visible when shutting down due to Bluetooth glitches.
2930

3031
[support#1962]: https://github.com/pybricks/support/issues/1962
3132
[support#2468]: https://github.com/pybricks/support/issues/2468

lib/pbio/sys/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ void pbsys_init(void) {
8787

8888
void pbsys_deinit(void) {
8989

90+
// Used by status indications during shutdown.
91+
pbsys_status_set(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST);
92+
9093
pbio_os_process_make_request(&pbsys_system_poll_process, PBIO_OS_PROCESS_REQUEST_TYPE_CANCEL);
9194

9295
pbsys_storage_deinit();

lib/pbio/sys/main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ void pbsys_main(void) {
112112

113113
// Stop motors, user animations, user bluetooth activity, etc.
114114
err = pbio_main_stop_application_resources();
115-
if (err != PBIO_SUCCESS) {
116-
// If we couldn't get the system back in a normal state, proceed
117-
// towards shutdown.
118-
break;
119-
}
120115

121116
// Get system back in idle state.
122117
pbsys_status_clear(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING);
@@ -129,6 +124,13 @@ void pbsys_main(void) {
129124
while (pbio_os_run_processes_once()) {
130125
}
131126

127+
if (err != PBIO_SUCCESS) {
128+
// If we couldn't get the system back in a normal state after
129+
// running a program, proceed towards shutdown. In practice, this
130+
// only happens for rare Bluetooth glitches on some platforms.
131+
break;
132+
}
133+
132134
// Finalize application now that system resources are safely closed.
133135
pbsys_main_run_program_cleanup();
134136
}

0 commit comments

Comments
 (0)