Skip to content

Commit 7a6cf29

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 5df8453 commit 7a6cf29

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
connection. All of the above Remote and Xbox Controller were introduced in
3838
the previous beta release, so did not affect any stable release ([support#2521]).
3939
- Fixed Xbox Controller sometimes not working the first time ([support#1509]).
40+
- Fixed motors sometimes not working after boot.
4041

4142
[support#1509]: https://github.com/pybricks/support/issues/1509
4243
[support#1962]: https://github.com/pybricks/support/issues/1962

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)