Skip to content

Commit f297e87

Browse files
committed
Account for divisor when overriding position.
1 parent 319ca85 commit f297e87

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ports/espressif/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementa
9898
int16_t count;
9999
pcnt_get_counter_value(self->unit, &count);
100100

101-
return (count / self->divisor) + self->position;
101+
return (count + self->position) / self->divisor;
102102
}
103103

104104
void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t *self,
105105
mp_int_t new_position) {
106-
self->position = new_position;
106+
self->position = new_position * self->divisor;
107107
pcnt_counter_clear(self->unit);
108108
}
109109

0 commit comments

Comments
 (0)