Added support for user animations with docs
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import time
|
||||
from math import e, exp, pi, sin
|
||||
from micropython import const
|
||||
|
||||
import pulseio
|
||||
from micropython import const
|
||||
|
||||
led_config = {
|
||||
'brightness_step': 5,
|
||||
@@ -12,6 +12,7 @@ led_config = {
|
||||
'animation_speed': 1,
|
||||
}
|
||||
|
||||
|
||||
class led:
|
||||
brightness = 0
|
||||
time = int(time.monotonic() * 1000)
|
||||
@@ -25,6 +26,7 @@ class led:
|
||||
animation_mode = 'static'
|
||||
animation_speed = 1
|
||||
enabled = True
|
||||
user_animation = None
|
||||
|
||||
def __init__(self, led_pin, config):
|
||||
self.led = pulseio.PWMOut(led_pin)
|
||||
@@ -33,6 +35,8 @@ class led:
|
||||
self.animation_mode = const(config['animation_mode'])
|
||||
self.animation_speed = const(config['animation_speed'])
|
||||
self.breathe_center = const(config['breathe_center'])
|
||||
if config['user_animation']:
|
||||
self.user_animation = config['user_animation']
|
||||
|
||||
def __repr__(self):
|
||||
return 'LED({})'.format(self._to_dict())
|
||||
@@ -131,6 +135,8 @@ class led:
|
||||
return self.effect_breathing()
|
||||
elif self.animation_mode == 'static':
|
||||
return self.effect_static()
|
||||
elif self.animation_mode == 'user':
|
||||
return self.user_animation(self)
|
||||
else:
|
||||
self.off()
|
||||
|
||||
|
11
kmk/rgb.py
11
kmk/rgb.py
@@ -1,5 +1,6 @@
|
||||
import time
|
||||
from math import e, exp, pi, sin
|
||||
|
||||
from micropython import const
|
||||
|
||||
rgb_config = {
|
||||
@@ -7,7 +8,7 @@ rgb_config = {
|
||||
'num_pixels': 0,
|
||||
'pixel_pin': None,
|
||||
'val_limit': 255,
|
||||
'hue_default' : 0,
|
||||
'hue_default': 0,
|
||||
'sat_default': 100,
|
||||
'rgb_order': (1, 0, 2), # GRB WS2812
|
||||
'val_default': 100,
|
||||
@@ -17,9 +18,10 @@ rgb_config = {
|
||||
'animation_speed': 1,
|
||||
'breathe_center': 1.5, # 1.0-2.7
|
||||
'knight_effect_length': 3,
|
||||
'animation_mode': 'static'
|
||||
'animation_mode': 'static',
|
||||
}
|
||||
|
||||
|
||||
class RGB:
|
||||
hue = 0
|
||||
sat = 100
|
||||
@@ -44,6 +46,7 @@ class RGB:
|
||||
knight_effect_length = None
|
||||
val_limit = None
|
||||
effect_init = False
|
||||
user_animation = None
|
||||
|
||||
def __init__(self, config, pixel_pin):
|
||||
try:
|
||||
@@ -66,6 +69,8 @@ class RGB:
|
||||
self.val_limit = const(config['val_limit'])
|
||||
self.rgb_animation_mode = const(config['animation_mode'])
|
||||
self.animation_speed = const(config['animation_speed'])
|
||||
if config['user_animation']:
|
||||
self.user_animation = config['user_animation']
|
||||
|
||||
except ImportError as e:
|
||||
print(e)
|
||||
@@ -374,6 +379,8 @@ class RGB:
|
||||
return self.effect_knight()
|
||||
elif self.animation_mode == 'swirl':
|
||||
return self.effect_swirl()
|
||||
elif self.animation_mode == 'user':
|
||||
return self.user_animation(self)
|
||||
elif self.animation_mode == 'static_standby':
|
||||
pass
|
||||
else:
|
||||
|
Reference in New Issue
Block a user