Skip to content

Commit 4e0cc44

Browse files
committed
pbio/port_lump: Retry mode switch on timeout.
We trigger a mode change for motors on boot, but in rare cases the motor never changes mode. Retrying works.
1 parent e1850c1 commit 4e0cc44

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
connection. All of the above Remote and Xbox Controller were introduced in
4040
the previous beta release, so did not affect any stable release ([support#2521]).
4141
- Fixed Xbox Controller sometimes not working the first time ([support#1509]).
42+
- Fixed motors sometimes not working after boot ([support#2550]).
4243

4344
[support#1509]: https://github.com/pybricks/support/issues/1509
4445
[support#1962]: https://github.com/pybricks/support/issues/1962
@@ -47,6 +48,7 @@
4748
[support#2500]: https://github.com/pybricks/support/issues/2500
4849
[support#2521]: https://github.com/pybricks/support/issues/2521
4950
[support#2522]: https://github.com/pybricks/support/issues/2522
51+
[support#2550]: https://github.com/pybricks/support/issues/2550
5052
[pybricks-micropython#405]: https://github.com/pybricks/pybricks-micropython/pull/405
5153
[pybricks-micropython#421]: https://github.com/pybricks/pybricks-micropython/pull/421
5254
[pybricks-micropython#425]: https://github.com/pybricks/pybricks-micropython/pull/425

lib/pbio/src/port_lump.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,10 @@ pbio_error_t pbio_port_lump_is_ready(pbio_port_lump_dev_t *lump_dev) {
10841084

10851085
// Not ready if waiting for mode change
10861086
if (lump_dev->mode != lump_dev->mode_switch.desired_mode) {
1087+
if (time - lump_dev->mode_switch.time > 500) {
1088+
debug_pr("Mode switch timed out. Retrying.\n");
1089+
pbio_port_lump_request_mode(lump_dev, lump_dev->mode_switch.desired_mode);
1090+
}
10871091
return PBIO_ERROR_AGAIN;
10881092
}
10891093

@@ -1113,6 +1117,8 @@ pbio_error_t pbio_port_lump_is_ready(pbio_port_lump_dev_t *lump_dev) {
11131117
*/
11141118
pbio_error_t pbio_port_lump_set_mode(pbio_port_lump_dev_t *lump_dev, uint8_t mode) {
11151119

1120+
debug_pr("Set mode to %d\n.", mode);
1121+
11161122
if (!lump_dev) {
11171123
return PBIO_ERROR_NO_DEV;
11181124
}

0 commit comments

Comments
 (0)