Skip to content

Commit b292993

Browse files
committed
pbio/dcmotor: Cap max voltage at hardware limit.
1 parent 80ce0c7 commit b292993

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/pbio/src/dcmotor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ void pbio_dcmotor_get_settings(pbio_dcmotor_t *dcmotor, int32_t *max_voltage) {
127127
}
128128

129129
pbio_error_t pbio_dcmotor_set_settings(pbio_dcmotor_t *dcmotor, int32_t max_voltage) {
130+
// New maximum voltage must be positive and at or below hardware limit.
131+
if (max_voltage < 0 || max_voltage > pbio_dcmotor_get_max_voltage(dcmotor->id)) {
132+
return PBIO_ERROR_INVALID_ARG;
133+
}
134+
// Set the new value.
130135
dcmotor->max_voltage = max_voltage;
131136
return PBIO_SUCCESS;
132137
}

0 commit comments

Comments
 (0)