aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJoshua Diamond <josh@windowoffire.com>2021-01-19 21:49:02 -0500
committerGitHub <noreply@github.com>2021-01-19 18:49:02 -0800
commitc0728bd189d0d9e5056f493e763191d8ca3c61f6 (patch)
tree1c0ea0ade16ebdfd391f96cf375aa3547ab70267 /docs
parent71f067a60ef01df6a58c086a939a58e40ab7e972 (diff)
downloadqmk_firmware-c0728bd189d0d9e5056f493e763191d8ca3c61f6.tar.gz
qmk_firmware-c0728bd189d0d9e5056f493e763191d8ca3c61f6.zip
Improve the Lighting Layers example in RGB Lighting docs (#11454)
* Improve the keymap layer state -> lighting layers example * A few more improvements
Diffstat (limited to 'docs')
-rw-r--r--docs/feature_rgblight.md27
1 files changed, 18 insertions, 9 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md
index 844e3e6d7..0d3e66670 100644
--- a/docs/feature_rgblight.md
+++ b/docs/feature_rgblight.md
@@ -196,7 +196,7 @@ it easy to use your underglow LEDs as status indicators to show which keyboard l
196 196
197By default, 8 layers are possible. This can be expanded to as many as 32 by overriding the definition of `RGBLIGHT_MAX_LAYERS` in `config.h` (e.g. `#define RGBLIGHT_MAX_LAYERS 32`). Please note, if you use a split keyboard, you will need to flash both sides of the split after changing this. Also, increasing the maximum will increase the firmware size, and will slow sync on split keyboards. 197By default, 8 layers are possible. This can be expanded to as many as 32 by overriding the definition of `RGBLIGHT_MAX_LAYERS` in `config.h` (e.g. `#define RGBLIGHT_MAX_LAYERS 32`). Please note, if you use a split keyboard, you will need to flash both sides of the split after changing this. Also, increasing the maximum will increase the firmware size, and will slow sync on split keyboards.
198 198
199To define a layer, we modify `keymap.c` to list out LED ranges and the colors we want to overlay on them using an array of `rgblight_segment_t` using the `RGBLIGHT_LAYER_SEGMENTS` macro. We can define multiple layers and enable/disable them independently: 199To define a layer, we modify `keymap.c` to list the LED ranges and the colors we want to overlay on them using an array of `rgblight_segment_t` using the `RGBLIGHT_LAYER_SEGMENTS` macro. We can define multiple layers and enable/disable them independently:
200 200
201```c 201```c
202// Light LEDs 6 to 9 and 12 to 15 red when caps lock is active. Hard to ignore! 202// Light LEDs 6 to 9 and 12 to 15 red when caps lock is active. Hard to ignore!
@@ -212,6 +212,10 @@ const rgblight_segment_t PROGMEM my_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS(
212const rgblight_segment_t PROGMEM my_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS( 212const rgblight_segment_t PROGMEM my_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(
213 {11, 2, HSV_PURPLE} 213 {11, 2, HSV_PURPLE}
214); 214);
215// Light LEDs 13 & 14 in green when keyboard layer 3 is active
216const rgblight_segment_t PROGMEM my_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(
217 {13, 2, HSV_GREEN}
218);
215// etc.. 219// etc..
216``` 220```
217 221
@@ -222,7 +226,8 @@ We combine these layers into an array using the `RGBLIGHT_LAYERS_LIST` macro, an
222const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST( 226const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
223 my_capslock_layer, 227 my_capslock_layer,
224 my_layer1_layer, // Overrides caps lock layer 228 my_layer1_layer, // Overrides caps lock layer
225 my_layer2_layer // Overrides other layers 229 my_layer2_layer, // Overrides other layers
230 my_layer3_layer // Overrides other layers
226); 231);
227 232
228void keyboard_post_init_user(void) { 233void keyboard_post_init_user(void) {
@@ -238,17 +243,21 @@ Everything above just configured the definition of each lighting layer.
238We can now enable and disable the lighting layers whenever the state of the keyboard changes: 243We can now enable and disable the lighting layers whenever the state of the keyboard changes:
239 244
240```c 245```c
241layer_state_t layer_state_set_user(layer_state_t state) {
242 // Both layers will light up if both kb layers are active
243 rgblight_set_layer_state(1, layer_state_cmp(state, 1));
244 rgblight_set_layer_state(2, layer_state_cmp(state, 2));
245 return state;
246}
247
248bool led_update_user(led_t led_state) { 246bool led_update_user(led_t led_state) {
249 rgblight_set_layer_state(0, led_state.caps_lock); 247 rgblight_set_layer_state(0, led_state.caps_lock);
250 return true; 248 return true;
251} 249}
250
251layer_state_t default_layer_state_set_user(layer_state_t state) {
252 rgblight_set_layer_state(1, layer_state_cmp(state, _DVORAK));
253 return state;
254}
255
256layer_state_t layer_state_set_user(layer_state_t state) {
257 rgblight_set_layer_state(2, layer_state_cmp(state, _FN));
258 rgblight_set_layer_state(3, layer_state_cmp(state, _ADJUST));
259 return state;
260}
252``` 261```
253 262
254### Lighting layer blink :id=lighting-layer-blink 263### Lighting layer blink :id=lighting-layer-blink