Added 2 more keys, stripped unused cruft, and added more docs.

This commit is contained in:
Kyle Brown 2019-02-24 22:32:13 -08:00
parent 5c8c2e97fd
commit f65ea1e841
6 changed files with 86 additions and 20 deletions

33
docs/examples.md Normal file
View File

@ -0,0 +1,33 @@
# Examples
Here you can find some examples of what some users have created in their personal keyboard configs. These are here to
help you understand how some of the tools may be used.
## Changing LED color based on layers
This allows you to create a layer key that also changes colors when pushing a layer key, and restore turn off the lights
when you release the layer key. The example uses the MO though any layer switch keys can be used if imported. Just use the
LAYER_1 key in your keymap, and it's ready to go! You can change animations, colors, or anything in there.
```python
from kmk.handlers.layers import (mo_pressed, mo_released)
from kmk.keys import KC, layer_key_validator, make_argumented_key
def layer1p(*args, **kwargs):
keyboard.pixels.set_hsv_fill(100, 100, 100)
return mo_pressed(*args, **kwargs)
def layer1r(*args, **kwargs):
keyboard.pixels.set_hsv_fill.fill(0, 0, 0)
return mo_released(*args, **kwargs)
make_argumented_key(
validator=layer_key_validator,
names=('LAYER_1',),
on_press=layer1p,
on_release=layer1r,
)
LAYER_1 = KC.LAYER_1(1)
```

View File

@ -1,6 +1,7 @@
# RGB/Underglow/Neopixel
Want your keyboard to shine? Add some lights!
This does require the neopixel library from Adafruit. This can be downloaded here https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/master/neopixel.py
This does require the neopixel library from Adafruit. This can be downloaded [here](https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/6e35cd2b40575a20e2904b096508325cef4a71d3/neopixel.py).
It is part of the [Adafruit CircuitPython Bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle).
Simply put this in the "root" of your circuitpython device. If unsure, it's the folder with main.py in it, and should be the first folder you see when you open the device.
@ -39,6 +40,8 @@ Changing the **Value** sets the overall brightness.
|`KC.RGB_SAD` | |Decrease Saturation |
|`KC.RGB_VAI` | |Increase Value |
|`KC.RGB_VAD` | |Decrease Value |
|`KC.RGB_ANI` | |Increase animation speed |
|`KC.RGB_AND` | |Decrease animation speed |
|`KC.RGB_MODE_PLAIN` |`RGB_M_P` |Static RGB |
|`KC.RGB_MODE_BREATHE` |`RGB_M_B` |Breathing animation |
|`KC.RGB_MODE_RAINBOW` |`RGB_M_R` |Rainbow animation |
@ -48,6 +51,7 @@ Changing the **Value** sets the overall brightness.
## Configuration
|Define |Default |Description |
|---------------------|-------------|-----------------------------------------------------------------------------|
|`keyboard.rgb_order` |`(1, 0, 2)` |The order of the pixels R G B, and optionally white. Example(1, 0, 2, 3) |
|`keyboard.hue_step` |`10` |The number of steps to cycle through the hue by |
|`keyboard.sat_step` |`17` |The number of steps to increment the saturation by |
|`keyboard.val_step` |`17` |The number of steps to increment the brightness by |
@ -69,6 +73,8 @@ If you want to create your own animations, or for example, change the lighting i
|`keyboard.pixels.decrease_sat(step)` |Decreases saturation by a given step |
|`keyboard.pixels.increase_val(step)` |Increases value (brightness) by a given step |
|`keyboard.pixels.decrease_val(step)` |Decreases value (brightness) by a given step |
|`keyboard.pixels.increase_ani()` |Increases animation speed by 1. Maximum 10 |
|`keyboard.pixels.decrease_ani()` |Decreases animation speed by 1. Minimum 10 |
|`keyboard.pixels.off()` |Turns all LED's off |
|`keyboard.pixels.show()` |Displays all stored configuration for LED's. Useful with disable_auto_write explained below |
|`keyboard.pixels.time_ms()` |Returns a time in ms since the board has booted. Useful for start/stop timers |
@ -83,7 +89,7 @@ Other settings that are useful that can be changed.
|`keyboard.disable_auto_write` |`False` |When True, disables showing changes. Good for setting multiple LED's before a visible update |
|`keyboard.reverse_animation` |`False` |If true, some animations will run in reverse. Can be safely used in user animations |
|`keyboard.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid |
|`keyboard.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5 |
|`keyboard.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. |
## Built-in Animation Configuration
|Define |Default |Description |
@ -101,3 +107,10 @@ If you wish to interact with these as you would normal LED's and do not want hel
keyboard.pixels.disabse_auto_write = True
keyboard.pixels.neopixel() # <-- This is the neopixel object
```
## Troubleshooting
### Incorrect colors
If your colors are incorrect, check the pixel order of your specific LED's. Here are some common ones.
* WS2811, WS2812, WS2812B, WS2812C are all GRB (1, 0, 2)
* SK6812, SK6812MINI, SK6805 are all GRB (1, 0, 2)
* Neopixels will vary depending on which one you buy. It will be listed on the product page.

View File

@ -125,16 +125,6 @@ def rgb_tog(key, state, *args, **kwargs):
return state
def rgb_forward(key, state, *args, **kwargs):
# TODO
return state
def rgb_reverse(key, state, *args, **kwargs):
# TODO
return state
def rgb_hui(key, state, *args, **kwargs):
state.config.pixels.increase_hue(state.config.pixels.hue_step)
return state
@ -165,6 +155,16 @@ def rgb_vad(key, state, *args, **kwargs):
return state
def rgb_ani(key, state, *args, **kwargs):
state.config.pixels.increase_ani()
return state
def rgb_and(key, state, *args, **kwargs):
state.config.pixels.decrease_ani()
return state
def rgb_mode_static(key, state, *args, **kwargs):
state.config.pixels.effect_init = True
state.config.pixels.animation_mode = 'static'

View File

@ -627,14 +627,14 @@ make_key(names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.ge
make_key(names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released)
make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released)
make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog)
make_key(names=('RGB_MODE_FORWARD', 'RGB_MOD'), on_press=handlers.rgb_forward)
make_key(names=('RGB_MODE_REVERSE', 'RGB_RMOD'), on_press=handlers.rgb_reverse)
make_key(names=('RGB_HUI',), on_press=handlers.rgb_hui)
make_key(names=('RGB_HUD',), on_press=handlers.rgb_hud)
make_key(names=('RGB_SAI',), on_press=handlers.rgb_sai)
make_key(names=('RGB_SAD',), on_press=handlers.rgb_sad)
make_key(names=('RGB_VAI',), on_press=handlers.rgb_vai)
make_key(names=('RGB_VAD',), on_press=handlers.rgb_vad)
make_key(names=('RGB_ANI',), on_press=handlers.rgb_ani)
make_key(names=('RGB_AND',), on_press=handlers.rgb_and)
make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static)
make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe)
make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow)

View File

@ -77,7 +77,7 @@ class RGB:
return ret
def time_ms(self):
return floor(time.monotonic() * 10)
return floor(time.monotonic() * 1000)
def hsv_to_rgb(self, hue, sat, val):
"""
@ -247,6 +247,26 @@ class RGB:
else:
self.val -= step
def increase_ani(self):
"""
Increases animation speed by 1 amount stopping at 10
:param step:
"""
if (self.animation_speed + 1) >= 10:
self.animation_speed = 10
else:
self.val += 1
def decrease_ani(self):
"""
Decreases animation speed by 1 amount stopping at 0
:param step:
"""
if (self.val - 1) <= 0:
self.val = 0
else:
self.val -= 1
def off(self):
"""
Turns off all LEDs/Neopixels without changing stored values

View File

@ -231,11 +231,11 @@ keyboard.keymap = [
],
[
# r3
[KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, _______, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL],
[_______, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS],
[_______, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU],
[_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD],
[BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX],
[KC.GESC, KC.RGB_M_P, KC.RGB_M_K, KC.RGB_M_B, KC.RGB_M_BR, _______, _______, _______, KC.F10, KC.F11, KC.F12, KC.DEL],
[KC.RGB_ANI, KC.RGB_HUD, KC.RGB_HUI, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS],
[KC.RGB_AND, KC.RGB_SAD, KC.RGB_SAI, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU],
[_______, KC.RGB_VAD, KC.RGB_VAI, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD],
[BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX],
],
]