Skip to content

Commit

Permalink
Replace timer_read() | 1 pattern with event type
Browse files Browse the repository at this point in the history
this covers all user keymaps that previously relied on the timestamp
mechanism to indicate a valid event.
  • Loading branch information
KarlK90 committed Mar 3, 2023
1 parent dcab33f commit c5d0918
Show file tree
Hide file tree
Showing 41 changed files with 252 additions and 180 deletions.
6 changes: 4 additions & 2 deletions keyboards/atlantis/encoder_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void encoder_action_unregister(void) {
keyevent_t encoder_event = (keyevent_t) {
.key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index],
.pressed = false,
.time = (timer_read() | 1)
.time = timer_read(),
.type = KEY_EVENT
};
encoder_state[index] = 0;
action_exec(encoder_event);
Expand All @@ -40,7 +41,8 @@ void encoder_action_register(uint8_t index, bool clockwise) {
keyevent_t encoder_event = (keyevent_t) {
.key = clockwise ? encoder_cw[index] : encoder_ccw[index],
.pressed = true,
.time = (timer_read() | 1)
.time = timer_read(),
.type = KEY_EVENT
};
encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
action_exec(encoder_event);
Expand Down
16 changes: 9 additions & 7 deletions keyboards/custommk/evo70/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,27 @@ void set_custom_encoder_mode_user(bool custom_mode) {

keyevent_t encoder_ccw = {
.key = (keypos_t){.row = 4, .col = 7},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder_cw = {
.key = (keypos_t){.row = 4, .col = 10},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};


bool encoder_update_user(uint8_t index, bool clockwise) {
if (custom_encoder_mode) {
if (clockwise) {
encoder_cw.pressed = true;
encoder_cw.time = (timer_read() | 1);
encoder_cw.time = timer_read();
action_exec(encoder_cw);
}
else {
encoder_ccw.pressed = true;
encoder_ccw.time = (timer_read() | 1);
encoder_ccw.time = timer_read();
action_exec(encoder_ccw);
}
return false;
Expand All @@ -86,13 +88,13 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
void matrix_scan_user(void) {
if (IS_PRESSED(encoder_ccw)) {
encoder_ccw.pressed = false;
encoder_ccw.time = (timer_read() | 1);
encoder_ccw.time = timer_read();
action_exec(encoder_ccw);
}

if (IS_PRESSED(encoder_cw)) {
encoder_cw.pressed = false;
encoder_cw.time = (timer_read() | 1);
encoder_cw.time = timer_read();
action_exec(encoder_cw);
}
}
}
22 changes: 13 additions & 9 deletions keyboards/custommk/genesis/rev2/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,50 @@ void keyboard_post_init_user(void) {

keyevent_t encoder_left_ccw = {
.key = (keypos_t){.row = 5, .col = 0},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder_left_cw = {
.key = (keypos_t){.row = 5, .col = 1},
.pressed = false
.type = KEY_EVENT
};

keyevent_t encoder_right_ccw = {
.key = (keypos_t){.row = 5, .col = 2},
.pressed = false
.type = KEY_EVENT
};

keyevent_t encoder_right_cw = {
.key = (keypos_t){.row = 5, .col = 3},
.pressed = false
.type = KEY_EVENT
};

void matrix_scan_user(void) {
if (IS_PRESSED(encoder_left_ccw)) {
encoder_left_ccw.pressed = false;
encoder_left_ccw.time = (timer_read() | 1);
encoder_left_ccw.time = timer_read();
action_exec(encoder_left_ccw);
}

if (IS_PRESSED(encoder_left_cw)) {
encoder_left_cw.pressed = false;
encoder_left_cw.time = (timer_read() | 1);
encoder_left_cw.time = timer_read();
action_exec(encoder_left_cw);
}

if (IS_PRESSED(encoder_right_ccw)) {
encoder_right_ccw.pressed = false;
encoder_right_ccw.time = (timer_read() | 1);
encoder_right_ccw.time = timer_read();
action_exec(encoder_right_ccw);
}

if (IS_PRESSED(encoder_right_cw)) {
encoder_right_cw.pressed = false;
encoder_right_cw.time = (timer_read() | 1);
encoder_right_cw.time = timer_read();
action_exec(encoder_right_cw);
}

Expand All @@ -145,21 +149,21 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
if (clockwise) {
encoder_left_cw.pressed = true;
encoder_left_cw.time = (timer_read() | 1);
encoder_left_cw.time = timer_read();
action_exec(encoder_left_cw);
} else {
encoder_left_ccw.pressed = true;
encoder_left_ccw.time = (timer_read() | 1);
encoder_left_ccw.time = timer_read();
action_exec(encoder_left_ccw);
}
} else {
if (clockwise) {
encoder_right_cw.pressed = true;
encoder_right_cw.time = (timer_read() | 1);
encoder_right_cw.time = timer_read();
action_exec(encoder_right_cw);
} else {
encoder_right_ccw.pressed = true;
encoder_right_ccw.time = (timer_read() | 1);
encoder_right_ccw.time = timer_read();
action_exec(encoder_right_ccw);
}
}
Expand Down
28 changes: 16 additions & 12 deletions keyboards/dailycraft/owl8/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,50 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

keyevent_t encoder1_ccw = {
.key = (keypos_t){.row = 0, .col = 12},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder1_cw = {
.key = (keypos_t){.row = 0, .col = 13},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder2_ccw = {
.key = (keypos_t){.row = 0, .col = 14},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder2_cw = {
.key = (keypos_t){.row = 0, .col = 15},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

void matrix_scan_user(void) {
if (IS_PRESSED(encoder1_ccw)) {
encoder1_ccw.pressed = false;
encoder1_ccw.time = (timer_read() | 1);
encoder1_ccw.time = timer_read();
action_exec(encoder1_ccw);
}

if (IS_PRESSED(encoder1_cw)) {
encoder1_cw.pressed = false;
encoder1_cw.time = (timer_read() | 1);
encoder1_cw.time = timer_read();
action_exec(encoder1_cw);
}

if (IS_PRESSED(encoder2_ccw)) {
encoder2_ccw.pressed = false;
encoder2_ccw.time = (timer_read() | 1);
encoder2_ccw.time = timer_read();
action_exec(encoder2_ccw);
}

if (IS_PRESSED(encoder2_cw)) {
encoder2_cw.pressed = false;
encoder2_cw.time = (timer_read() | 1);
encoder2_cw.time = timer_read();
action_exec(encoder2_cw);
}
}
Expand All @@ -100,21 +104,21 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
encoder1_cw.pressed = true;
encoder1_cw.time = (timer_read() | 1);
encoder1_cw.time = timer_read();
action_exec(encoder1_cw);
} else {
encoder1_ccw.pressed = true;
encoder1_ccw.time = (timer_read() | 1);
encoder1_ccw.time = timer_read();
action_exec(encoder1_ccw);
}
} else if (index == 1) {
if (clockwise) {
encoder2_cw.pressed = true;
encoder2_cw.time = (timer_read() | 1);
encoder2_cw.time = timer_read();
action_exec(encoder2_cw);
} else {
encoder2_ccw.pressed = true;
encoder2_ccw.time = (timer_read() | 1);
encoder2_ccw.time = timer_read();
action_exec(encoder2_ccw);
}
}
Expand Down
28 changes: 16 additions & 12 deletions keyboards/dailycraft/stickey4/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,50 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

keyevent_t encoder1_ccw = {
.key = (keypos_t){.row = 0, .col = 4},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder1_cw = {
.key = (keypos_t){.row = 0, .col = 5},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder2_ccw = {
.key = (keypos_t){.row = 0, .col = 6},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

keyevent_t encoder2_cw = {
.key = (keypos_t){.row = 0, .col = 7},
.pressed = false
.pressed = false,
.type = KEY_EVENT
};

void matrix_scan_user(void) {
if (IS_PRESSED(encoder1_ccw)) {
encoder1_ccw.pressed = false;
encoder1_ccw.time = (timer_read() | 1);
encoder1_ccw.time = timer_read();
action_exec(encoder1_ccw);
}

if (IS_PRESSED(encoder1_cw)) {
encoder1_cw.pressed = false;
encoder1_cw.time = (timer_read() | 1);
encoder1_cw.time = timer_read();
action_exec(encoder1_cw);
}

if (IS_PRESSED(encoder2_ccw)) {
encoder2_ccw.pressed = false;
encoder2_ccw.time = (timer_read() | 1);
encoder2_ccw.time = timer_read();
action_exec(encoder2_ccw);
}

if (IS_PRESSED(encoder2_cw)) {
encoder2_cw.pressed = false;
encoder2_cw.time = (timer_read() | 1);
encoder2_cw.time = timer_read();
action_exec(encoder2_cw);
}
}
Expand All @@ -92,21 +96,21 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) { /* First encoder */
if (clockwise) {
encoder1_cw.pressed = true;
encoder1_cw.time = (timer_read() | 1);
encoder1_cw.time = timer_read();
action_exec(encoder1_cw);
} else {
encoder1_ccw.pressed = true;
encoder1_ccw.time = (timer_read() | 1);
encoder1_ccw.time = timer_read();
action_exec(encoder1_ccw);
}
} else if (index == 1) {
if (clockwise) {
encoder2_cw.pressed = true;
encoder2_cw.time = (timer_read() | 1);
encoder2_cw.time = timer_read();
action_exec(encoder2_cw);
} else {
encoder2_ccw.pressed = true;
encoder2_ccw.time = (timer_read() | 1);
encoder2_ccw.time = timer_read();
action_exec(encoder2_ccw);
}
}
Expand Down
Loading

0 comments on commit c5d0918

Please sign in to comment.