pbio/hbridge: set state for passive duty
Flip order of these two commands, or pbio_hbridge_set_duty_cycle_sys would overwrite the state.
@@ -100,8 +100,12 @@ pbio_error_t pbio_hbridge_set_duty_cycle_sys(pbio_hbridge_t *hbridge, int32_t du
}
pbio_error_t pbio_hbridge_set_duty_cycle_usr(pbio_hbridge_t *hbridge, int32_t duty_steps) {
+ pbio_error_t err = pbio_hbridge_set_duty_cycle_sys(hbridge, PBIO_DUTY_STEPS * duty_steps / PBIO_DUTY_USER_STEPS);
+ if (err != PBIO_SUCCESS) {
+ return err;
+ }
hbridge->state = PBIO_HBRIDGE_DUTY_PASSIVE;
- return pbio_hbridge_set_duty_cycle_sys(hbridge, PBIO_DUTY_STEPS * duty_steps / PBIO_DUTY_USER_STEPS);
+ return PBIO_SUCCESS;
}
#endif // PBIO_CONFIG_HBRIDGE
