Skip to content

Commit cb72ea5

Browse files
committed
pbdrv/ev3dev_stretch/motor: reinitialize on reset
When the port mode is being set/reset, be sure to set the connection status to false. This ensures that a subsequent call to the motor will reinitialize as needed.
1 parent 0f133f3 commit cb72ea5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/pbio/drv/ev3dev_stretch/motor.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ pbio_error_t pbdrv_motor_get_id(pbio_port_t port, pbio_iodev_type_id_t *id) {
191191
}
192192

193193
pbio_error_t pbdrv_motor_setup(pbio_port_t port, bool is_servo) {
194+
195+
// Verify port
196+
if (port < PBDRV_CONFIG_FIRST_MOTOR_PORT || port > PBDRV_CONFIG_LAST_MOTOR_PORT) {
197+
return PBIO_ERROR_INVALID_PORT;
198+
}
199+
// Set connected status to false so we reinitialize later
200+
motors[port - PBDRV_CONFIG_FIRST_MOTOR_PORT].connected = false;
201+
202+
// Set port mode to dc motor or servo
194203
if (!is_servo) {
195204
return ev3dev_lego_port_configure(port, PBIO_IODEV_TYPE_ID_EV3DEV_DC_MOTOR);
196205
}

0 commit comments

Comments
 (0)