Initial RGB with test animation running automatically

This commit is contained in:
Kyle Brown
2019-02-09 13:12:04 -08:00
parent e332804dc9
commit 4b033857b1
3 changed files with 150 additions and 10 deletions

View File

@@ -49,6 +49,16 @@ import kmk.internal_state # isort:skip
# Thanks for sticking around. Now let's do real work, starting below
from kmk.util import intify_coordinate as ic
import busio
import gc
import supervisor
from kmk.consts import LeaderMode, UnicodeMode
from kmk.hid import USB_HID
from kmk.internal_state import InternalState
from kmk.keys import KC
from kmk.matrix import MatrixScanner
from kmk import rgb
class Firmware:
@@ -80,6 +90,10 @@ class Firmware:
uart = None
uart_flip = True
uart_pin = None
pixel_pin = None
num_pixels = None
pixels = None
pixel_state = 0, 0
def __init__(self):
# Attempt to sanely guess a coord_mapping if one is not provided
@@ -174,6 +188,14 @@ class Firmware:
else:
return busio.UART(tx=pin, rx=None, timeout=timeout)
def init_pixels(self, pixel_pin, num_pixels=0):
try:
import neopixel
return neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
except ImportError as e:
print(e)
return None
def go(self):
assert self.keymap, 'must define a keymap with at least one row'
assert self.row_pins, 'no GPIO pins defined for matrix rows'
@@ -194,7 +216,10 @@ class Firmware:
if self.uart_pin is not None:
self.uart = self.init_uart(self.uart_pin)
self.matrix = self.matrix_scanner(
if self.pixel_pin is not None:
self.pixels = self.init_pixels(self.pixel_pin, self.num_pixels)
self.matrix = MatrixScanner(
cols=self.col_pins,
rows=self.row_pins,
diode_orientation=self.diode_orientation,
@@ -214,6 +239,7 @@ class Firmware:
if self.debug_enabled:
print("Firin' lazers. Keyboard is booted.")
while True:
state_changed = False
@@ -248,3 +274,14 @@ class Firmware:
if self.debug_enabled and state_changed:
print('New State: {}'.format(self._state._to_dict()))
gc.collect()
test = rgb.color_chase(self.pixels,
self.num_pixels,
color=(255,0,0),
color2=(0,255,255),
animation_state=self.pixel_state[0])
if test is not None:
# Debugging some strange errors with NoneType
self.pixel_state = test