Cheapino: encoder abstractions
This commit is contained in:
parent
76b3490f10
commit
a7f3742dc1
@ -4,6 +4,23 @@
|
|||||||
#define COL_SHIFTER ((uint16_t)1)
|
#define COL_SHIFTER ((uint16_t)1)
|
||||||
|
|
||||||
static bool colABpressed = false;
|
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) {
|
void blank_column(matrix_row_t current_matrix[], uint8_t col) {
|
||||||
uint16_t column_index_bitmask = COL_SHIFTER << 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
|
// 7th column means encoder was pressed
|
||||||
if (is_entire_column_held(current_matrix, 7)) {
|
if (is_entire_column_held(current_matrix, 7)) {
|
||||||
|
encoderPressed = true;
|
||||||
blank_column(current_matrix, 7);
|
blank_column(current_matrix, 7);
|
||||||
current_matrix[3] |= COL_SHIFTER;
|
current_matrix[3] |= COL_SHIFTER;
|
||||||
} else {
|
} else {
|
||||||
current_matrix[3] &= ~COL_SHIFTER;
|
current_matrix[3] &= ~COL_SHIFTER;
|
||||||
|
// Only trigger click on release
|
||||||
|
if (encoderPressed) {
|
||||||
|
encoderPressed = false;
|
||||||
|
clicked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now check rotary action:
|
// Now check rotary action:
|
||||||
@ -44,13 +67,13 @@ void fix_encoder_action(matrix_row_t current_matrix[]) {
|
|||||||
} else if (colA) {
|
} else if (colA) {
|
||||||
if (colABpressed) {
|
if (colABpressed) {
|
||||||
colABpressed = false;
|
colABpressed = false;
|
||||||
tap_code(KC_U);
|
turned(true);
|
||||||
}
|
}
|
||||||
blank_column(current_matrix, 9);
|
blank_column(current_matrix, 9);
|
||||||
} else if (colB) {
|
} else if (colB) {
|
||||||
if (colABpressed) {
|
if (colABpressed) {
|
||||||
colABpressed = false;
|
colABpressed = false;
|
||||||
tap_code(KC_D);
|
turned(false);
|
||||||
}
|
}
|
||||||
blank_column(current_matrix, 11);
|
blank_column(current_matrix, 11);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
CAPS_WORD_ENABLE = yes
|
||||||
CUSTOM_MATRIX = lite
|
CUSTOM_MATRIX = lite
|
||||||
SRC += encoder.c
|
SRC += encoder.c
|
||||||
SRC += matrix.c
|
SRC += matrix.c
|
Loading…
x
Reference in New Issue
Block a user