Needs docs, but code is ready for review probably
This commit is contained in:
parent
5334e7e0be
commit
ad3430eeb6
@ -105,6 +105,7 @@ class Firmware:
|
|||||||
val_step = 1
|
val_step = 1
|
||||||
animation_speed = 1
|
animation_speed = 1
|
||||||
breathe_center = 1.5 # 1.0-2.7
|
breathe_center = 1.5 # 1.0-2.7
|
||||||
|
knight_effect_length = 3
|
||||||
animation_mode = 'static'
|
animation_mode = 'static'
|
||||||
pixels = None
|
pixels = None
|
||||||
|
|
||||||
@ -226,10 +227,10 @@ class Firmware:
|
|||||||
self.pixels = rgb.RGB(self.pixel_pin, self.rgb_order, self.num_pixels,
|
self.pixels = rgb.RGB(self.pixel_pin, self.rgb_order, self.num_pixels,
|
||||||
self.hue_step, self.sat_step, self.val_step,
|
self.hue_step, self.sat_step, self.val_step,
|
||||||
self.hue_default, self.sat_default, self.val_default,
|
self.hue_default, self.sat_default, self.val_default,
|
||||||
self.breathe_center, self.val_limit, self.animation_mode
|
self.breathe_center, self.knight_effect_length,
|
||||||
|
self.val_limit, self.animation_mode, self.animation_speed
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
self.matrix = MatrixScanner(
|
self.matrix = MatrixScanner(
|
||||||
cols=self.col_pins,
|
cols=self.col_pins,
|
||||||
rows=self.row_pins,
|
rows=self.row_pins,
|
||||||
|
@ -166,21 +166,30 @@ def rgb_vad(key, state, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def rgb_mode_static(key, state, *args, **kwargs):
|
def rgb_mode_static(key, state, *args, **kwargs):
|
||||||
|
state.config.pixels.effect_init = True
|
||||||
state.config.pixels.animation_mode = 'static'
|
state.config.pixels.animation_mode = 'static'
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
def rgb_mode_breathe(key, state, *args, **kwargs):
|
def rgb_mode_breathe(key, state, *args, **kwargs):
|
||||||
|
state.config.pixels.effect_init = True
|
||||||
state.config.pixels.animation_mode = 'breathing'
|
state.config.pixels.animation_mode = 'breathing'
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
def rgb_mode_breathe_rainbow(key, state, *args, **kwargs):
|
def rgb_mode_breathe_rainbow(key, state, *args, **kwargs):
|
||||||
|
state.config.pixels.effect_init = True
|
||||||
state.config.pixels.animation_mode = 'breathing_rainbow'
|
state.config.pixels.animation_mode = 'breathing_rainbow'
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
def rgb_mode_rainbow(key, state, *args, **kwargs):
|
def rgb_mode_rainbow(key, state, *args, **kwargs):
|
||||||
|
state.config.pixels.effect_init = True
|
||||||
state.config.pixels.animation_mode = 'rainbow'
|
state.config.pixels.animation_mode = 'rainbow'
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
def rgb_mode_knight(key, state, *args, **kwargs):
|
||||||
|
state.config.pixels.effect_init = True
|
||||||
|
state.config.pixels.animation_mode = 'knight'
|
||||||
|
return state
|
||||||
|
@ -639,6 +639,7 @@ 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_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)
|
make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow)
|
||||||
make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), on_press=handlers.rgb_mode_breathe_rainbow)
|
make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'), on_press=handlers.rgb_mode_breathe_rainbow)
|
||||||
|
make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight)
|
||||||
make_key(
|
make_key(
|
||||||
names=('LEADER', 'LEAD'),
|
names=('LEADER', 'LEAD'),
|
||||||
on_press=handlers.leader_pressed,
|
on_press=handlers.leader_pressed,
|
||||||
|
65
kmk/rgb.py
65
kmk/rgb.py
@ -14,6 +14,7 @@ class RGB:
|
|||||||
enabled = True
|
enabled = True
|
||||||
neopixel = None
|
neopixel = None
|
||||||
rgbw = False
|
rgbw = False
|
||||||
|
reverse_animation = False
|
||||||
disable_auto_write = False
|
disable_auto_write = False
|
||||||
|
|
||||||
# Set by config
|
# Set by config
|
||||||
@ -22,13 +23,16 @@ class RGB:
|
|||||||
sat_step = 5
|
sat_step = 5
|
||||||
val_step = 5
|
val_step = 5
|
||||||
breath_center = 1.5 # 1.0-2.7
|
breath_center = 1.5 # 1.0-2.7
|
||||||
|
knight_effect_length = 4
|
||||||
val_limit = 255
|
val_limit = 255
|
||||||
animation_mode = 'static'
|
animation_mode = 'static'
|
||||||
|
effect_init = False
|
||||||
|
|
||||||
def __init__(self, pixel_pin, rgb_order, num_pixels,
|
def __init__(self, pixel_pin, rgb_order, num_pixels,
|
||||||
hue_step, sat_step, val_step,
|
hue_step, sat_step, val_step,
|
||||||
hue_default, sat_default, val_default,
|
hue_default, sat_default, val_default,
|
||||||
breath_center, val_limit, animation_mode):
|
breath_center, knight_effect_length,
|
||||||
|
val_limit, animation_mode, animation_speed):
|
||||||
try:
|
try:
|
||||||
import neopixel
|
import neopixel
|
||||||
self.neopixel = neopixel.NeoPixel(pixel_pin,
|
self.neopixel = neopixel.NeoPixel(pixel_pin,
|
||||||
@ -45,8 +49,10 @@ class RGB:
|
|||||||
self.sat = sat_default
|
self.sat = sat_default
|
||||||
self.val = val_default
|
self.val = val_default
|
||||||
self.breath_center = breath_center
|
self.breath_center = breath_center
|
||||||
|
self.knight_effect_length = knight_effect_length
|
||||||
self.val_limit = val_limit
|
self.val_limit = val_limit
|
||||||
self.animation_mode = animation_mode
|
self.animation_mode = animation_mode
|
||||||
|
self.animation_speed = animation_speed
|
||||||
|
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print(e)
|
print(e)
|
||||||
@ -62,6 +68,7 @@ class RGB:
|
|||||||
'animation_mode': self.animation_mode,
|
'animation_mode': self.animation_mode,
|
||||||
'time': self.time,
|
'time': self.time,
|
||||||
'intervals': self.intervals,
|
'intervals': self.intervals,
|
||||||
|
'animation_mode': self.animation_mode,
|
||||||
'animation_speed': self.animation_speed,
|
'animation_speed': self.animation_speed,
|
||||||
'enabled': self.enabled,
|
'enabled': self.enabled,
|
||||||
'neopixel': self.neopixel,
|
'neopixel': self.neopixel,
|
||||||
@ -160,10 +167,9 @@ class RGB:
|
|||||||
'''
|
'''
|
||||||
if self.neopixel:
|
if self.neopixel:
|
||||||
if self.rgbw:
|
if self.rgbw:
|
||||||
self.neopixel.fill(self.hsv_to_rgbw(hue, sat, val))
|
self.set_rgb_fill(self.hsv_to_rgbw(hue, sat, val))
|
||||||
else:
|
else:
|
||||||
self.neopixel.fill(self.hsv_to_rgb(hue, sat, val))
|
self.set_rgb_fill(self.hsv_to_rgb(hue, sat, val))
|
||||||
self.neopixel.show()
|
|
||||||
|
|
||||||
def set_rgb(self, rgb, index):
|
def set_rgb(self, rgb, index):
|
||||||
'''
|
'''
|
||||||
@ -172,9 +178,10 @@ class RGB:
|
|||||||
:param index: Index of LED/Pixel
|
:param index: Index of LED/Pixel
|
||||||
'''
|
'''
|
||||||
if self.neopixel:
|
if self.neopixel:
|
||||||
self.neopixel[index] = rgb
|
if index >=0 and index <= self.num_pixels - 1:
|
||||||
if not self.disable_auto_write:
|
self.neopixel[index] = rgb
|
||||||
self.neopixel.show()
|
if not self.disable_auto_write:
|
||||||
|
self.neopixel.show()
|
||||||
|
|
||||||
def set_rgb_fill(self, rgb):
|
def set_rgb_fill(self, rgb):
|
||||||
'''
|
'''
|
||||||
@ -183,7 +190,8 @@ class RGB:
|
|||||||
'''
|
'''
|
||||||
if self.neopixel:
|
if self.neopixel:
|
||||||
self.neopixel.fill(rgb)
|
self.neopixel.fill(rgb)
|
||||||
self.neopixel.show()
|
if not self.disable_auto_write:
|
||||||
|
self.neopixel.show()
|
||||||
|
|
||||||
def increase_hue(self, step):
|
def increase_hue(self, step):
|
||||||
'''
|
'''
|
||||||
@ -247,8 +255,7 @@ class RGB:
|
|||||||
Turns off all LEDs/Neopixels without changing stored values
|
Turns off all LEDs/Neopixels without changing stored values
|
||||||
'''
|
'''
|
||||||
if self.neopixel:
|
if self.neopixel:
|
||||||
if not self.disable_auto_write:
|
self.set_hsv_fill(0, 0, 0)
|
||||||
self.set_hsv_fill(0, 0, 0)
|
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
'''
|
'''
|
||||||
@ -262,6 +269,8 @@ class RGB:
|
|||||||
Activates a "step" in the animation based on the active mode
|
Activates a "step" in the animation based on the active mode
|
||||||
:return: Returns the new state in animation
|
:return: Returns the new state in animation
|
||||||
'''
|
'''
|
||||||
|
if self.effect_init:
|
||||||
|
self.init_effect()
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
if self.animation_mode == 'breathing':
|
if self.animation_mode == 'breathing':
|
||||||
return self.effect_breathing()
|
return self.effect_breathing()
|
||||||
@ -271,6 +280,8 @@ class RGB:
|
|||||||
return self.effect_breathing_rainbow()
|
return self.effect_breathing_rainbow()
|
||||||
elif self.animation_mode == 'static':
|
elif self.animation_mode == 'static':
|
||||||
return self.effect_static()
|
return self.effect_static()
|
||||||
|
elif self.animation_mode == 'knight':
|
||||||
|
return self.effect_knight()
|
||||||
else:
|
else:
|
||||||
self.off()
|
self.off()
|
||||||
|
|
||||||
@ -286,6 +297,11 @@ class RGB:
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def init_effect(self):
|
||||||
|
self.pos = 0
|
||||||
|
self.reverse_animation = False
|
||||||
|
self.effect_init = False
|
||||||
|
|
||||||
def effect_static(self):
|
def effect_static(self):
|
||||||
self.set_hsv_fill(self.hue, self.sat, self.val)
|
self.set_hsv_fill(self.hue, self.sat, self.val)
|
||||||
return self
|
return self
|
||||||
@ -314,16 +330,27 @@ class RGB:
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def effect_rainbow_swirl(self):
|
def effect_knight(self):
|
||||||
interval = self.animation_step()
|
# Determine which LEDs should be lit up
|
||||||
if interval:
|
self.disable_auto_write = True # Turn off instantly showing
|
||||||
for i in range(0, self.num_pixels):
|
self.off() # Fill all off
|
||||||
self.hue = (360 / self.num_pixels * i + self.hue) % 360
|
pos = floor(self.pos)
|
||||||
self.set_hsv_fill(self.hue, self.sat, self.val)
|
|
||||||
|
|
||||||
if interval % 2:
|
# Set all pixels on in range of animation length offset by position
|
||||||
self.increase_hue(self.animation_speed)
|
for i in range(pos, (pos + self.knight_effect_length)):
|
||||||
|
self.set_hsv(self.hue, self.sat, self.val, i)
|
||||||
|
|
||||||
|
# Reverse animation when a boundary is hit
|
||||||
|
if pos >= self.num_pixels or pos - 1 < (self.knight_effect_length * -1):
|
||||||
|
self.reverse_animation = not self.reverse_animation
|
||||||
|
|
||||||
|
if self.reverse_animation:
|
||||||
|
self.pos -= self.animation_speed / 5
|
||||||
else:
|
else:
|
||||||
self.decrease_hue(self.animation_speed)
|
self.pos += self.animation_speed / 5
|
||||||
|
|
||||||
|
# Show final results
|
||||||
|
self.disable_auto_write = False # Resume showing changes
|
||||||
|
self.show()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
@ -34,7 +34,9 @@ keyboard.hue_step = 5
|
|||||||
keyboard.sat_step = 5
|
keyboard.sat_step = 5
|
||||||
keyboard.val_step = 5
|
keyboard.val_step = 5
|
||||||
keyboard.hue_default = 260
|
keyboard.hue_default = 260
|
||||||
keyboard.animation_speed = 1
|
keyboard.knight_effect_length = 4
|
||||||
|
keyboard.animation_mode = 'knight'
|
||||||
|
keyboard.animation_speed = 2
|
||||||
|
|
||||||
OFF = (0, 0, 0)
|
OFF = (0, 0, 0)
|
||||||
BLUE = (0, 0, 100)
|
BLUE = (0, 0, 100)
|
||||||
@ -230,7 +232,7 @@ keyboard.keymap = [
|
|||||||
# r3
|
# r3
|
||||||
[KC.GESC, KC.RGB_HUI, KC.RGB_HUD, KC.RGB_SAI, KC.RGB_SAD, KC.RGB_VAI, KC.RGB_VAD, _______, KC.F10, KC.F11, KC.F12, KC.DEL],
|
[KC.GESC, KC.RGB_HUI, KC.RGB_HUD, KC.RGB_SAI, KC.RGB_SAD, KC.RGB_VAI, KC.RGB_VAD, _______, KC.F10, KC.F11, KC.F12, KC.DEL],
|
||||||
[KC.RGB_M_P, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS],
|
[KC.RGB_M_P, _______, _______, _______, _______, _______, _______, _______, KC.F7, KC.F8, KC.F9, SHFT_INS],
|
||||||
[KC.RGB_M_B, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU],
|
[KC.RGB_M_K, _______, _______, _______, _______, _______, _______, _______, KC.F4, KC.F5, KC.F6, KC.VOLU],
|
||||||
[KC.RGB_M_BR, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD],
|
[KC.RGB_M_BR, _______, _______, _______, _______, _______, _______, _______, KC.F1, KC.F2, KC.F4, KC.VOLD],
|
||||||
[BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX],
|
[BASE, GAMING, _______, _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX],
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user