mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-04-04 12:55:44 +00:00
working example
This commit is contained in:
parent
e890fa0e76
commit
751ad39ad4
@ -225,6 +225,11 @@ uint8_t source_layers_cache[((MATRIX_ROWS * MATRIX_COLS) + (CHAR_BIT)-1) / (CHAR
|
||||
uint8_t encoder_source_layers_cache[(NUM_ENCODERS + (CHAR_BIT)-1) / (CHAR_BIT)][MAX_LAYER_BITS] = {{0}};
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
|
||||
uint16_t keycode_map[((MATRIX_ROWS * MATRIX_COLS) + (CHAR_BIT)-1) / (CHAR_BIT)][16] = {{KC_NO}};
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
uint16_t encoder_keycode_map[(NUM_ENCODERS + (CHAR_BIT)-1) / (CHAR_BIT)][16] = {{KC_NO}};
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
|
||||
/** \brief update source layers cache impl
|
||||
*
|
||||
* Updates the supplied cache when changing layers
|
||||
@ -237,6 +242,14 @@ void update_source_layers_cache_impl(uint8_t layer, uint16_t entry_number, uint8
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief update encoder keycode map
|
||||
*
|
||||
* Updates map of keycodes when pressing a key down
|
||||
*/
|
||||
void update_keycode_map_impl(uint16_t entry_number, uint16_t keycode, uint16_t cache[][16]) {
|
||||
cache[entry_number / 16][entry_number % 16] = keycode;
|
||||
}
|
||||
|
||||
/** \brief read source layers cache
|
||||
*
|
||||
* reads the cached keys stored when the layer was changed
|
||||
@ -253,6 +266,14 @@ uint8_t read_source_layers_cache_impl(uint16_t entry_number, uint8_t cache[][MAX
|
||||
return layer;
|
||||
}
|
||||
|
||||
/** \brief read keycode map
|
||||
*
|
||||
* reads map of keycodes when unpressing a key
|
||||
*/
|
||||
uint16_t read_keycode_map_impl(uint16_t entry_number, uint16_t cache[][16]) {
|
||||
return cache[entry_number / 16][entry_number % 16];
|
||||
}
|
||||
|
||||
/** \brief update encoder source layers cache
|
||||
*
|
||||
* Updates the cached encoders when changing layers
|
||||
@ -270,6 +291,41 @@ void update_source_layers_cache(keypos_t key, uint8_t layer) {
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
}
|
||||
|
||||
/** \brief update encoder keycode map
|
||||
*
|
||||
* Updates map of keycodes when pressing a key down
|
||||
*/
|
||||
void update_keycode_map(keypos_t key, uint16_t keycode) {
|
||||
if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
|
||||
const uint16_t entry_number = (uint16_t)(key.row * MATRIX_COLS) + key.col;
|
||||
update_keycode_map_impl(entry_number, keycode, keycode_map);
|
||||
}
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
else if (key.row == KEYLOC_ENCODER_CW || key.row == KEYLOC_ENCODER_CCW) {
|
||||
const uint16_t entry_number = key.col;
|
||||
update_keycode_map_impl(entry_number, keycode, encoder_keycode_map);
|
||||
}
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
}
|
||||
|
||||
/** \brief read keycode map
|
||||
*
|
||||
* reads map of keycodes when unpressing a key
|
||||
*/
|
||||
uint16_t read_keycode_map(keypos_t key) {
|
||||
if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
|
||||
const uint16_t entry_number = (uint16_t)(key.row * MATRIX_COLS) + key.col;
|
||||
return read_keycode_map_impl(entry_number, keycode_map);
|
||||
}
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
else if (key.row == KEYLOC_ENCODER_CW || key.row == KEYLOC_ENCODER_CCW) {
|
||||
const uint16_t entry_number = key.col;
|
||||
return read_keycode_map_impl(entry_number, encoder_keycode_map);
|
||||
}
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
return KC_NO;
|
||||
}
|
||||
|
||||
/** \brief read source layers cache
|
||||
*
|
||||
* reads the cached keys stored when the layer was changed
|
||||
|
@ -159,7 +159,9 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_
|
||||
#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
|
||||
|
||||
void update_source_layers_cache(keypos_t key, uint8_t layer);
|
||||
void update_keycode_map(keypos_t key, uint16_t keycode);
|
||||
uint8_t read_source_layers_cache(keypos_t key);
|
||||
uint16_t read_keycode_map(keypos_t key);
|
||||
#endif
|
||||
action_t store_or_get_action(bool pressed, keypos_t key);
|
||||
|
||||
|
@ -231,14 +231,19 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
|
||||
/* TODO: Use store_or_get_action() or a similar function. */
|
||||
if (!disable_action_cache) {
|
||||
uint8_t layer;
|
||||
uint16_t keycode;
|
||||
|
||||
if (event.pressed && update_layer_cache) {
|
||||
layer = layer_switch_get_layer(event.key);
|
||||
update_source_layers_cache(event.key, layer);
|
||||
keycode = keymap_key_to_keycode(layer, event.key);
|
||||
update_keycode_map(event.key, keycode);
|
||||
} else {
|
||||
layer = read_source_layers_cache(event.key);
|
||||
keycode = read_keycode_map(event.key);
|
||||
}
|
||||
return keymap_key_to_keycode(layer, event.key);
|
||||
return keycode;
|
||||
// return keymap_key_to_keycode(layer, event.key);
|
||||
} else
|
||||
#endif
|
||||
return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
|
||||
|
Loading…
Reference in New Issue
Block a user