diff options
author | Drashna Jaelre <drashna@live.com> | 2021-08-26 13:41:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-27 06:41:33 +1000 |
commit | 29ec2d8f4283212cf45c926c288f652a6727acb7 (patch) | |
tree | 940bd04c7a380b4d9fa6b306e125c107b5d4c78e /docs/feature_rgb_matrix.md | |
parent | 7e1634e2a6abac5fbdf7778ea7734a10b84ca49a (diff) | |
download | qmk_firmware-29ec2d8f4283212cf45c926c288f652a6727acb7.tar.gz qmk_firmware-29ec2d8f4283212cf45c926c288f652a6727acb7.zip |
[Docs] Add examples to RGB Matrix Indicators docs (#12797)
Diffstat (limited to 'docs/feature_rgb_matrix.md')
-rw-r--r-- | docs/feature_rgb_matrix.md | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index 31fa9ed36..42a57aec1 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md | |||
@@ -741,3 +741,42 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { | |||
741 | } | 741 | } |
742 | } | 742 | } |
743 | ``` | 743 | ``` |
744 | |||
745 | #### Examples :id=indicator-examples | ||
746 | |||
747 | This example sets the modifiers to be a specific color based on the layer state. You can use a switch case here, instead, if you would like. This uses HSV and then converts to RGB, because this allows the brightness to be limited (important when using the WS2812 driver). | ||
748 | |||
749 | ```c | ||
750 | void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { | ||
751 | HSV hsv = {0, 255, 255}; | ||
752 | |||
753 | if (layer_state_is(layer_state, 2)) { | ||
754 | hsv = {130, 255, 255}; | ||
755 | } else { | ||
756 | hsv = {30, 255, 255}; | ||
757 | } | ||
758 | |||
759 | if (hsv.v > rgb_matrix_get_val()) { | ||
760 | hsv.v = rgb_matrix_get_val(); | ||
761 | } | ||
762 | RGB rgb = hsv_to_rgb(hsv); | ||
763 | |||
764 | for (uint8_t i = led_min; i <= led_max; i++) { | ||
765 | if (HAS_FLAGS(g_led_config.flags[i], 0x01)) { // 0x01 == LED_FLAG_MODIFIER | ||
766 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
767 | } | ||
768 | } | ||
769 | } | ||
770 | ``` | ||
771 | |||
772 | If you want to indicate a Host LED status (caps lock, num lock, etc), you can use something like this to light up the caps lock key: | ||
773 | |||
774 | ```c | ||
775 | void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { | ||
776 | if (host_keyboard_led_state().caps_lock) { | ||
777 | RGB_MATRIX_INDICATOR_SET_COLOR(5, 255, 255, 255); // assuming caps lock is at led #5 | ||
778 | } else { | ||
779 | RGB_MATRIX_INDICATOR_SET_COLOR(5, 0, 0, 0); | ||
780 | } | ||
781 | } | ||
782 | ``` | ||