diff options
Diffstat (limited to 'quantum/encoder.c')
| -rw-r--r-- | quantum/encoder.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/quantum/encoder.c b/quantum/encoder.c index 7ca31afed..2ed64c1e3 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c | |||
| @@ -94,8 +94,9 @@ void encoder_init(void) { | |||
| 94 | #endif | 94 | #endif |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | static void encoder_update(int8_t index, uint8_t state) { | 97 | static bool encoder_update(int8_t index, uint8_t state) { |
| 98 | uint8_t i = index; | 98 | bool changed = false; |
| 99 | uint8_t i = index; | ||
| 99 | 100 | ||
| 100 | #ifdef ENCODER_RESOLUTIONS | 101 | #ifdef ENCODER_RESOLUTIONS |
| 101 | int8_t resolution = encoder_resolutions[i]; | 102 | int8_t resolution = encoder_resolutions[i]; |
| @@ -109,40 +110,53 @@ static void encoder_update(int8_t index, uint8_t state) { | |||
| 109 | encoder_pulses[i] += encoder_LUT[state & 0xF]; | 110 | encoder_pulses[i] += encoder_LUT[state & 0xF]; |
| 110 | if (encoder_pulses[i] >= resolution) { | 111 | if (encoder_pulses[i] >= resolution) { |
| 111 | encoder_value[index]++; | 112 | encoder_value[index]++; |
| 113 | changed = true; | ||
| 112 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); | 114 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); |
| 113 | } | 115 | } |
| 114 | if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise | 116 | if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise |
| 115 | encoder_value[index]--; | 117 | encoder_value[index]--; |
| 118 | changed = true; | ||
| 116 | encoder_update_kb(index, ENCODER_CLOCKWISE); | 119 | encoder_update_kb(index, ENCODER_CLOCKWISE); |
| 117 | } | 120 | } |
| 118 | encoder_pulses[i] %= resolution; | 121 | encoder_pulses[i] %= resolution; |
| 122 | return changed; | ||
| 119 | } | 123 | } |
| 120 | 124 | ||
| 121 | void encoder_read(void) { | 125 | bool encoder_read(void) { |
| 126 | bool changed = false; | ||
| 122 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { | 127 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { |
| 123 | encoder_state[i] <<= 2; | 128 | encoder_state[i] <<= 2; |
| 124 | encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); | 129 | encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); |
| 125 | encoder_update(i, encoder_state[i]); | 130 | changed |= encoder_update(i, encoder_state[i]); |
| 126 | } | 131 | } |
| 132 | return changed; | ||
| 127 | } | 133 | } |
| 128 | 134 | ||
| 129 | #ifdef SPLIT_KEYBOARD | 135 | #ifdef SPLIT_KEYBOARD |
| 136 | void last_encoder_activity_trigger(void); | ||
| 137 | |||
| 130 | void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); } | 138 | void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); } |
| 131 | 139 | ||
| 132 | void encoder_update_raw(uint8_t* slave_state) { | 140 | void encoder_update_raw(uint8_t* slave_state) { |
| 141 | bool changed = false; | ||
| 133 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { | 142 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { |
| 134 | uint8_t index = i + thatHand; | 143 | uint8_t index = i + thatHand; |
| 135 | int8_t delta = slave_state[i] - encoder_value[index]; | 144 | int8_t delta = slave_state[i] - encoder_value[index]; |
| 136 | while (delta > 0) { | 145 | while (delta > 0) { |
| 137 | delta--; | 146 | delta--; |
| 138 | encoder_value[index]++; | 147 | encoder_value[index]++; |
| 148 | changed = true; | ||
| 139 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); | 149 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); |
| 140 | } | 150 | } |
| 141 | while (delta < 0) { | 151 | while (delta < 0) { |
| 142 | delta++; | 152 | delta++; |
| 143 | encoder_value[index]--; | 153 | encoder_value[index]--; |
| 154 | changed = true; | ||
| 144 | encoder_update_kb(index, ENCODER_CLOCKWISE); | 155 | encoder_update_kb(index, ENCODER_CLOCKWISE); |
| 145 | } | 156 | } |
| 146 | } | 157 | } |
| 158 | |||
| 159 | // Update the last encoder input time -- handled external to encoder_read() when we're running a split | ||
| 160 | if (changed) last_encoder_activity_trigger(); | ||
| 147 | } | 161 | } |
| 148 | #endif | 162 | #endif |
