fixed splits. Enabled extensions on nyquist

This commit is contained in:
Kyle Brown
2020-10-23 18:10:19 -07:00
parent 54592a01b0
commit a7b44699b5
4 changed files with 46 additions and 39 deletions

View File

@@ -1,5 +1,7 @@
import board
from kmk.extensions.rgb import RGB
from kmk.extensions.split import Split
from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard
from kmk.matrix import DiodeOrientation
@@ -15,3 +17,17 @@ class KMKKeyboard(_KMKKeyboard):
uart_pin = board.SCL
rgb_pixel_pin = board.TX
extra_data_pin = board.SDA
rgb_ext = RGB(
pixel_pin=board.TX,
num_pixels=12,
val_limit=150,
hue_step=10,
sat_step=5,
val_step=5,
hue_default=260,
sat_default=100,
val_default=40,
animation_speed=1,
)
split = Split(uart_pin=board.SCL, split_offsets=[6, 6, 6, 6, 6])
extensions = [rgb_ext, split]

View File

@@ -1,7 +1,6 @@
import busio
from kmk.extensions import Extension
from kmk.kmktime import sleep_ms
from kmk.matrix import intify_coordinate
@@ -16,20 +15,20 @@ class Split(Extension):
def __init__(
self,
extra_data_pin=None,
offsets=(),
flip=False,
side=None,
stype=None,
split_offsets=None,
split_flip=True,
split_side=None,
split_type=SplitType.UART,
target_left=True,
uart_flip=True,
uart_pin=None,
uart_timeout=20,
):
self.extra_data_pin = extra_data_pin
self.split_offsets = offsets
self.split_flip = flip
self.split_side = side
self.split_type = stype
self.split_offsets = split_offsets
self.split_flip = split_flip
self.split_side = split_side
self.split_type = split_type
self.split_target_left = target_left
self._uart = None
self._uart_buffer = []
@@ -38,26 +37,20 @@ class Split(Extension):
self.uart_timeout = uart_timeout
def during_bootup(self, keyboard):
if self.split_type is not None:
try:
# Working around https://github.com/adafruit/circuitpython/issues/1769
keyboard._hid_helper_inst.create_report([]).send()
self._is_target = True
# Sleep 2s so target portion doesn't "appear" to boot quicker than
# dependent portions (which will take ~2s to time out on the HID send)
sleep_ms(2000)
except OSError:
self._is_target = False
if self.split_flip and not self._is_target:
keyboard.col_pins = list(reversed(keyboard.col_pins))
if self.split_side == 'Left':
self.split_target_left = self._is_target
elif self.split_side == 'Right':
self.split_target_left = not self._is_target
else:
try:
# Working around https://github.com/adafruit/circuitpython/issues/1769
# keyboard._hid_helper_inst.create_report([]).send()
# Line above is broken and needs fixed for aut detection
self._is_target = True
except OSError:
self._is_target = False
if self.split_flip and not self._is_target:
keyboard.col_pins = list(reversed(keyboard.col_pins))
if self.split_side == 'Left':
self.split_target_left = self._is_target
elif self.split_side == 'Right':
self.split_target_left = not self._is_target
if self.uart_pin is not None:
if self._is_target:
@@ -68,7 +61,6 @@ class Split(Extension):
self._uart = busio.UART(
tx=self.uart_pin, rx=None, timeout=self.uart_timeout
)
# Attempt to sanely guess a coord_mapping if one is not provided.
if not keyboard.coord_mapping:
keyboard.coord_mapping = []

View File

@@ -341,7 +341,8 @@ class KMKKeyboard:
self._extensions = [] + getattr(self, 'extensions', [])
try:
print('EXTENSIONS', self.extensions)
if self.debug_enabled:
print('EXTENSIONS', self.extensions)
del self.extensions
except Exception:
pass
@@ -360,7 +361,9 @@ class KMKKeyboard:
except Exception:
# TODO FIXME log the exceptions or something
print('Failed to load ', ext)
pass
import time
time.sleep(30)
self._init_matrix()
@@ -373,7 +376,7 @@ class KMKKeyboard:
try:
self._handle_matrix_report(ext.before_matrix_scan(self))
except Exception as e:
print(e)
print('Failed to run pre matrix function: ', e)
matrix_update = self.matrix.scan_for_changes()
self._handle_matrix_report(matrix_update)
@@ -382,7 +385,7 @@ class KMKKeyboard:
try:
ext.after_matrix_scan(self, matrix_update)
except Exception as e:
print(e)
print('Failed to run post matrix function: ', e)
for ext in self._extensions:
try: