From 42eb303d6430f0e3858f0a367926256c139bc771 Mon Sep 17 00:00:00 2001 From: H3lli0n Date: Sun, 1 Dec 2024 08:54:36 +0100 Subject: [PATCH] fix: layer indicator management + capslock led indicator --- keyboards/hlb/poorkoi/keymaps/vial/config.h | 2 + keyboards/hlb/poorkoi/poorkoi.c | 114 ++++++++++++-------- keyboards/hlb/poorkoi/poorkoi.h | 1 + 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/keyboards/hlb/poorkoi/keymaps/vial/config.h b/keyboards/hlb/poorkoi/keymaps/vial/config.h index 63eac782a4..0438009f45 100644 --- a/keyboards/hlb/poorkoi/keymaps/vial/config.h +++ b/keyboards/hlb/poorkoi/keymaps/vial/config.h @@ -27,3 +27,5 @@ #define RGBLIGHT_EFFECT_TWINKLE #define RGBLIGHT_LAYERS +#define RGBLIGHT_LAYER_BLINK +#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF diff --git a/keyboards/hlb/poorkoi/poorkoi.c b/keyboards/hlb/poorkoi/poorkoi.c index cdb789813e..3fb6807d9c 100644 --- a/keyboards/hlb/poorkoi/poorkoi.c +++ b/keyboards/hlb/poorkoi/poorkoi.c @@ -26,6 +26,49 @@ typedef union { /* User preference */ user_config_t user_config; +/* Feature toggle blink duration */ +const uint16_t rgbBlinkDuration = 300; + +/* RGB Layers definition*/ +const rgblight_segment_t PROGMEM my_base_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, HSV_OFF} +); +const rgblight_segment_t PROGMEM my_fn_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, LAYER_FN_COLOR} +); +const rgblight_segment_t PROGMEM my_media_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, LAYER_MEDIA_COLOR} +); +const rgblight_segment_t PROGMEM my_gaming_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, LAYER_GAMING_COLOR} +); +const rgblight_segment_t PROGMEM my_mac_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, LAYER_MAC_COLOR} +); +const rgblight_segment_t PROGMEM my_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, CAPS_LOCK_COLOR} +); +const rgblight_segment_t PROGMEM my_indicator_on_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, LAYER_INDIC_COLOR}, + {9, 5, LAYER_INDIC_COLOR} +); +const rgblight_segment_t PROGMEM my_indicator_off_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {16, 1, LAYER_INDIC_COLOR}, + {2, 5, LAYER_INDIC_COLOR} +); + +const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST( + my_base_layer, + my_fn_layer, + my_media_layer, + my_gaming_layer, + my_mac_layer, + my_capslock_layer, + my_indicator_on_layer, + my_indicator_off_layer +); + + void eeconfig_init_user(void) { // EEPROM is getting reset! user_config.raw = 0; user_config.rgb_layer_change = false; // We want this enabled by default @@ -38,65 +81,38 @@ void eeconfig_init_user(void) { // EEPROM is getting reset! } void keyboard_pre_init_kb(void) { - rgblight_set_effect_range(0, 16); + rgblight_set_effect_range(0, RGBLIGHT_LED_COUNT - 1); keyboard_pre_init_user(); } void keyboard_post_init_user(void) { - // Read the user config from EEPROM - user_config.raw = eeconfig_read_user(); + // Enable the LED layers + rgblight_layers = my_rgb_layers; - // Set default layer, if enabled - if (user_config.rgb_layer_change) { - rgblight_enable_noeeprom(); - rgblight_sethsv_at(HSV_OFF, 16); - } + // Read the user config from EEPROM + user_config.raw = eeconfig_read_user(); } /* Updating LED located under capslock */ bool led_update_kb(led_t led_state) { - bool res = led_update_user(led_state); + rgblight_set_layer_state(5, host_keyboard_led_state().caps_lock); + return true; +} - // Dealing with capslock - if (CAPS_LOCK_ENABLE && res) { - if(led_state.caps_lock) { - rgblight_sethsv_at(CAPS_LOCK_COLOR, 16); - } - // Color of activated layer - else{ - layer_state_set(layer_state); - } - } - - return res; +layer_state_t default_layer_state_set_user(layer_state_t state) { + rgblight_set_layer_state(_BASE, layer_state_cmp(state, _BASE)); + return state; } /* Use capslock led for layer indicator */ layer_state_t layer_state_set_user(layer_state_t state) { - switch (get_highest_layer(state)) { - case _BASE: - if(host_keyboard_led_state().caps_lock) { - rgblight_sethsv_at(CAPS_LOCK_COLOR, 16); - } - else{ - if (user_config.rgb_layer_change) { rgblight_sethsv_at(HSV_OFF, 16);} - } - break; - case _FN: - if (user_config.rgb_layer_change) { rgblight_sethsv_at(LAYER_FN_COLOR, 16); } - break; - case _MEDIA: - if (user_config.rgb_layer_change) { rgblight_sethsv_at(LAYER_MEDIA_COLOR, 16); } - break; - case _GAME: - if (user_config.rgb_layer_change) { rgblight_sethsv_at(LAYER_GAMING_COLOR, 16); } - break; - case _MAC: - if (user_config.rgb_layer_change) { rgblight_sethsv_at(LAYER_MAC_COLOR, 16); } - break; - default: // for any other layers, or the default layer - rgblight_sethsv_at(HSV_OFF, 16); - break; + rgblight_set_layer_state(_BASE, layer_state_cmp(state, _BASE)); + + if(user_config.rgb_layer_change){ + rgblight_set_layer_state(_FN, layer_state_cmp(state, _FN)); + rgblight_set_layer_state(_MEDIA, layer_state_cmp(state, _MEDIA)); + rgblight_set_layer_state(_GAME, layer_state_cmp(state, _GAME)); + rgblight_set_layer_state(_MAC, layer_state_cmp(state, _MAC)); } return state; @@ -109,11 +125,17 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { user_config.rgb_layer_change ^= 1; // Toggles the status eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM + if (user_config.rgb_layer_change) { // if layer state indication is enabled, - layer_state_set(layer_state); // then immediately update the layer color + rgblight_blink_layer(6, rgbBlinkDuration); + }else{ + rgblight_blink_layer(7, rgbBlinkDuration); } + + layer_state_set(layer_state); // then immediately update the layer color } return false; // Skip all further processing of this key + default: return true; // Process all other keycodes normally } diff --git a/keyboards/hlb/poorkoi/poorkoi.h b/keyboards/hlb/poorkoi/poorkoi.h index 9bef3065fd..b210b95f39 100644 --- a/keyboards/hlb/poorkoi/poorkoi.h +++ b/keyboards/hlb/poorkoi/poorkoi.h @@ -25,6 +25,7 @@ along with this program. If not, see . #define LAYER_MEDIA_COLOR HSV_ORANGE #define LAYER_GAMING_COLOR HSV_CYAN #define LAYER_MAC_COLOR HSV_RED +#define LAYER_INDIC_COLOR HSV_WHITE enum layers { _BASE = 0,