refactor
parent
2f2c3d6994
commit
789169a86f
122
src/main.c
122
src/main.c
|
@ -77,6 +77,61 @@ int main(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void main_key_loop() {
|
||||||
|
for (;;) {
|
||||||
|
// swap `kb_is_pressed` and `kb_was_pressed`, then update
|
||||||
|
bool (*temp)[KB_ROWS][KB_COLUMNS] = kb_was_pressed;
|
||||||
|
kb_was_pressed = kb_is_pressed;
|
||||||
|
kb_is_pressed = temp;
|
||||||
|
|
||||||
|
kb_update_matrix(*kb_is_pressed);
|
||||||
|
|
||||||
|
// this loop is responsible to
|
||||||
|
// - "execute" keys when they change state
|
||||||
|
// - keep track of which layers the keys were on when they were pressed
|
||||||
|
// (so they can be released using the function from that layer)
|
||||||
|
//
|
||||||
|
// note
|
||||||
|
// - everything else is the key function's responsibility
|
||||||
|
// - see the keyboard layout file ("keyboard/layout/*.c") for
|
||||||
|
// which key is assigned which function (per layer)
|
||||||
|
// - see "lib/key-functions/public/*.c" for the function definitions
|
||||||
|
for (uint8_t row=0; row<KB_ROWS; row++) {
|
||||||
|
for (uint8_t col=0; col<KB_COLUMNS; col++) {
|
||||||
|
current_is_pressed = (*kb_is_pressed)[row][col];
|
||||||
|
bool was_pressed = (*kb_was_pressed)[row][col];
|
||||||
|
|
||||||
|
if (current_is_pressed != was_pressed) {
|
||||||
|
if (current_is_pressed) {
|
||||||
|
current_layer = layers_top;
|
||||||
|
layers_pressed[row][col] = current_layer;
|
||||||
|
trans_key_pressed = false;
|
||||||
|
} else {
|
||||||
|
current_layer = layers_pressed[row][col];
|
||||||
|
trans_key_pressed = kb_was_transparent[row][col];
|
||||||
|
}
|
||||||
|
|
||||||
|
// set remaining vars, and "execute" key
|
||||||
|
current_row = row;
|
||||||
|
current_col = col;
|
||||||
|
layer_offset = 0;
|
||||||
|
exec_key();
|
||||||
|
kb_was_transparent[row][col] = trans_key_pressed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// send the USB report (even if nothing's changed)
|
||||||
|
usb_keyboard_send();
|
||||||
|
usb_extra_consumer_send();
|
||||||
|
|
||||||
|
// debounce in ms; see keyswitch spec for necessary value
|
||||||
|
_delay_ms(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// layer functions
|
// layer functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -102,11 +157,6 @@ uint8_t _highest_active_layer(uint8_t offset) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the highest active layer
|
|
||||||
uint8_t top_layer() {
|
|
||||||
return layers_top;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return if highest active layer is sticky
|
// return if highest active layer is sticky
|
||||||
StickyState layer_top_sticky() {
|
StickyState layer_top_sticky() {
|
||||||
return layer_sticky(layers_top);
|
return layer_sticky(layers_top);
|
||||||
|
@ -434,11 +484,10 @@ void kbfun_layer_disable() {
|
||||||
*/
|
*/
|
||||||
void kbfun_layer_sticky() {
|
void kbfun_layer_sticky() {
|
||||||
uint8_t layer = _kbfun_get_keycode();
|
uint8_t layer = _kbfun_get_keycode();
|
||||||
uint8_t topLayer = top_layer();
|
|
||||||
StickyState topSticky = layer_top_sticky();
|
StickyState topSticky = layer_top_sticky();
|
||||||
|
|
||||||
if (current_is_pressed) {
|
if (current_is_pressed) {
|
||||||
if (topLayer == layer) {
|
if (layer == layers_top) {
|
||||||
// FIXME
|
// FIXME
|
||||||
/* if (topSticky == StickyOnceUp) { */
|
/* if (topSticky == StickyOnceUp) { */
|
||||||
/* layer_enable(layer, StickyLock); */
|
/* layer_enable(layer, StickyLock); */
|
||||||
|
@ -538,62 +587,3 @@ void kbfun_mediakey_press_release(void) {
|
||||||
uint8_t keycode = _kbfun_get_keycode();
|
uint8_t keycode = _kbfun_get_keycode();
|
||||||
_kbfun_mediakey_press_release(current_is_pressed, keycode);
|
_kbfun_mediakey_press_release(current_is_pressed, keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void main_key_loop() {
|
|
||||||
for (;;) {
|
|
||||||
// swap `kb_is_pressed` and `kb_was_pressed`, then update
|
|
||||||
bool (*temp)[KB_ROWS][KB_COLUMNS] = kb_was_pressed;
|
|
||||||
kb_was_pressed = kb_is_pressed;
|
|
||||||
kb_is_pressed = temp;
|
|
||||||
|
|
||||||
kb_update_matrix(*kb_is_pressed);
|
|
||||||
|
|
||||||
// this loop is responsible to
|
|
||||||
// - "execute" keys when they change state
|
|
||||||
// - keep track of which layers the keys were on when they were pressed
|
|
||||||
// (so they can be released using the function from that layer)
|
|
||||||
//
|
|
||||||
// note
|
|
||||||
// - everything else is the key function's responsibility
|
|
||||||
// - see the keyboard layout file ("keyboard/layout/*.c") for
|
|
||||||
// which key is assigned which function (per layer)
|
|
||||||
// - see "lib/key-functions/public/*.c" for the function definitions
|
|
||||||
for (uint8_t row=0; row<KB_ROWS; row++) {
|
|
||||||
for (uint8_t col=0; col<KB_COLUMNS; col++) {
|
|
||||||
current_is_pressed = (*kb_is_pressed)[row][col];
|
|
||||||
bool was_pressed = (*kb_was_pressed)[row][col];
|
|
||||||
|
|
||||||
if (current_is_pressed != was_pressed) {
|
|
||||||
if (current_is_pressed) {
|
|
||||||
current_layer = top_layer();
|
|
||||||
layers_pressed[row][col] = current_layer;
|
|
||||||
trans_key_pressed = false;
|
|
||||||
} else {
|
|
||||||
current_layer = layers_pressed[row][col];
|
|
||||||
trans_key_pressed = kb_was_transparent[row][col];
|
|
||||||
}
|
|
||||||
|
|
||||||
// set remaining vars, and "execute" key
|
|
||||||
current_row = row;
|
|
||||||
current_col = col;
|
|
||||||
layer_offset = 0;
|
|
||||||
exec_key();
|
|
||||||
kb_was_transparent[row][col] = trans_key_pressed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// send the USB report (even if nothing's changed)
|
|
||||||
usb_keyboard_send();
|
|
||||||
usb_extra_consumer_send();
|
|
||||||
|
|
||||||
// debounce in ms; see keyswitch spec for necessary value
|
|
||||||
_delay_ms(5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
|
||||||
// generated keyboard layout
|
|
||||||
// ---------------------------------------------------------------------------------
|
|
||||||
|
|
|
@ -19,15 +19,14 @@ void _kbfun_press_release(bool press,uint8_t keycode);
|
||||||
uint8_t kb_layout_get(uint8_t layer,uint8_t row,uint8_t column);
|
uint8_t kb_layout_get(uint8_t layer,uint8_t row,uint8_t column);
|
||||||
void_funptr_t kb_layout_release_get(uint8_t layer,uint8_t row,uint8_t column);
|
void_funptr_t kb_layout_release_get(uint8_t layer,uint8_t row,uint8_t column);
|
||||||
void_funptr_t kb_layout_press_get(uint8_t layer,uint8_t row,uint8_t column);
|
void_funptr_t kb_layout_press_get(uint8_t layer,uint8_t row,uint8_t column);
|
||||||
void exec_key(void);
|
|
||||||
uint8_t layer_peek(uint8_t offset);
|
uint8_t layer_peek(uint8_t offset);
|
||||||
void layer_disable_top();
|
void layer_disable_top();
|
||||||
void layer_disable(uint8_t layer);
|
void layer_disable(uint8_t layer);
|
||||||
void layer_enable(uint8_t layer,StickyState sticky);
|
void layer_enable(uint8_t layer,StickyState sticky);
|
||||||
StickyState layer_sticky(uint8_t layer);
|
StickyState layer_sticky(uint8_t layer);
|
||||||
StickyState layer_top_sticky();
|
StickyState layer_top_sticky();
|
||||||
uint8_t top_layer();
|
|
||||||
uint8_t _highest_active_layer(uint8_t offset);
|
uint8_t _highest_active_layer(uint8_t offset);
|
||||||
|
void exec_key(void);
|
||||||
void main_key_loop();
|
void main_key_loop();
|
||||||
void init_layers();
|
void init_layers();
|
||||||
int main(void);
|
int main(void);
|
||||||
|
|
Loading…
Reference in New Issue