fix: layer indicator management + capslock led indicator
This commit is contained in:
parent
f064a761ee
commit
42eb303d64
3 changed files with 71 additions and 46 deletions
|
|
@ -27,3 +27,5 @@
|
|||
#define RGBLIGHT_EFFECT_TWINKLE
|
||||
|
||||
#define RGBLIGHT_LAYERS
|
||||
#define RGBLIGHT_LAYER_BLINK
|
||||
#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue