Skip to content

Commit 80ce0c7

Browse files
committed
pbio/dcmotor: Simplify settings loader.
Since there is only one setting, it's easier to just have a getter for it. This way we can use it in the setter to avoid setting a value larger than the maximum.
1 parent 296ee98 commit 80ce0c7

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

lib/pbio/include/pbio/dcmotor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pbio_error_t pbio_dcmotor_brake(pbio_dcmotor_t *dcmotor);
4343
pbio_error_t pbio_dcmotor_set_voltage(pbio_dcmotor_t *dcmotor, int32_t voltage);
4444
pbio_error_t pbio_dcmotor_set_voltage_passive(pbio_dcmotor_t *dcmotor, int32_t voltage);
4545

46-
pbio_error_t pbio_dcmotor_load_settings(pbio_dcmotor_t *dcmotor, pbio_iodev_type_id_t id);
46+
int32_t pbio_dcmotor_get_max_voltage(pbio_iodev_type_id_t id);
4747

4848
void pbio_dcmotor_get_settings(pbio_dcmotor_t *dcmotor, int32_t *max_voltage);
4949
pbio_error_t pbio_dcmotor_set_settings(pbio_dcmotor_t *dcmotor, int32_t max_voltage);

lib/pbio/platform/motors/settings.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,11 @@ pbio_error_t pbio_servo_load_settings(pbio_control_settings_t *control_settings,
331331
}
332332
}
333333

334-
pbio_error_t pbio_dcmotor_load_settings(pbio_dcmotor_t *dcmotor, pbio_iodev_type_id_t id) {
335-
switch (id) {
336-
case PBIO_IODEV_TYPE_ID_NONE:
337-
return PBIO_ERROR_NOT_SUPPORTED;
338-
case PBIO_IODEV_TYPE_ID_SPIKE_S_MOTOR:
339-
dcmotor->max_voltage = 6000;
340-
return PBIO_SUCCESS;
341-
default:
342-
dcmotor->max_voltage = 9000;
343-
return PBIO_SUCCESS;
334+
int32_t pbio_dcmotor_get_max_voltage(pbio_iodev_type_id_t id) {
335+
if (id == PBIO_IODEV_TYPE_ID_SPIKE_S_MOTOR) {
336+
return 6000;
344337
}
338+
return 9000;
345339
}
346340

347341
#endif // PBDRV_CONFIG_NUM_MOTOR_CONTROLLER != 0

lib/pbio/src/dcmotor.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ static pbio_error_t pbio_dcmotor_setup(pbio_dcmotor_t *dcmotor, pbio_direction_t
4040
}
4141

4242
// Load settings for this motor
43-
err = pbio_dcmotor_load_settings(dcmotor, dcmotor->id);
44-
if (err != PBIO_SUCCESS) {
45-
return err;
46-
}
43+
dcmotor->max_voltage = pbio_dcmotor_get_max_voltage(dcmotor->id);
4744

4845
// Set direction and state
4946
dcmotor->direction = direction;

0 commit comments

Comments
 (0)