Colorize layers differently so keys that respond to mods are different colors when mods are active

This commit is contained in:
KemoNine 2020-09-14 17:26:13 -04:00
parent 9df98ed3f0
commit d4f18ebbd8

View file

@ -1,5 +1,11 @@
#include "debug.h"
#include "action_layer.h"
#include "version.h"
#include QMK_KEYBOARD_H
#define CAPS_LED 30
enum alt_keycodes {
U_T_AUTO = SAFE_RANGE, //USB Extra Port Toggle Auto Detect / Always Active
U_T_AGCR, //USB Toggle Automatic GCR control
@ -11,6 +17,7 @@ enum alt_keycodes {
};
keymap_config_t keymap_config;
rgb_config_t rgb_matrix_config;
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT_65_ansi_blocker(KC_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_HOME,
@ -25,8 +32,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_NO, KC_TRNS, KC_VOLD, RGB_VAD, KC_VOLU)
};
const uint8_t PROGMEM layercolors[][2] = {
[0] = {10,255}
};
const uint8_t PROGMEM ledcolors[][DRIVER_LED_TOTAL][3] = {
[1] = {
{128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255}, {128, 255, 255},
{128, 255, 255},{128, 255, 255}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {128, 255, 255}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {128, 255, 255},
{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {128, 255, 255},
{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {128, 255, 255}, {0, 0, 0}, {128, 255, 255}, {128, 255, 255},
{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},{128, 255, 255}, {128, 255, 255}, {128, 255, 255}
}
};
// Runs just one time when the keyboard initializes.
void matrix_init_user(void) {
rgb_matrix_config.raw = pgm_read_dword(EECONFIG_RGB_MATRIX);
rgb_matrix_enable();
rgb_matrix_sethsv(10, 255, 95);
rgb_matrix_mode(RGB_MATRIX_SOLID_COLOR);
@ -36,6 +59,46 @@ void matrix_init_user(void) {
void matrix_scan_user(void) {
};
void set_leds_color( int layer) {
for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
uint8_t val = pgm_read_byte(&ledcolors[layer][i][2]);
// if the brightness of the led is set to 0 in the map,
// the value is not overriden with global controls, allowing the led
// to appear turned off
HSV hsv = { .h = pgm_read_byte(&ledcolors[layer][i][0]), .s = pgm_read_byte(&ledcolors[layer][i][1]), .v = val == 0 ? 0 : rgb_matrix_config.hsv.v};
RGB rgb = hsv_to_rgb( hsv );
rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
}
}
void set_layer_color( uint8_t layer ) {
HSV hsv = { .h = pgm_read_byte(&layercolors[layer][0]), .s = pgm_read_byte(&layercolors[layer][1]), .v = rgb_matrix_config.hsv.v};
RGB rgb = hsv_to_rgb( hsv );
for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
}
}
void rgb_matrix_indicators_user(void) {
uint32_t mode = rgblight_get_mode();
// assign colors if the matrix is on and the current mode
// is SOLID COLORS => No animations running
if(rgb_matrix_config.enable == 1 && mode == RGB_MATRIX_SOLID_COLOR) {
uint8_t layer = biton32(layer_state);
switch (layer) {
case 0:
set_layer_color(0);
break;
case 1:
set_leds_color(1);
break;
}
}
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) {
rgb_matrix_set_color(CAPS_LED, 128, 255, 255);
}
}
#define MODS_SHIFT (get_mods() & MOD_BIT(KC_LSHIFT) || get_mods() & MOD_BIT(KC_RSHIFT))
#define MODS_CTRL (get_mods() & MOD_BIT(KC_LCTL) || get_mods() & MOD_BIT(KC_RCTRL))
#define MODS_ALT (get_mods() & MOD_BIT(KC_LALT) || get_mods() & MOD_BIT(KC_RALT))