Cheapino: encoder abstractions

This commit is contained in:
Thomas Haukland 2023-03-25 22:40:34 +01:00
parent 76b3490f10
commit a7f3742dc1
2 changed files with 26 additions and 2 deletions

View File

@ -4,6 +4,23 @@
#define COL_SHIFTER ((uint16_t)1)
static bool colABpressed = false;
static bool encoderPressed = false;
void clicked(void) {
tap_code(KC_MUTE);
}
void turned(bool clockwise) {
if (IS_LAYER_ON(6)) {
tap_code(LGUI(clockwise ? KC_DOWN : KC_UP));
} else if (IS_LAYER_ON(3)) {
tap_code(clockwise ? KC_TAB : LSFT(KC_TAB));
} else if (IS_LAYER_ON(5)) {
tap_code(clockwise ? KC_MS_WH_DOWN : KC_MS_WH_UP);
} else {
tap_code(clockwise ? KC_VOLU : KC_VOLD);
}
}
void blank_column(matrix_row_t current_matrix[], uint8_t col) {
uint16_t column_index_bitmask = COL_SHIFTER << col;
@ -27,10 +44,16 @@ void fix_encoder_action(matrix_row_t current_matrix[]) {
// 7th column means encoder was pressed
if (is_entire_column_held(current_matrix, 7)) {
encoderPressed = true;
blank_column(current_matrix, 7);
current_matrix[3] |= COL_SHIFTER;
} else {
current_matrix[3] &= ~COL_SHIFTER;
// Only trigger click on release
if (encoderPressed) {
encoderPressed = false;
clicked();
}
}
// Now check rotary action:
@ -44,13 +67,13 @@ void fix_encoder_action(matrix_row_t current_matrix[]) {
} else if (colA) {
if (colABpressed) {
colABpressed = false;
tap_code(KC_U);
turned(true);
}
blank_column(current_matrix, 9);
} else if (colB) {
if (colABpressed) {
colABpressed = false;
tap_code(KC_D);
turned(false);
}
blank_column(current_matrix, 11);
}

View File

@ -1,3 +1,4 @@
CAPS_WORD_ENABLE = yes
CUSTOM_MATRIX = lite
SRC += encoder.c
SRC += matrix.c