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) | |
| download | qmk_firmware-c4551d7ef1ed2c1069f23cc8499b7c7fc30f3ecf.tar.gz qmk_firmware-c4551d7ef1ed2c1069f23cc8499b7c7fc30f3ecf.zip | |
[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 000000000..4deaa0a46 --- /dev/null +++ b/users/drashna/rgb/readme.md | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | # RGB | ||
| 2 | |||
| 3 | Custom RGB code can be disabled by setting `CUSTOM_RGBLIGHT = no` or `CUSTOM_RGB_MATRIX = no` in your `rules.mk` | ||
| 4 | |||
| 5 | ## RGB Light | ||
| 6 | |||
| 7 | ### Layer Indication Code | ||
| 8 | |||
| 9 | 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. | ||
| 10 | |||
| 11 | This works for both the regular layers, and for the default layers, too. | ||
| 12 | |||
| 13 | I use the sethsv variants of the commands, so that different modes can be used, as well. | ||
| 14 | |||
| 15 | RGB Matrix uses a custom, per board implementation, at the moment. | ||
| 16 | |||
| 17 | ### RGB Light Startup Animation | ||
| 18 | |||
| 19 | On startup, if enabled, the board will cycle through the entire hue wheel, starting and ending on the default layer color. | ||
| 20 | |||
| 21 | ```c | ||
| 22 | void keyboard_post_init_rgb(void) { | ||
| 23 | #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION) | ||
| 24 | if (userspace_config.rgb_layer_change) { rgblight_enable_noeeprom(); } | ||
| 25 | if (rgblight_config.enable) { | ||
| 26 | layer_state_set_user(layer_state); | ||
| 27 | uint16_t old_hue = rgblight_config.hue; | ||
| 28 | rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); | ||
| 29 | for (uint16_t i = 255; i > 0; i--) { | ||
| 30 | rgblight_sethsv_noeeprom( ( i + old_hue) % 255, 255, 255); | ||
| 31 | matrix_scan(); | ||
| 32 | wait_ms(10); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | #endif | ||
| 36 | layer_state_set_user(layer_state); | ||
| 37 | } | ||
| 38 | ``` | ||
| 39 | |||
| 40 | This could probably benefit from some cleanup and better handling. | ||
| 41 | |||
| 42 | ## RGB Matrix | ||
| 43 | |||
| 44 | ### Idle Animation | ||
| 45 | |||
| 46 | This feature can be toggled with the `RGB_IDL` keycode. | ||
| 47 | |||
| 48 | This sets the mode to the Heatmap Animation when typing, but will switch to the cycle in animations when idle. | ||
| 49 | |||
| 50 | ### Layer Indication | ||
| 51 | |||
| 52 | 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 97811092c..e6d631466 100644 --- a/users/drashna/rgb/rgb_matrix_stuff.c +++ b/users/drashna/rgb/rgb_matrix_stuff.c | |||
| @@ -1,18 +1,5 @@ | |||
| 1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | 1 | // Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> |
| 2 | * | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 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 | 3 | ||
| 17 | #include "drashna.h" | 4 | #include "drashna.h" |
| 18 | #include "rgb_matrix.h" | 5 | #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 | |||
| 29 | 16 | ||
| 30 | switch (mode) { | 17 | switch (mode) { |
| 31 | case 1: // breathing | 18 | case 1: // breathing |
| 32 | { | 19 | { |
| 33 | uint16_t time = scale16by8(g_rgb_timer, speed / 8); | 20 | uint16_t time = scale16by8(g_rgb_timer, speed / 8); |
| 34 | hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); | 21 | hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); |
| 35 | RGB rgb = hsv_to_rgb(hsv); | 22 | RGB rgb = hsv_to_rgb(hsv); |
| 36 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 23 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 37 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { | 24 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { |
| 38 | RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); | 25 | RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); |
| 39 | } | ||
| 40 | } | 26 | } |
| 41 | break; | ||
| 42 | } | 27 | } |
| 28 | break; | ||
| 29 | } | ||
| 43 | default: // Solid Color | 30 | default: // Solid Color |
| 44 | { | 31 | { |
| 45 | RGB rgb = hsv_to_rgb(hsv); | 32 | RGB rgb = hsv_to_rgb(hsv); |
| 46 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 33 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 47 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { | 34 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { |
| 48 | RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); | 35 | RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); |
| 49 | } | ||
| 50 | } | 36 | } |
| 51 | break; | ||
| 52 | } | 37 | } |
| 38 | break; | ||
| 39 | } | ||
| 53 | } | 40 | } |
| 54 | } | 41 | } |
| 55 | 42 | ||
| @@ -95,3 +82,48 @@ bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) { | |||
| 95 | } | 82 | } |
| 96 | return true; | 83 | return true; |
| 97 | } | 84 | } |
| 85 | |||
| 86 | __attribute__((weak)) bool rgb_matrix_indicators_advanced_keymap(uint8_t led_min, uint8_t led_max) { return true; } | ||
| 87 | void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { | ||
| 88 | if (!rgb_matrix_indicators_advanced_keymap(led_min, led_max)) { return; } | ||
| 89 | |||
| 90 | #if defined(RGBLIGHT_ENABLE) | ||
| 91 | if (!userspace_config.rgb_layer_change) | ||
| 92 | #else | ||
| 93 | if (userspace_config.rgb_layer_change) | ||
| 94 | #endif | ||
| 95 | { | ||
| 96 | switch (get_highest_layer(layer_state | default_layer_state)) { | ||
| 97 | case _DEFAULT_LAYER_1: | ||
| 98 | rgb_matrix_layer_helper(DEFAULT_LAYER_1_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 99 | break; | ||
| 100 | case _DEFAULT_LAYER_2: | ||
| 101 | rgb_matrix_layer_helper(DEFAULT_LAYER_2_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 102 | break; | ||
| 103 | case _DEFAULT_LAYER_3: | ||
| 104 | rgb_matrix_layer_helper(DEFAULT_LAYER_3_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 105 | break; | ||
| 106 | case _DEFAULT_LAYER_4: | ||
| 107 | rgb_matrix_layer_helper(DEFAULT_LAYER_4_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 108 | break; | ||
| 109 | case _GAMEPAD: | ||
| 110 | rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 111 | break; | ||
| 112 | case _DIABLO: | ||
| 113 | rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed * 8, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 114 | break; | ||
| 115 | case _RAISE: | ||
| 116 | rgb_matrix_layer_helper(HSV_YELLOW, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 117 | break; | ||
| 118 | case _LOWER: | ||
| 119 | rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 120 | break; | ||
| 121 | case _ADJUST: | ||
| 122 | rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max); | ||
| 123 | break; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | __attribute__((weak)) bool rgb_matrix_indicators_keymap(void) { return true; } | ||
| 129 | 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 b86f2f651..7c6f6c271 100644 --- a/users/drashna/rgb/rgb_matrix_stuff.h +++ b/users/drashna/rgb/rgb_matrix_stuff.h | |||
| @@ -1,18 +1,5 @@ | |||
| 1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | 1 | // Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> |
| 2 | * | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 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 | 3 | ||
| 17 | #pragma once | 4 | #pragma once |
| 18 | #include "quantum.h" | 5 | #include "quantum.h" |
| @@ -23,3 +10,6 @@ void matrix_scan_rgb_matrix(void); | |||
| 23 | 10 | ||
| 24 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); | 11 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); |
| 25 | 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); | 12 | 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); |
| 13 | |||
| 14 | bool rgb_matrix_indicators_advanced_keymap(uint8_t led_min, uint8_t led_max); | ||
| 15 | bool rgb_matrix_indicators_keymap(void); | ||
diff --git a/users/drashna/rgb/rgb_stuff.c b/users/drashna/rgb/rgb_stuff.c index 15108bde0..e0422334a 100644 --- a/users/drashna/rgb/rgb_stuff.c +++ b/users/drashna/rgb/rgb_stuff.c | |||
| @@ -1,18 +1,5 @@ | |||
| 1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | 1 | // Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> |
| 2 | * | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 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 | 3 | ||
| 17 | #ifdef RGBLIGHT_ENABLE | 4 | #ifdef RGBLIGHT_ENABLE |
| 18 | 5 | ||
diff --git a/users/drashna/rgb/rgb_stuff.h b/users/drashna/rgb/rgb_stuff.h index af1acdde7..d720275b6 100644 --- a/users/drashna/rgb/rgb_stuff.h +++ b/users/drashna/rgb/rgb_stuff.h | |||
| @@ -1,18 +1,5 @@ | |||
| 1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | 1 | // Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> |
| 2 | * | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 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 | 3 | ||
| 17 | #pragma once | 4 | #pragma once |
| 18 | #include "quantum.h" | 5 | #include "quantum.h" |
