Caps lock support, base layer RGB override support

This commit is contained in:
Sadek Baroudi 2021-02-23 22:48:40 -08:00
parent 03809ec029
commit 0f3de6550a
6 changed files with 77 additions and 13 deletions

View File

@ -28,6 +28,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
switch (keycode) {
case KC_CAPSLOCK:
if (record->event.pressed) {
if (is_caps_lock_on) {
is_caps_lock_on = false;
} else {
is_caps_lock_on = true;
}
}
break;
case KC_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
if (!record->event.pressed) {
#ifndef MAKE_BOOTLOADER
@ -76,6 +85,30 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
rgblight_enable_noeeprom();
# endif
layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
# if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_ENABLE)
} else {
rgblight_disable_noeeprom();
// TODO: Right now, when disabling rgb_layer_change, it doesn't remember
// the current rgb hsv and mode. It just uses the current color of
// the current layer for this keycode. Tried the code below to force
// it, but it's not working
//rgblight_set_hsv_and_mode(userspace_config.hue, userspace_config.sat, userspace_config.val, userspace_config.mode);
# endif
}
}
#endif // RGBLIGHT_ENABLE
break;
case KC_RGB_BLT: // This enables the base layer as a static color, or allows you to override using RGB
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
if (record->event.pressed) {
userspace_config.rgb_base_layer_override ^= 1;
dprintf("rgblight base layer override change [EEPROM]: %u\n", userspace_config.rgb_base_layer_override);
eeconfig_update_user(userspace_config.raw);
if (userspace_config.rgb_base_layer_override) {
# if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_ENABLE)
rgblight_enable_noeeprom();
# endif
layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better)
# if defined(RGBLIGHT_ENABLE) && defined(RGB_MATRIX_ENABLE)
} else {
rgblight_disable_noeeprom();
@ -104,14 +137,14 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
break;
case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
if (record->event.pressed) {
bool is_eeprom_updated;
bool is_eeprom_updated = false;
# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
// This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
if (userspace_config.rgb_layer_change) {
userspace_config.rgb_layer_change = false;
dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
is_eeprom_updated = true;
}
// // This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
// if (userspace_config.rgb_layer_change) {
// userspace_config.rgb_layer_change = false;
// dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change);
// is_eeprom_updated = true;
// }
# endif
# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
if (userspace_config.rgb_matrix_idle_anim) {
@ -124,6 +157,16 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
eeconfig_update_user(userspace_config.raw);
}
}
if (!record->event.pressed) {
# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
userspace_config.mode = rgblight_get_mode();
userspace_config.hue = rgblight_get_hue();
userspace_config.sat = rgblight_get_sat();
userspace_config.val = rgblight_get_val();
userspace_config.speed = rgblight_get_speed();
eeconfig_update_user(userspace_config.raw);
# endif
}
break;
#endif
case L_GREP:

View File

@ -10,6 +10,7 @@
enum userspace_custom_keycodes {
VRSN = PLACEHOLDER_SAFE_RANGE, // Prints QMK Firmware and board info
KC_RGB_T, // Toggles RGB Layer Indication mode
KC_RGB_BLT, // Toggles RGB Base Layer Override mode
RGB_IDL, // RGB Idling animations
KC_MAKE, // Run keyboard's customized make command
L_GREP,

View File

@ -65,9 +65,8 @@ void matrix_scan_rgb_light(void) {
}
void rgblight_set_hsv_and_mode(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode) {
rgblight_sethsv_noeeprom(hue, sat, val);
// wait_us(175); // Add a slight delay between color and mode to ensure it's processed correctly
rgblight_mode_noeeprom(mode);
rgblight_sethsv_noeeprom(hue, sat, val);
}
layer_state_t layer_state_set_rgb_light(layer_state_t state) {
@ -77,7 +76,13 @@ layer_state_t layer_state_set_rgb_light(layer_state_t state) {
uint8_t mode = RGBLIGHT_MODE_STATIC_LIGHT;
switch (get_highest_layer(state|default_layer_state)) {
case _COLEMAK:
rgblight_set_hsv_and_mode(HSV_BLUE, mode);
if (is_caps_lock_on) {
rgblight_set_hsv_and_mode(HSV_RED, mode);
} else if (userspace_config.rgb_base_layer_override) {
rgblight_set_hsv_and_mode(userspace_config.hue, userspace_config.sat, userspace_config.val, userspace_config.mode);
} else {
rgblight_set_hsv_and_mode(HSV_BLUE, mode);
}
break;
case _QWERTY:
rgblight_set_hsv_and_mode(10, 10, 255, mode); // white

View File

@ -1,6 +1,7 @@
#include "sadekbaroudi.h"
userspace_config_t userspace_config;
bool is_caps_lock_on;
__attribute__((weak)) void keyboard_pre_init_keymap(void) {}
@ -23,6 +24,7 @@ void matrix_init_user(void) {
__attribute__((weak)) void keyboard_post_init_keymap(void) {}
void keyboard_post_init_user(void) {
is_caps_lock_on = false;
#if defined(RGBLIGHT_ENABLE)
keyboard_post_init_rgb_light();
#endif
@ -115,7 +117,13 @@ __attribute__((weak)) void eeconfig_init_keymap(void) {}
void eeconfig_init_user(void) {
userspace_config.raw = 0;
userspace_config.rgb_base_layer_override = false;
userspace_config.rgb_layer_change = true;
userspace_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
userspace_config.hue = 169; // BLUE
userspace_config.sat = 255;
userspace_config.val = 255;
userspace_config.speed = 1;
eeconfig_update_user(userspace_config.raw);
eeconfig_init_keymap();
keyboard_init();

View File

@ -55,10 +55,17 @@ bool hasAllBitsInMask(uint8_t value, uint8_t mask);
typedef union {
uint32_t raw;
struct {
bool rgb_layer_change :1;
bool rgb_matrix_idle_anim :1;
bool rgb_layer_change :1;
bool rgb_base_layer_override :1;
bool rgb_matrix_idle_anim :1;
uint8_t mode; //:default 1; RGBLIGHT_MODE_STATIC_LIGHT;
uint8_t hue; //:0-255;
uint8_t sat; //:0-255;
uint8_t val; //:0-255;
uint8_t speed; //:default 1;
};
} userspace_config_t;
// clang-format on
extern userspace_config_t userspace_config;
extern bool is_caps_lock_on;

View File

@ -109,7 +109,7 @@ NOTE: These are all the same length. If you do a search/replace
#define ________________FUNCTION_3_________________ KC_VOLD, KC_F1, KC_F2, KC_F3, KC_F12
#define ___________________RGB_1___________________ RGB_TOG, RGB_MODE_REVERSE, RGB_MODE_FORWARD, _______, _______
#define ___________________RGB_2___________________ RGB_MODE_PLAIN, RGB_HUI, RGB_SAI, RGB_VAI, _______
#define ___________________RGB_2___________________ KC_RGB_BLT, RGB_HUI, RGB_SAI, RGB_VAI, _______
#define ___________________RGB_3___________________ KC_RGB_T, RGB_HUD, RGB_SAD, RGB_VAD, _______
#define __________________MOUSE_1__________________ _______, KC_MS_WH_UP, KC_MS_UP, KC_MS_WH_DOWN, _______