summaryrefslogtreecommitdiffstats
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
parent71f067a60ef01df6a58c086a939a58e40ab7e972 (diff)
Improve the Lighting Layers example in RGB Lighting docs (#11454)
* Improve the keymap layer state -> lighting layers example * A few more improvements
-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 844e3e6d76..0d3e666701 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
By 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.
-To 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:
+To 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:
```c
// 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(
const rgblight_segment_t PROGMEM my_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(
{11, 2, HSV_PURPLE}
);
+// Light LEDs 13 & 14 in green when keyboard layer 3 is active
+const rgblight_segment_t PROGMEM my_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(
+ {13, 2, HSV_GREEN}
+);
// etc..
```
@@ -222,7 +226,8 @@ We combine these layers into an array using the `RGBLIGHT_LAYERS_LIST` macro, an
const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
my_capslock_layer,
my_layer1_layer, // Overrides caps lock layer
- my_layer2_layer // Overrides other layers
+ my_layer2_layer, // Overrides other layers
+ my_layer3_layer // Overrides other layers
);
void keyboard_post_init_user(void) {
@@ -238,17 +243,21 @@ Everything above just configured the definition of each lighting layer.
We can now enable and disable the lighting layers whenever the state of the keyboard changes:
```c
-layer_state_t layer_state_set_user(layer_state_t state) {
- // Both layers will light up if both kb layers are active
- rgblight_set_layer_state(1, layer_state_cmp(state, 1));
- rgblight_set_layer_state(2, layer_state_cmp(state, 2));
- return state;
-}
-
bool led_update_user(led_t led_state) {
rgblight_set_layer_state(0, led_state.caps_lock);
return true;
}
+
+layer_state_t default_layer_state_set_user(layer_state_t state) {
+ rgblight_set_layer_state(1, layer_state_cmp(state, _DVORAK));
+ return state;
+}
+
+layer_state_t layer_state_set_user(layer_state_t state) {
+ rgblight_set_layer_state(2, layer_state_cmp(state, _FN));
+ rgblight_set_layer_state(3, layer_state_cmp(state, _ADJUST));
+ return state;
+}
```
### Lighting layer blink :id=lighting-layer-blink