stm32/servo: Fix angle and speed methods to work again with -ve args.
Fixes a regression introduced by 70affd9ba2
Fixes issue #6403
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
acdb0608b7
commit
b31cb21a39
@ -278,7 +278,7 @@ STATIC mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_obj_new_int((self->pulse_cur - self->pulse_centre) * 90 / self->pulse_angle_90);
|
||||
} else {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
self->pulse_dest = self->pulse_centre + (uint16_t)((mp_float_t)self->pulse_angle_90 * mp_obj_get_float(args[1]) / MICROPY_FLOAT_CONST(90.0));
|
||||
self->pulse_dest = self->pulse_centre + (int16_t)((mp_float_t)self->pulse_angle_90 * mp_obj_get_float(args[1]) / MICROPY_FLOAT_CONST(90.0));
|
||||
#else
|
||||
self->pulse_dest = self->pulse_centre + self->pulse_angle_90 * mp_obj_get_int(args[1]) / 90;
|
||||
#endif
|
||||
@ -308,7 +308,7 @@ STATIC mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_obj_new_int((self->pulse_cur - self->pulse_centre) * 100 / self->pulse_speed_100);
|
||||
} else {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
self->pulse_dest = self->pulse_centre + (uint16_t)((mp_float_t)self->pulse_speed_100 * mp_obj_get_float(args[1]) / MICROPY_FLOAT_CONST(100.0));
|
||||
self->pulse_dest = self->pulse_centre + (int16_t)((mp_float_t)self->pulse_speed_100 * mp_obj_get_float(args[1]) / MICROPY_FLOAT_CONST(100.0));
|
||||
#else
|
||||
self->pulse_dest = self->pulse_centre + self->pulse_speed_100 * mp_obj_get_int(args[1]) / 100;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user