mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-22 19:39:27 +00:00
Updated split encoders so indexes are based on left hand encoders first (#6382)
* Updated encoder.c so that split encoders are indexed based on left hand encoders first. This ensures when swapping master sides that code logic based on encoder index doesn't change. PR Review fixes * Removed extra define
This commit is contained in:
parent
e5aa28455e
commit
46c49ae4e6
@ -40,8 +40,10 @@ static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1,
|
|||||||
static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
|
static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
|
||||||
|
|
||||||
#ifdef SPLIT_KEYBOARD
|
#ifdef SPLIT_KEYBOARD
|
||||||
// slave half encoders come over as second set of encoders
|
// right half encoders come over as second set of encoders
|
||||||
static int8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0};
|
static int8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0};
|
||||||
|
// row offsets for each hand
|
||||||
|
static uint8_t thisHand, thatHand;
|
||||||
#else
|
#else
|
||||||
static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0};
|
static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0};
|
||||||
#endif
|
#endif
|
||||||
@ -68,20 +70,33 @@ void encoder_init(void) {
|
|||||||
|
|
||||||
encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
|
encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SPLIT_KEYBOARD
|
||||||
|
thisHand = isLeftHand ? 0 : NUMBER_OF_ENCODERS;
|
||||||
|
thatHand = NUMBER_OF_ENCODERS - thisHand;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void encoder_update(int8_t index, uint8_t state) {
|
||||||
|
encoder_value[index] += encoder_LUT[state & 0xF];
|
||||||
|
if (encoder_value[index] >= ENCODER_RESOLUTION) {
|
||||||
|
encoder_update_kb(index, false);
|
||||||
|
}
|
||||||
|
if (encoder_value[index] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
|
||||||
|
encoder_update_kb(index, true);
|
||||||
|
}
|
||||||
|
encoder_value[index] %= ENCODER_RESOLUTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
void encoder_read(void) {
|
void encoder_read(void) {
|
||||||
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
|
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
|
||||||
encoder_state[i] <<= 2;
|
encoder_state[i] <<= 2;
|
||||||
encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
|
encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
|
||||||
encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF];
|
#if SPLIT_KEYBOARD
|
||||||
if (encoder_value[i] >= ENCODER_RESOLUTION) {
|
encoder_update(i + thisHand, encoder_state[i]);
|
||||||
encoder_update_kb(i, false);
|
#else
|
||||||
}
|
encoder_update(i, encoder_state[i]);
|
||||||
if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
|
#endif
|
||||||
encoder_update_kb(i, true);
|
|
||||||
}
|
|
||||||
encoder_value[i] %= ENCODER_RESOLUTION;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,14 +105,7 @@ void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, encoder_state
|
|||||||
|
|
||||||
void encoder_update_raw(uint8_t* slave_state) {
|
void encoder_update_raw(uint8_t* slave_state) {
|
||||||
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
|
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
|
||||||
encoder_value[NUMBER_OF_ENCODERS + i] += encoder_LUT[slave_state[i] & 0xF];
|
encoder_update(i + thatHand, slave_state[i]);
|
||||||
if (encoder_value[NUMBER_OF_ENCODERS + i] >= ENCODER_RESOLUTION) {
|
|
||||||
encoder_update_kb(NUMBER_OF_ENCODERS + i, false);
|
|
||||||
}
|
|
||||||
if (encoder_value[NUMBER_OF_ENCODERS + i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
|
|
||||||
encoder_update_kb(NUMBER_OF_ENCODERS + i, true);
|
|
||||||
}
|
|
||||||
encoder_value[NUMBER_OF_ENCODERS + i] %= ENCODER_RESOLUTION;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user