Skip to content

Commit 33a1ad4

Browse files
committed
sys/main: process all events before power off
This fixes an odd behavior where the City hub turns itself back on as soon as it powers off. This is probably a hardware issue, e.g. an induced voltage somewhere is enough to turn it back on. Fixes: pybricks/support#385
1 parent 52447b3 commit 33a1ad4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
# Changelog
44

5+
6+
## [Unreleased]
7+
8+
### Fixed
9+
- Fixed City hub not always powering off on shutdown ([support#385]).
10+
511
## [3.1.0a2] - 2021-07-06
612

713
### Added
@@ -79,6 +85,7 @@ Prerelease changes are documented at [support#48].
7985
[support#352]: https://github.com/pybricks/support/issues/352
8086
[support#361]: https://github.com/pybricks/support/issues/361
8187
[support#379]: https://github.com/pybricks/support/issues/379
88+
[support#385]: https://github.com/pybricks/support/issues/385
8289

8390
[Unreleased]: https://github.com/pybricks/pybricks-micropython/compare/v3.1.0a2...HEAD
8491
[3.1.0a2]: https://github.com/pybricks/pybricks-micropython/compare/v3.0.0a1...v3.1.0a2

lib/pbio/sys/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ void pbsys_main(pbsys_main_t main) {
4242
pbsys_user_program_unprepare();
4343
}
4444

45+
// The power could be held on due to someone pressing the center button
46+
// or USB being plugged in, so we have this loop to keep pumping events
47+
// to turn off most of the peripherals and keep the battery charger running.
4548
for (;;) {
49+
// We must handle all pending events before turning the power off the
50+
// first time, otherwise the city hub turns itself back on sometimes.
51+
while (pbio_do_one_event()) {
52+
}
4653
pbdrv_reset_power_off();
47-
pbio_do_one_event();
4854
}
4955
}

0 commit comments

Comments
 (0)