diff --git a/CHANGELOG.md b/CHANGELOG.md index d71da9607..4ad60661f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - Fixed not able to connect to new Technic Move hub with `LWP3Device()`. - Removed `gc_collect()` from `tools.run_task()` loop to fix unwanted delays. - Fixed `await wait(0)` never yielding, so parallel tasks could lock up ([support#1429]). +- Fixed some sensors not powering off when the hub is turned off. ### Removed - Removed `loop_time` argument to `pybricks.tools.run_task` as this wasn't diff --git a/lib/pbio/include/pbdrv/motor_driver.h b/lib/pbio/include/pbdrv/motor_driver.h index cef5be275..34fca5063 100644 --- a/lib/pbio/include/pbdrv/motor_driver.h +++ b/lib/pbio/include/pbdrv/motor_driver.h @@ -75,6 +75,18 @@ pbio_error_t pbdrv_motor_driver_set_duty_cycle(pbdrv_motor_driver_dev_t *driver, */ pbio_error_t pbdrv_motor_driver_get_device_type_id(pbio_port_id_t port, pbdrv_legodev_type_id_t *type_id); +/** + * Powers off all motor outputs. + */ +static inline void pbdrv_motor_driver_power_off(void) { + for (uint8_t i = 0; i < PBDRV_CONFIG_MOTOR_DRIVER_NUM_DEV; i++) { + pbdrv_motor_driver_dev_t *driver; + if (pbdrv_motor_driver_get_dev(i, &driver) == PBIO_SUCCESS) { + pbdrv_motor_driver_coast(driver); + } + } +} + #else static inline pbio_error_t pbdrv_motor_driver_get_dev(uint8_t id, pbdrv_motor_driver_dev_t **driver) { @@ -94,6 +106,9 @@ static inline pbio_error_t pbdrv_motor_driver_get_device_type_id(pbio_port_id_t return PBIO_ERROR_NOT_SUPPORTED; } +static inline void pbdrv_motor_driver_power_off(void) { +} + #endif #endif // _PBDRV_MOTOR_DRIVER_H_ diff --git a/lib/pbio/sys/main.c b/lib/pbio/sys/main.c index 5b69e6e30..6dfb7e929 100644 --- a/lib/pbio/sys/main.c +++ b/lib/pbio/sys/main.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -113,6 +114,8 @@ int main(int argc, char **argv) { while (pbio_do_one_event()) { } + pbdrv_motor_driver_power_off(); + // Some hubs will turn themselves back on if I/O port VCC is off when // we call pbdrv_reset_power_off(). So don't turn off power until the // return value of pbdrv_ioport_power_off() tells us it is safe to do