Skip to content

Commit

Permalink
sys/main: process all events before power off
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dlech committed Jul 6, 2021
1 parent 52447b3 commit 443ddd7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Changelog


## [Unreleased]

### Fixed
- Fixed City hub not always powering off on shutdown ([support#385])

## [3.1.0a2] - 2021-07-06

### Added
Expand Down Expand Up @@ -79,6 +85,7 @@ Prerelease changes are documented at [support#48].
[support#352]: https://github.com/pybricks/support/issues/352
[support#361]: https://github.com/pybricks/support/issues/361
[support#379]: https://github.com/pybricks/support/issues/379
[support#385]: https://github.com/pybricks/support/issues/385

[Unreleased]: https://github.com/pybricks/pybricks-micropython/compare/v3.1.0a2...HEAD
[3.1.0a2]: https://github.com/pybricks/pybricks-micropython/compare/v3.0.0a1...v3.1.0a2
Expand Down
8 changes: 7 additions & 1 deletion lib/pbio/sys/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ void pbsys_main(pbsys_main_t main) {
pbsys_user_program_unprepare();
}

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

0 comments on commit 443ddd7

Please sign in to comment.