From 9607962cd5da243429c0406fd017b430a1b210d5 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Mon, 3 May 2021 20:33:04 -0700 Subject: [PATCH] [Docs] Add examples to RGB Matrix Indicators docs --- docs/feature_rgb_matrix.md | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index e996cadddd0a..39c21a58db7f 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -542,6 +542,45 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { } ``` +#### Examples :id=indicator-examples + +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). + +```c +void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { + HSV hsv = {0, 255, 255}; + + if (layer_state_is(layer_state, 2)) { + hsv = {130, 255, 255}; + } else { + hsv = {30, 255, 255}; + } + + if (hsv.v > rgb_matrix_get_val()) { + hsv.v = rgb_matrix_get_val(); + } + RGB rgb = hsv_to_rgb(hsv); + + for (uint8_t i = led_min; i <= led_max; i++) { + if (HAS_FLAGS(g_led_config.flags[i], 0x01)) { // 0x01 == LED_FLAG_MODIFIER + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + } +} +``` + +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: + +```c +void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { + if (host_keyboard_led_state().caps_lock) { + RGB_MATRIX_INDICATOR_SET_COLOR(5, 255, 255, 255); // assuming caps lock is at led #5 + } else { + RGB_MATRIX_INDICATOR_SET_COLOR(5, 0, 0, 0); + } +} +``` + ### Suspended state :id=suspended-state To use the suspend feature, make sure that `#define RGB_DISABLE_WHEN_USB_SUSPENDED true` is added to the `config.h` file.