Skip to content

Commit

Permalink
Documentation update - activ layer rgb indication (#944)
Browse files Browse the repository at this point in the history
* Extended documentation for the trackball LED animated light

* Docs improvement about activ layer rgb indication
  • Loading branch information
jacmie authored Mar 26, 2024
1 parent 68914d1 commit 7ad8718
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions docs/en/layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,47 @@ keyboard.keymap = [
]
```

## Advanced Example
## Active Layer indication with RGB
A common question is: "How do I change RGB background based on my active layer?"
Here is _one_ (simple) way of many to go about it.

To indicate active layer you can use RGB background, or in many cases board's status LED, then no additional hardware is needed. Information about the LED type and to which GPIO pin it is connected is often available on the pinout of the board and in the documentation.

In this example on board RGB status LED is used. Number of layers is unlimited and only chosen layers can be used. Note, that LED's basic colors can have different order for different hardware.

```python
import board

from kmk.modules.layers import Layers as _Layers
from kmk.extensions.rgb import RGB

rgb = RGB(...) # your RGB configuration goes here
sat = 255
val = 5; # brightness in range 0-255

rgb = RGB(pixel_pin=board.GP16, # GPIO pin of the status LED, or background RGB light
num_pixels=1, # one if status LED, more if background RGB light
rgb_order=(0, 1, 2), # RGB order may differ depending on the hardware
hue_default=0, # in range 0-255: 0/255-red, 85-green, 170-blue
sat_default=sat,
val_default=val,
)

keyboard.extensions.append(rgb)

class Layers(_Layers):
last_top_layer = 0
hues = (4, 20, 69)

def after_hid_send(self, keyboard):
if keyboard.active_layers[0] != self.last_top_layer:
self.last_top_layer = keyboard.active_layers[0]
rgb.set_hsv_fill(self.hues[self.last_top_layer], 255, 255)
rgb.hue = self.hues[self.last_top_layer]
last_top_layer = 0

def after_hid_send(self, keyboard):
if keyboard.active_layers[0] != self.last_top_layer:
self.last_top_layer = keyboard.active_layers[0]
if self.last_top_layer == 0: # default
rgb.set_hsv_fill(0, sat, val) # red
elif self.last_top_layer == 1:
rgb.set_hsv_fill(170, sat, val) # blue
elif self.last_top_layer == 2:
rgb.set_hsv_fill(43, sat, val) # yellow
elif self.last_top_layer == 4:
rgb.set_hsv_fill(0, 0, val) # white

keyboard.modules.append(Layers())
```

0 comments on commit 7ad8718

Please sign in to comment.