Account for divisor when overriding position.

This commit is contained in:
Dominic Davis-Foster 2022-04-06 18:13:59 +01:00
parent 319ca8560c
commit f297e872d6
No known key found for this signature in database
GPG Key ID: 3DCA8C2F52EC3292

View File

@ -98,12 +98,12 @@ mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementa
int16_t count;
pcnt_get_counter_value(self->unit, &count);
return (count / self->divisor) + self->position;
return (count + self->position) / self->divisor;
}
void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t *self,
mp_int_t new_position) {
self->position = new_position;
self->position = new_position * self->divisor;
pcnt_counter_clear(self->unit);
}