Skip to content

Commit

Permalink
[Core] Refactor keyevent_t for 1ms timing resolution (qmk#15847)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlK90 authored Apr 3, 2023
1 parent 2d9140a commit fcf8b80
Show file tree
Hide file tree
Showing 49 changed files with 360 additions and 273 deletions.
2 changes: 1 addition & 1 deletion docs/feature_stenography.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool post_process_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t
This function is called after a key has been processed, but before any decision about whether or not to send a chord. This is where to put hooks for things like, say, live displays of steno chords or keys.
If `IS_PRESSED(record->event)` is false, and `n_pressed_keys` is 0 or 1, the chord will be sent shortly, but has not yet been sent. This relieves you of the need of keeping track of where a packet ends and another begins.
If `record->event.pressed` is false, and `n_pressed_keys` is 0 or 1, the chord will be sent shortly, but has not yet been sent. This relieves you of the need of keeping track of where a packet ends and another begins.
The `chord` argument contains the packet of the current chord as specified by the protocol in use. This is *NOT* simply a list of chorded steno keys of the form `[STN_E, STN_U, STN_BR, STN_GR]`. Refer to the appropriate protocol section of this document to learn more about the format of the packets in your steno protocol/mode of choice.
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/feature_stenography.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; }
bool post_process_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed);
```
この関数はキーが処理された後、ただしコードを送信するかどうかを決める前に呼び出されます。`IS_PRESSED(record->event)` が false で、`pressed` が 0 または 1 の場合は、コードはまもなく送信されますが、まだ送信されてはいません。ここが速記コードあるいはキーのライブ表示などのフックを配置する場所です。
この関数はキーが処理された後、ただしコードを送信するかどうかを決める前に呼び出されます。`record->event.pressed` が false で、`pressed` が 0 または 1 の場合は、コードはまもなく送信されますが、まだ送信されてはいません。ここが速記コードあるいはキーのライブ表示などのフックを配置する場所です。
## キーコードリファレンス :id=keycode-reference
Expand Down
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 fcf8b80

Please sign in to comment.