Add quarter-click logic to adafruit/circuitpython#1045
This commit is contained in:
parent
95454ecde0
commit
a7c349bc6e
|
@ -43,11 +43,21 @@ static void _intr_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
|||
new_state = (new_state << 1) + (new_state ^ nrf_gpio_pin_read(self->pin_b));
|
||||
|
||||
uint8_t change = (new_state - self->state) & 0x03;
|
||||
if (change == 1) self->position++;
|
||||
else if (change == 3) self->position--;
|
||||
if (change == 1) self->quarter++;
|
||||
else if (change == 3) self->quarter--;
|
||||
// ignore other state transitions
|
||||
|
||||
self->state = new_state;
|
||||
|
||||
// logic from the atmel-samd port: provides some damping and scales movement
|
||||
// down by 4:1.
|
||||
if (self->quarter >= 4) {
|
||||
self->position++;
|
||||
self->quarter = 0;
|
||||
} else if (self->quarter <= -4) {
|
||||
self->position--;
|
||||
self->quarter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t* self,
|
||||
|
|
|
@ -36,6 +36,7 @@ typedef struct {
|
|||
uint8_t pin_a;
|
||||
uint8_t pin_b;
|
||||
uint8_t state;
|
||||
int8_t quarter;
|
||||
mp_int_t position;
|
||||
} rotaryio_incrementalencoder_obj_t;
|
||||
|
||||
|
|
Loading…
Reference in New Issue