From c107b61eac8ca3ccbb9efff336441505d782fa9d Mon Sep 17 00:00:00 2001 From: tucvbif <47757803+tucvbif@users.noreply.github.com> Date: Sat, 24 Jul 2021 23:53:29 +0300 Subject: [PATCH] Remove hysteresis on 4x encoders Sometimes, controller skips encoder pulses and when it returns to default position, the encoder_pulses variable isn't equals 0. And when I turn encoder in opposite direciton, it skips first click becase of encoder_pulses crosses zero. To prevent this, I add the ENCODER_DEFAULT_POS constant, and reset encoder_pulses into 0 when the state variable equals ENCODER_DEFAULT_POS. --- quantum/encoder.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/quantum/encoder.c b/quantum/encoder.c index c30bf01cb2f6..8fb87281c2b1 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -119,6 +119,11 @@ static bool encoder_update(uint8_t index, uint8_t state) { encoder_update_kb(index, ENCODER_CLOCKWISE); } encoder_pulses[i] %= resolution; +#ifdef ENCODER_DEFAULT_POS + if ((state & 0x3) == ENCODER_DEFAULT_POS) { + encoder_pulses[i] = 0; + } +#endif return changed; }