From 0d85a568e569fdbd8df5dd03175d15ef052974f6 Mon Sep 17 00:00:00 2001 From: heuman-a Date: Sat, 6 Jul 2024 22:54:30 +0200 Subject: [PATCH 1/3] Fix Code to align QMK Coding Guidelines for keyboard_post_init_user() --- keyboards/framework/framework.c | 2 -- .../framework/macropad/keymaps/default/keymap.c | 15 +++++++++++++++ keyboards/framework/macropad/macropad.c | 11 +---------- keyboards/framework/macropad/macropad.h | 6 ------ .../framework/numpad/keymaps/default/keymap.c | 14 ++++++++++++++ keyboards/framework/numpad/numpad.c | 9 --------- keyboards/framework/numpad/numpad.h | 4 ---- 7 files changed, 30 insertions(+), 31 deletions(-) diff --git a/keyboards/framework/framework.c b/keyboards/framework/framework.c index 1749229ceb6..8f14cb8eb3e 100644 --- a/keyboards/framework/framework.c +++ b/keyboards/framework/framework.c @@ -6,8 +6,6 @@ #include "os_detection.h" void keyboard_post_init_kb(void) { - keyboard_post_init_user(); - // Enable debug output debug_enable = true; debug_matrix = true; diff --git a/keyboards/framework/macropad/keymaps/default/keymap.c b/keyboards/framework/macropad/keymaps/default/keymap.c index ecef137f0ef..1b1258c39d0 100644 --- a/keyboards/framework/macropad/keymaps/default/keymap.c +++ b/keyboards/framework/macropad/keymaps/default/keymap.c @@ -4,6 +4,12 @@ #include QMK_KEYBOARD_H #include "factory.h" +enum _layers { + _NUMLOCK, + _FN, + _FACTORY, +}; + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* * ┌────┬────┬────┬────┐ @@ -102,3 +108,12 @@ void enable_factory_mode(bool enable) { else layer_off(_FACTORY); } + +void keyboard_post_init_user(void) { + // Sync initial numlock state from the host + if (host_keyboard_led_state().num_lock) { + layer_on(_NUMLOCK); + } else { + layer_off(_FN); + } +} diff --git a/keyboards/framework/macropad/macropad.c b/keyboards/framework/macropad/macropad.c index 7fb11cdc723..1c4c86cd5a2 100644 --- a/keyboards/framework/macropad/macropad.c +++ b/keyboards/framework/macropad/macropad.c @@ -80,13 +80,4 @@ led_config_t g_led_config = { { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 } }; -#endif - -void keyboard_post_init_user(void) { - // Sync initial numlock state from the host - if (host_keyboard_led_state().num_lock) { - layer_on(_NUMLOCK); - } else { - layer_off(_FN); - } -} +#endif \ No newline at end of file diff --git a/keyboards/framework/macropad/macropad.h b/keyboards/framework/macropad/macropad.h index 78b831e81eb..b2af646e1e5 100644 --- a/keyboards/framework/macropad/macropad.h +++ b/keyboards/framework/macropad/macropad.h @@ -15,9 +15,3 @@ { K108, H1, H2, KC_NO, H4, K107, K109, K110 }, \ { KC_NO, KC_NO, KC_NO, KC_NO, H3, KC_NO, KC_NO, KC_NO }, \ } - -enum _layers { - _NUMLOCK, - _FN, - _FACTORY, -}; diff --git a/keyboards/framework/numpad/keymaps/default/keymap.c b/keyboards/framework/numpad/keymaps/default/keymap.c index e663e76a382..d684755b3f6 100644 --- a/keyboards/framework/numpad/keymaps/default/keymap.c +++ b/keyboards/framework/numpad/keymaps/default/keymap.c @@ -3,6 +3,11 @@ #include QMK_KEYBOARD_H +enum _layers { + _NUMLOCK, + _FN +}; + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* * ┌────┬────┬────┬────┐ @@ -69,3 +74,12 @@ bool led_update_user(led_t led_state) { } return true; } + +void keyboard_post_init_user(void) { + // Sync initial numlock state from the host + if (host_keyboard_led_state().num_lock) { + layer_on(_NUMLOCK); + } else { + layer_off(_FN); + } +} diff --git a/keyboards/framework/numpad/numpad.c b/keyboards/framework/numpad/numpad.c index 2838df53915..1a0389fe5be 100644 --- a/keyboards/framework/numpad/numpad.c +++ b/keyboards/framework/numpad/numpad.c @@ -3,12 +3,3 @@ #include "quantum.h" #include "numpad.h" - -void keyboard_post_init_user(void) { - // Sync initial numlock state from the host - if (host_keyboard_led_state().num_lock) { - layer_on(_NUMLOCK); - } else { - layer_off(_FN); - } -} diff --git a/keyboards/framework/numpad/numpad.h b/keyboards/framework/numpad/numpad.h index aec24bf957d..ec80e7ee2db 100644 --- a/keyboards/framework/numpad/numpad.h +++ b/keyboards/framework/numpad/numpad.h @@ -17,7 +17,3 @@ { KC_NO, KC_NO, KC_NO, KC_NO, H3, KC_NO, KC_NO, KC_NO }, \ } -enum _layers { - _NUMLOCK, - _FN -}; From 03b979456f7474c725aa06b38a5eaaf76aabfa32 Mon Sep 17 00:00:00 2001 From: heuman-a Date: Fri, 23 Aug 2024 22:53:23 +0200 Subject: [PATCH 2/3] ADD store last numlock value to avoid triggering one-time function "layer_state_set_user" endlessly --- .../framework/macropad/keymaps/default/keymap.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/keyboards/framework/macropad/keymaps/default/keymap.c b/keyboards/framework/macropad/keymaps/default/keymap.c index 1b1258c39d0..9aecdcb395c 100644 --- a/keyboards/framework/macropad/keymaps/default/keymap.c +++ b/keyboards/framework/macropad/keymaps/default/keymap.c @@ -94,12 +94,19 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { bool led_update_user(led_t led_state) { // Change layer if numlock state changes, either triggered by OS or // by numlock key on this keyboard + static bool last_value = false; if (led_state.num_lock) { - layer_off(_FN); + if(last_value != led_state.num_lock) { + layer_off(_FN); + last_value = led_state.num_lock; + } } else { - layer_on(_FN); + if(last_value != led_state.num_lock) { + layer_on(_FN); + last_value = led_state.num_lock; + } } - return true; + return true; } void enable_factory_mode(bool enable) { From df3f1af16eb5ed6858c5711d19eed23788ca098a Mon Sep 17 00:00:00 2001 From: heuman-a Date: Sat, 24 Aug 2024 19:41:55 +0200 Subject: [PATCH 3/3] UPDATE Increase performance of function --- keyboards/framework/macropad/keymaps/default/keymap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/keyboards/framework/macropad/keymaps/default/keymap.c b/keyboards/framework/macropad/keymaps/default/keymap.c index 9aecdcb395c..14974737d6f 100644 --- a/keyboards/framework/macropad/keymaps/default/keymap.c +++ b/keyboards/framework/macropad/keymaps/default/keymap.c @@ -95,15 +95,12 @@ bool led_update_user(led_t led_state) { // Change layer if numlock state changes, either triggered by OS or // by numlock key on this keyboard static bool last_value = false; - if (led_state.num_lock) { - if(last_value != led_state.num_lock) { + if(last_value != led_state.num_lock) { + last_value = led_state.num_lock; + if (led_state.num_lock) { layer_off(_FN); - last_value = led_state.num_lock; - } - } else { - if(last_value != led_state.num_lock) { + } else { layer_on(_FN); - last_value = led_state.num_lock; } } return true;