diff options
Diffstat (limited to 'quantum/encoder.c')
| -rw-r--r-- | quantum/encoder.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/quantum/encoder.c b/quantum/encoder.c index 0a3d6f577c..105bed0147 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c | |||
| @@ -23,6 +23,10 @@ | |||
| 23 | // for memcpy | 23 | // for memcpy |
| 24 | #include <string.h> | 24 | #include <string.h> |
| 25 | 25 | ||
| 26 | #ifndef ENCODER_MAP_KEY_DELAY | ||
| 27 | # define ENCODER_MAP_KEY_DELAY 2 | ||
| 28 | #endif | ||
| 29 | |||
| 26 | #if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION) | 30 | #if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION) |
| 27 | # define ENCODER_RESOLUTION 4 | 31 | # define ENCODER_RESOLUTION 4 |
| 28 | #endif | 32 | #endif |
| @@ -135,6 +139,16 @@ void encoder_init(void) { | |||
| 135 | } | 139 | } |
| 136 | } | 140 | } |
| 137 | 141 | ||
| 142 | #ifdef ENCODER_MAP_ENABLE | ||
| 143 | static void encoder_exec_mapping(uint8_t index, bool clockwise) { | ||
| 144 | // The delays below cater for Windows and its wonderful requirements. | ||
| 145 | action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true)); | ||
| 146 | wait_ms(ENCODER_MAP_KEY_DELAY); | ||
| 147 | action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false)); | ||
| 148 | wait_ms(ENCODER_MAP_KEY_DELAY); | ||
| 149 | } | ||
| 150 | #endif // ENCODER_MAP_ENABLE | ||
| 151 | |||
| 138 | static bool encoder_update(uint8_t index, uint8_t state) { | 152 | static bool encoder_update(uint8_t index, uint8_t state) { |
| 139 | bool changed = false; | 153 | bool changed = false; |
| 140 | uint8_t i = index; | 154 | uint8_t i = index; |
| @@ -152,12 +166,20 @@ static bool encoder_update(uint8_t index, uint8_t state) { | |||
| 152 | if (encoder_pulses[i] >= resolution) { | 166 | if (encoder_pulses[i] >= resolution) { |
| 153 | encoder_value[index]++; | 167 | encoder_value[index]++; |
| 154 | changed = true; | 168 | changed = true; |
| 169 | #ifdef ENCODER_MAP_ENABLE | ||
| 170 | encoder_exec_mapping(index, ENCODER_COUNTER_CLOCKWISE); | ||
| 171 | #else // ENCODER_MAP_ENABLE | ||
| 155 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); | 172 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); |
| 173 | #endif // ENCODER_MAP_ENABLE | ||
| 156 | } | 174 | } |
| 157 | if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise | 175 | if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise |
| 158 | encoder_value[index]--; | 176 | encoder_value[index]--; |
| 159 | changed = true; | 177 | changed = true; |
| 178 | #ifdef ENCODER_MAP_ENABLE | ||
| 179 | encoder_exec_mapping(index, ENCODER_CLOCKWISE); | ||
| 180 | #else // ENCODER_MAP_ENABLE | ||
| 160 | encoder_update_kb(index, ENCODER_CLOCKWISE); | 181 | encoder_update_kb(index, ENCODER_CLOCKWISE); |
| 182 | #endif // ENCODER_MAP_ENABLE | ||
| 161 | } | 183 | } |
| 162 | encoder_pulses[i] %= resolution; | 184 | encoder_pulses[i] %= resolution; |
| 163 | #ifdef ENCODER_DEFAULT_POS | 185 | #ifdef ENCODER_DEFAULT_POS |
| @@ -197,13 +219,21 @@ void encoder_update_raw(uint8_t *slave_state) { | |||
| 197 | delta--; | 219 | delta--; |
| 198 | encoder_value[index]++; | 220 | encoder_value[index]++; |
| 199 | changed = true; | 221 | changed = true; |
| 222 | # ifdef ENCODER_MAP_ENABLE | ||
| 223 | encoder_exec_mapping(index, ENCODER_COUNTER_CLOCKWISE); | ||
| 224 | # else // ENCODER_MAP_ENABLE | ||
| 200 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); | 225 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); |
| 226 | # endif // ENCODER_MAP_ENABLE | ||
| 201 | } | 227 | } |
| 202 | while (delta < 0) { | 228 | while (delta < 0) { |
| 203 | delta++; | 229 | delta++; |
| 204 | encoder_value[index]--; | 230 | encoder_value[index]--; |
| 205 | changed = true; | 231 | changed = true; |
| 232 | # ifdef ENCODER_MAP_ENABLE | ||
| 233 | encoder_exec_mapping(index, ENCODER_CLOCKWISE); | ||
| 234 | # else // ENCODER_MAP_ENABLE | ||
| 206 | encoder_update_kb(index, ENCODER_CLOCKWISE); | 235 | encoder_update_kb(index, ENCODER_CLOCKWISE); |
| 236 | # endif // ENCODER_MAP_ENABLE | ||
| 207 | } | 237 | } |
| 208 | } | 238 | } |
| 209 | 239 | ||
