summaryrefslogtreecommitdiff
path: root/quantum/encoder.c
diff options
context:
space:
mode:
authorMarek Wyborski <9861955+mwyborski@users.noreply.github.com>2022-07-02 14:12:41 +0200
committerGitHub <noreply@github.com>2022-07-02 22:12:41 +1000
commitb8e8a20ca64327d0c5276f87a9dddc8e83cee0de (patch)
tree8a80d0be0a94b0db21f2cebc80b76ec2dad87cf0 /quantum/encoder.c
parent3ecb0a80af9e4ce4194a34032642933641730706 (diff)
Improve ENCODER_DEFAULT_POS to recognize lost ticks (#16932)
Diffstat (limited to 'quantum/encoder.c')
-rw-r--r--quantum/encoder.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/quantum/encoder.c b/quantum/encoder.c
index 105bed0147..5f8a7ce080 100644
--- a/quantum/encoder.c
+++ b/quantum/encoder.c
@@ -163,27 +163,38 @@ static bool encoder_update(uint8_t index, uint8_t state) {
163 index += thisHand; 163 index += thisHand;
164#endif 164#endif
165 encoder_pulses[i] += encoder_LUT[state & 0xF]; 165 encoder_pulses[i] += encoder_LUT[state & 0xF];
166
167#ifdef ENCODER_DEFAULT_POS
168 if ((encoder_pulses[i] >= resolution) || (encoder_pulses[i] <= -resolution) || ((state & 0x3) == ENCODER_DEFAULT_POS)) {
169 if (encoder_pulses[i] >= 1) {
170#else
166 if (encoder_pulses[i] >= resolution) { 171 if (encoder_pulses[i] >= resolution) {
167 encoder_value[index]++; 172#endif
168 changed = true; 173
174 encoder_value[index]++;
175 changed = true;
169#ifdef ENCODER_MAP_ENABLE 176#ifdef ENCODER_MAP_ENABLE
170 encoder_exec_mapping(index, ENCODER_COUNTER_CLOCKWISE); 177 encoder_exec_mapping(index, ENCODER_COUNTER_CLOCKWISE);
171#else // ENCODER_MAP_ENABLE 178#else // ENCODER_MAP_ENABLE
172 encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); 179 encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE);
173#endif // ENCODER_MAP_ENABLE 180#endif // ENCODER_MAP_ENABLE
174 } 181 }
182
183#ifdef ENCODER_DEFAULT_POS
184 if (encoder_pulses[i] <= -1) {
185#else
175 if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise 186 if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise
176 encoder_value[index]--; 187#endif
177 changed = true; 188 encoder_value[index]--;
189 changed = true;
178#ifdef ENCODER_MAP_ENABLE 190#ifdef ENCODER_MAP_ENABLE
179 encoder_exec_mapping(index, ENCODER_CLOCKWISE); 191 encoder_exec_mapping(index, ENCODER_CLOCKWISE);
180#else // ENCODER_MAP_ENABLE 192#else // ENCODER_MAP_ENABLE
181 encoder_update_kb(index, ENCODER_CLOCKWISE); 193 encoder_update_kb(index, ENCODER_CLOCKWISE);
182#endif // ENCODER_MAP_ENABLE 194#endif // ENCODER_MAP_ENABLE
183 } 195 }
184 encoder_pulses[i] %= resolution; 196 encoder_pulses[i] %= resolution;
185#ifdef ENCODER_DEFAULT_POS 197#ifdef ENCODER_DEFAULT_POS
186 if ((state & 0x3) == ENCODER_DEFAULT_POS) {
187 encoder_pulses[i] = 0; 198 encoder_pulses[i] = 0;
188 } 199 }
189#endif 200#endif