Initial attempt to merge internal_state with kmk_keyboard. Seems to work on Plank so far
fix formatting Example of new "Extension"/plugin system, using LED Cleanup of RGB code staticmethod to proper, normal methods Needs cleanup, but: migrate Leader to Extension API remove useless self reurns fix an AttributeError with Leader key removal Checkpoint from the weekend: split as an Extension (not working or done yet) wip
This commit is contained in:
147
kmk/rgb.py
147
kmk/rgb.py
@@ -1,98 +1,83 @@
|
||||
import neopixel
|
||||
import time
|
||||
from math import e, exp, pi, sin
|
||||
from micropython import const
|
||||
|
||||
rgb_config = {
|
||||
'pixels': None,
|
||||
'num_pixels': 0,
|
||||
'pixel_pin': None,
|
||||
'val_limit': 255,
|
||||
'hue_default': 0,
|
||||
'sat_default': 100,
|
||||
'rgb_order': (1, 0, 2), # GRB WS2812
|
||||
'val_default': 100,
|
||||
'hue_step': 1,
|
||||
'sat_step': 1,
|
||||
'val_step': 1,
|
||||
'animation_speed': 1,
|
||||
'breathe_center': 1.5, # 1.0-2.7
|
||||
'knight_effect_length': 3,
|
||||
'animation_mode': 'static',
|
||||
}
|
||||
from kmk.extensions import Extension
|
||||
|
||||
rgb_config = {}
|
||||
|
||||
|
||||
class RGB:
|
||||
hue = 0
|
||||
sat = 100
|
||||
val = 80
|
||||
class AnimationModes:
|
||||
OFF = 0
|
||||
STATIC = 1
|
||||
STATIC_STANDBY = 2
|
||||
BREATHING = 3
|
||||
USER = 4
|
||||
|
||||
|
||||
class RGB(Extension):
|
||||
pos = 0
|
||||
time = int(time.monotonic() * 10)
|
||||
intervals = (30, 20, 10, 5)
|
||||
animation_speed = 1
|
||||
enabled = True
|
||||
neopixel = None
|
||||
rgbw = False
|
||||
reverse_animation = False
|
||||
disable_auto_write = False
|
||||
animation_mode = 'static'
|
||||
|
||||
# Set by config
|
||||
num_pixels = None
|
||||
hue_step = None
|
||||
sat_step = None
|
||||
val_step = None
|
||||
breathe_center = None # 1.0-2.7
|
||||
knight_effect_length = None
|
||||
val_limit = None
|
||||
effect_init = False
|
||||
user_animation = None
|
||||
def __init__(
|
||||
self,
|
||||
pixel_pin,
|
||||
num_pixels=0,
|
||||
val_limit=255,
|
||||
hue_default=0,
|
||||
sat_default=100,
|
||||
rgb_order=(1, 0, 2), # GRB WS2812
|
||||
val_default=100,
|
||||
hue_step=1,
|
||||
sat_step=1,
|
||||
val_step=1,
|
||||
animation_speed=1,
|
||||
breathe_center=1.5, # 1.0-2.7
|
||||
knight_effect_length=3,
|
||||
animation_mode=AnimationModes.STATIC,
|
||||
effect_init=False,
|
||||
reverse_animation=False,
|
||||
user_animation=None,
|
||||
disable_auto_write=False,
|
||||
):
|
||||
self.neopixel = neopixel.NeoPixel(
|
||||
pixel_pin,
|
||||
num_pixels,
|
||||
pixel_order=rgb_order,
|
||||
auto_write=not disable_auto_write,
|
||||
)
|
||||
|
||||
def __init__(self, config, pixel_pin):
|
||||
try:
|
||||
import neopixel
|
||||
if len(rgb_order) == 4:
|
||||
self.rgbw = True
|
||||
|
||||
self.neopixel = neopixel.NeoPixel(
|
||||
pixel_pin,
|
||||
config['num_pixels'],
|
||||
pixel_order=config['rgb_order'],
|
||||
auto_write=False,
|
||||
)
|
||||
if len(config['rgb_order']) == 4:
|
||||
self.rgbw = True
|
||||
self.num_pixels = const(config['num_pixels'])
|
||||
self.hue_step = const(config['hue_step'])
|
||||
self.sat_step = const(config['sat_step'])
|
||||
self.val_step = const(config['val_step'])
|
||||
self.hue = const(config['hue_default'])
|
||||
self.sat = const(config['sat_default'])
|
||||
self.val = const(config['val_default'])
|
||||
self.breathe_center = const(config['breathe_center'])
|
||||
self.knight_effect_length = const(config['knight_effect_length'])
|
||||
self.val_limit = const(config['val_limit'])
|
||||
self.animation_mode = config['animation_mode']
|
||||
self.animation_speed = const(config['animation_speed'])
|
||||
if 'user_animation' in config:
|
||||
self.user_animation = config['user_animation']
|
||||
self.num_pixels = num_pixels
|
||||
self.hue_step = hue_step
|
||||
self.sat_step = sat_step
|
||||
self.val_step = val_step
|
||||
self.hue = hue_default
|
||||
self.sat = sat_default
|
||||
self.val = val_default
|
||||
self.breathe_center = breathe_center
|
||||
self.knight_effect_length = knight_effect_length
|
||||
self.val_limit = val_limit
|
||||
self.animation_mode = animation_mode
|
||||
self.animation_speed = animation_speed
|
||||
self.reverse_animation = reverse_animation
|
||||
self.user_animation = user_animation
|
||||
self.disable_auto_write = disable_auto_write
|
||||
|
||||
except ImportError as e:
|
||||
print(e)
|
||||
def during_bootup(self, keyboard):
|
||||
pass
|
||||
|
||||
def __repr__(self):
|
||||
return 'RGB({})'.format(self._to_dict())
|
||||
def after_hid_send(self, keyboard):
|
||||
if self.animation_mode:
|
||||
self.loopcounter += 1
|
||||
if self.loopcounter >= 7:
|
||||
self.animate()
|
||||
self.loopcounter = 0
|
||||
|
||||
def _to_dict(self):
|
||||
return {
|
||||
'hue': self.hue,
|
||||
'sat': self.sat,
|
||||
'val': self.val,
|
||||
'time': self.time,
|
||||
'intervals': self.intervals,
|
||||
'animation_mode': self.animation_mode,
|
||||
'animation_speed': self.animation_speed,
|
||||
'enabled': self.enabled,
|
||||
'neopixel': self.neopixel,
|
||||
'disable_auto_write': self.disable_auto_write,
|
||||
}
|
||||
return keyboard
|
||||
|
||||
def time_ms(self):
|
||||
return int(time.monotonic() * 1000)
|
||||
|
Reference in New Issue
Block a user