diff options
Diffstat (limited to 'users/vnmm/rgb_matrix_user.c')
| -rw-r--r-- | users/vnmm/rgb_matrix_user.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/users/vnmm/rgb_matrix_user.c b/users/vnmm/rgb_matrix_user.c new file mode 100644 index 0000000000..c85f86782e --- /dev/null +++ b/users/vnmm/rgb_matrix_user.c | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include QMK_KEYBOARD_H | ||
| 18 | #include "rgb_matrix_user.h" | ||
| 19 | #include "keymap_user.h" | ||
| 20 | |||
| 21 | keypos_t led_index_key_position[RGB_MATRIX_LED_COUNT]; | ||
| 22 | |||
| 23 | #ifdef SHIFT_INDICATOR_COLOR | ||
| 24 | # define is_shift_pressed (get_mods() & MOD_MASK_SHIFT) | ||
| 25 | #else | ||
| 26 | # define is_shift_pressed false | ||
| 27 | #endif | ||
| 28 | |||
| 29 | void rgb_matrix_init_user(void) { | ||
| 30 | // Set up led_index_key_position | ||
| 31 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 32 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 33 | uint8_t led_index = g_led_config.matrix_co[row][col]; | ||
| 34 | if (led_index != NO_LED) { | ||
| 35 | led_index_key_position[led_index] = (keypos_t){.row = row, .col = col}; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { | ||
| 42 | uint8_t current_layer = get_highest_layer(layer_state); | ||
| 43 | bool caps = host_keyboard_led_state().caps_lock; | ||
| 44 | switch (current_layer) { | ||
| 45 | case WIN_BASE: | ||
| 46 | case MAC_BASE: | ||
| 47 | // Light up letters if caps and light up letters and numbers if shift. If shift and caps light up just numbers. | ||
| 48 | #ifdef CAPS_LOCK_INDICATOR_COLOR | ||
| 49 | if (caps && !is_shift_pressed) { | ||
| 50 | rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_caps_lock_indicator, CAPS_LOCK_INDICATOR_COLOR); | ||
| 51 | # ifdef CAPS_LOCK_INDICATOR_OTHER | ||
| 52 | rgb_matrix_set_color_by_not_keycode(led_min, led_max, current_layer, is_caps_lock_indicator, CAPS_LOCK_INDICATOR_OTHER); | ||
| 53 | # endif | ||
| 54 | } | ||
| 55 | # ifdef SHIFT_INDICATOR_COLOR | ||
| 56 | else if (is_shift_pressed && !caps) { | ||
| 57 | // Light up letters and other shift affected keys | ||
| 58 | rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_shift_indicator, SHIFT_INDICATOR_COLOR); | ||
| 59 | rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_caps_lock_indicator, CAPS_LOCK_INDICATOR_COLOR); | ||
| 60 | } else if (is_shift_pressed && caps) { | ||
| 61 | // Only shift affected keys light up | ||
| 62 | rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_shift_indicator, SHIFT_INDICATOR_COLOR); | ||
| 63 | } | ||
| 64 | # endif // SHIFT_INDICATOR_COLOR | ||
| 65 | #endif // CAPS_LOCK_INDICATOR_COLOR | ||
| 66 | break; | ||
| 67 | default: | ||
| 68 | #ifdef FN_LAYER_TRANSPARENT_KEYS_COLOR | ||
| 69 | rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_transparent, FN_LAYER_TRANSPARENT_KEYS_COLOR); | ||
| 70 | #endif | ||
| 71 | #ifdef FN_LAYER_KEYS_COLOR | ||
| 72 | rgb_matrix_set_color_by_not_keycode(led_min, led_max, current_layer, is_transparent, FN_LAYER_KEYS_COLOR); | ||
| 73 | #endif | ||
| 74 | #ifdef CURRENT_LAYER_INDICATOR_COLOR | ||
| 75 | rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_default_layer, CURRENT_LAYER_INDICATOR_COLOR); | ||
| 76 | #endif | ||
| 77 | #ifdef NKRO_INDICATOR_COLOR | ||
| 78 | if (keymap_config.nkro) { | ||
| 79 | rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_nkro_indicator, NKRO_INDICATOR_COLOR); | ||
| 80 | } | ||
| 81 | #endif | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | return false; | ||
| 85 | } | ||
| 86 | |||
| 87 | // set color of keys that match the keycode | ||
| 88 | void rgb_matrix_set_color_by_keycode(uint8_t led_min, uint8_t led_max, uint8_t layer, bool (*is_keycode)(uint16_t), uint8_t red, uint8_t green, uint8_t blue) { | ||
| 89 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 90 | uint16_t keycode = keymap_key_to_keycode(layer, led_index_key_position[i]); | ||
| 91 | if ((*is_keycode)(keycode)) { | ||
| 92 | rgb_matrix_set_color(i, red, green, blue); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | // set color of all leds that are not a certain keycode | ||
| 98 | void rgb_matrix_set_color_by_not_keycode(uint8_t led_min, uint8_t led_max, uint8_t layer, bool (*is_keycode)(uint16_t), uint8_t red, uint8_t green, uint8_t blue) { | ||
| 99 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 100 | uint16_t keycode = keymap_key_to_keycode(layer, led_index_key_position[i]); | ||
| 101 | if (!(*is_keycode)(keycode)) { | ||
| 102 | rgb_matrix_set_color(i, red, green, blue); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | // check if keycode is a letter or shift or caps lock | ||
| 108 | bool is_caps_lock_indicator(uint16_t keycode) { | ||
| 109 | #ifdef CAPS_LOCK_INDICATOR_LIGHT_ALPHAS | ||
| 110 | return (KC_A <= keycode && keycode <= KC_Z) || keycode == KC_CAPS || keycode == KC_LSFT || keycode == KC_RSFT; | ||
| 111 | #else | ||
| 112 | return keycode == KC_CAPS; | ||
| 113 | #endif | ||
| 114 | } | ||
| 115 | |||
| 116 | // check if keycode is the DF to default layer | ||
| 117 | #ifdef CURRENT_LAYER_INDICATOR_COLOR | ||
| 118 | bool is_default_layer(uint16_t keycode) { | ||
| 119 | return keycode == DF(get_highest_layer(default_layer_state)); | ||
| 120 | } | ||
| 121 | #endif | ||
| 122 | |||
| 123 | // check if keycode is the NKRO toggle | ||
| 124 | #ifdef NKRO_INDICATOR_COLOR | ||
| 125 | bool is_nkro_indicator(uint16_t keycode) { | ||
| 126 | return keycode == NK_TOGG; | ||
| 127 | } | ||
| 128 | #endif | ||
| 129 | |||
| 130 | // check if keycode is transparent | ||
| 131 | bool is_transparent(uint16_t keycode) { | ||
| 132 | return keycode == KC_TRNS; | ||
| 133 | } | ||
| 134 | |||
| 135 | // check if keycode is affected by shift on the number row | ||
| 136 | #ifdef SHIFT_INDICATOR_COLOR | ||
| 137 | bool is_shift_indicator(uint16_t keycode) { | ||
| 138 | return (KC_1 <= keycode && keycode <= KC_0) || keycode == KC_MINS || keycode == KC_EQL || keycode == KC_GRV || keycode == KC_BSLS || keycode == KC_LBRC || keycode == KC_RBRC || keycode == KC_SCLN || keycode == KC_QUOT || keycode == KC_COMM || keycode == KC_DOT || keycode == KC_SLSH || keycode == QK_GESC || keycode == KC_LSFT || keycode == KC_RSFT; | ||
| 139 | } | ||
| 140 | #endif | ||
