diff options
author | Drashna Jaelre <drashna@live.com> | 2021-12-29 20:17:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-29 20:17:34 -0800 |
commit | c4551d7ef1ed2c1069f23cc8499b7c7fc30f3ecf (patch) | |
tree | 67dc381a45d59626132c4c59b71c4b36fa971f8b /users/drashna/rgb | |
parent | 1a8a842cfb3e87a82afb57ba29ca59c5fa6fe97b (diff) |
[Keymap] Reorganization, cleanup and readmes for drashna code (#15617)
Diffstat (limited to 'users/drashna/rgb')
-rw-r--r-- | users/drashna/rgb/readme.md | 52 | ||||
-rw-r--r-- | users/drashna/rgb/rgb_matrix_stuff.c | 94 | ||||
-rw-r--r-- | users/drashna/rgb/rgb_matrix_stuff.h | 20 | ||||
-rw-r--r-- | users/drashna/rgb/rgb_stuff.c | 17 | ||||
-rw-r--r-- | users/drashna/rgb/rgb_stuff.h | 17 |
5 files changed, 124 insertions, 76 deletions
diff --git a/users/drashna/rgb/readme.md b/users/drashna/rgb/readme.md new file mode 100644 index 0000000000..4deaa0a463 --- /dev/null +++ b/users/drashna/rgb/readme.md @@ -0,0 +1,52 @@ +# RGB + +Custom RGB code can be disabled by setting `CUSTOM_RGBLIGHT = no` or `CUSTOM_RGB_MATRIX = no` in your `rules.mk` + +## RGB Light + +### Layer Indication Code + +At least for RGB Light, the `layer_state_set` function is used to detect the current highest layer, and change the underglow based on that layer. + +This works for both the regular layers, and for the default layers, too. + +I use the sethsv variants of the commands, so that different modes can be used, as well. + +RGB Matrix uses a custom, per board implementation, at the moment. + +### RGB Light Startup Animation + +On startup, if enabled, the board will cycle through the entire hue wheel, starting and ending on the default layer color. + +```c +void keyboard_post_init_rgb(void) { +#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION) + if (userspace_config.rgb_layer_change) { rgblight_enable_noeeprom(); } + if (rgblight_config.enable) { + layer_state_set_user(layer_state); + uint16_t old_hue = rgblight_config.hue; + rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); + for (uint16_t i = 255; i > 0; i--) { + rgblight_sethsv_noeeprom( ( i + old_hue) % 255, 255, 255); + matrix_scan(); + wait_ms(10); + } + } +#endif + layer_state_set_user(layer_state); +} +``` + +This could probably benefit from some cleanup and better handling. + +## RGB Matrix + +### Idle Animation + +This feature can be toggled with the `RGB_IDL` keycode. + +This sets the mode to the Heatmap Animation when typing, but will switch to the cycle in animations when idle. + +### Layer Indication + +This sets the modifier keys to indicate the current layer state, with the option to override the behavior. diff --git a/users/drashna/rgb/rgb_matrix_stuff.c b/users/drashna/rgb/rgb_matrix_stuff.c index 97811092c1..e6d631466d 100644 --- a/users/drashna/rgb/rgb_matrix_stuff.c +++ b/users/drashna/rgb/rgb_matrix_stuff.c @@ -1,18 +1,5 @@ -/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later #include "drashna.h" #include "rgb_matrix.h" @@ -29,27 +16,27 @@ void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode switch (mode) { case 1: // breathing - { - uint16_t time = scale16by8(g_rgb_timer, speed / 8); - hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); - RGB rgb = hsv_to_rgb(hsv); - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { - if (HAS_FLAGS(g_led_config.flags[i], led_type)) { - RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); - } + { + uint16_t time = scale16by8(g_rgb_timer, speed / 8); + hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + if (HAS_FLAGS(g_led_config.flags[i], led_type)) { + RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); } - break; } + break; + } default: // Solid Color - { - RGB rgb = hsv_to_rgb(hsv); - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { - if (HAS_FLAGS(g_led_config.flags[i], led_type)) { - RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); - } + { + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + if (HAS_FLAGS(g_led_config.flags[i], led_type)) { + RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); } - break; } + break; + } } } @@ -95,3 +82,48 @@ bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) { } return true; } + +__attribute__((weak)) bool rgb_matrix_indicators_advanced_keymap(uint8_t led_min, uint8_t led_max) { return true; } +void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { + if (!rgb_matrix_indicators_advanced_keymap(led_min, led_max)) { return; } + +#if defined(RGBLIGHT_ENABLE) + if (!userspace_config.rgb_layer_change) +#else + if (userspace_config.rgb_layer_change) +#endif + { + switch (get_highest_layer(layer_state | default_layer_state)) { + case _DEFAULT_LAYER_1: + rgb_matrix_layer_helper(DEFAULT_LAYER_1_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _DEFAULT_LAYER_2: + rgb_matrix_layer_helper(DEFAULT_LAYER_2_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _DEFAULT_LAYER_3: + rgb_matrix_layer_helper(DEFAULT_LAYER_3_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _DEFAULT_LAYER_4: + rgb_matrix_layer_helper(DEFAULT_LAYER_4_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _GAMEPAD: + rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _DIABLO: + rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed * 8, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _RAISE: + rgb_matrix_layer_helper(HSV_YELLOW, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _LOWER: + rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + case _ADJUST: + rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); + break; + } + } +} + +__attribute__((weak)) bool rgb_matrix_indicators_keymap(void) { return true; } +void rgb_matrix_indicators_user(void) { rgb_matrix_indicators_keymap(); } diff --git a/users/drashna/rgb/rgb_matrix_stuff.h b/users/drashna/rgb/rgb_matrix_stuff.h index b86f2f6514..7c6f6c271e 100644 --- a/users/drashna/rgb/rgb_matrix_stuff.h +++ b/users/drashna/rgb/rgb_matrix_stuff.h @@ -1,18 +1,5 @@ -/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "quantum.h" @@ -23,3 +10,6 @@ void matrix_scan_rgb_matrix(void); void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type, uint8_t led_min, uint8_t led_max); + +bool rgb_matrix_indicators_advanced_keymap(uint8_t led_min, uint8_t led_max); +bool rgb_matrix_indicators_keymap(void); diff --git a/users/drashna/rgb/rgb_stuff.c b/users/drashna/rgb/rgb_stuff.c index 15108bde04..e0422334aa 100644 --- a/users/drashna/rgb/rgb_stuff.c +++ b/users/drashna/rgb/rgb_stuff.c @@ -1,18 +1,5 @@ -/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later #ifdef RGBLIGHT_ENABLE diff --git a/users/drashna/rgb/rgb_stuff.h b/users/drashna/rgb/rgb_stuff.h index af1acdde71..d720275b60 100644 --- a/users/drashna/rgb/rgb_stuff.h +++ b/users/drashna/rgb/rgb_stuff.h @@ -1,18 +1,5 @@ -/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include "quantum.h" |