forked from mirrors/qmk_userspace
Fix Per Key LED Indicator Callbacks (#18450)
Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
This commit is contained in:
parent
09d3e27710
commit
64b1ed4550
218 changed files with 1430 additions and 1271 deletions
|
@ -888,16 +888,21 @@ Where `28` is an unused index from `eeconfig.h`.
|
|||
|
||||
If you want to set custom indicators, such as an LED for Caps Lock, or layer indication, you can use the `rgb_matrix_indicators_kb` or `rgb_matrix_indicators_user` function for that:
|
||||
```c
|
||||
void rgb_matrix_indicators_kb(void) {
|
||||
bool rgb_matrix_indicators_kb(void) {
|
||||
if (!rgb_matrix_indicators_user()) {
|
||||
return false;
|
||||
}
|
||||
rgb_matrix_set_color(index, red, green, blue);
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
In addition, there are the advanced indicator functions. These are aimed at those with heavily customized displays, where rendering every LED per cycle is expensive. Such as some of the "drashna" layouts. This includes a special macro to help make this easier to use: `RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b)`.
|
||||
|
||||
```c
|
||||
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
RGB_MATRIX_INDICATOR_SET_COLOR(index, red, green, blue);
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -905,7 +910,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
|||
|
||||
Caps Lock indicator on alphanumeric flagged keys:
|
||||
```c
|
||||
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
if (host_keyboard_led_state().caps_lock) {
|
||||
for (uint8_t i = led_min; i <= led_max; i++) {
|
||||
if (g_led_config.flags[i] & LED_FLAG_KEYLIGHT) {
|
||||
|
@ -913,12 +918,13 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
Layer indicator on all keys:
|
||||
```c
|
||||
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
for (uint8_t i = led_min; i <= led_max; i++) {
|
||||
switch(get_highest_layer(layer_state|default_layer_state)) {
|
||||
case 2:
|
||||
|
@ -931,12 +937,13 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
Layer indicator only on keys with configured keycodes:
|
||||
```c
|
||||
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
||||
if (get_highest_layer(layer_state) > 0) {
|
||||
uint8_t layer = get_highest_layer(layer_state);
|
||||
|
||||
|
@ -951,6 +958,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -961,7 +969,7 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
|||
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) {
|
||||
bool 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)) {
|
||||
|
@ -980,18 +988,20 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
|||
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
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) {
|
||||
bool 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);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue