Simplify splits, expand extentions
This commit is contained in:
@@ -21,7 +21,6 @@ class KMKKeyboard(_KMKKeyboard):
|
|||||||
|
|
||||||
split_type = 'UART' # TODO add bluetooth support as well
|
split_type = 'UART' # TODO add bluetooth support as well
|
||||||
split_flip = True
|
split_flip = True
|
||||||
split_offsets = [6, 6, 6, 6, 6]
|
|
||||||
uart_pin = board.P0_08
|
uart_pin = board.P0_08
|
||||||
rgb_pixel_pin = board.P0_06
|
rgb_pixel_pin = board.P0_06
|
||||||
extra_data_pin = board.SDA # TODO This is incorrect. Find better solution
|
extra_data_pin = board.SDA # TODO This is incorrect. Find better solution
|
||||||
@@ -35,5 +34,5 @@ class KMKKeyboard(_KMKKeyboard):
|
|||||||
coord_mapping.extend(ic(3, x) for x in range(3, 9))
|
coord_mapping.extend(ic(3, x) for x in range(3, 9))
|
||||||
|
|
||||||
layers_ext = Layers()
|
layers_ext = Layers()
|
||||||
split = Split(uart_pin=uart_pin, split_offsets=split_offsets)
|
split = Split(uart_pin=uart_pin)
|
||||||
extensions = [layers_ext]
|
extensions = [layers_ext]
|
||||||
|
@@ -33,6 +33,9 @@ class Extension:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def after_matrix_scan(self, keyboard, matrix_update):
|
def after_matrix_scan(self, keyboard, matrix_update):
|
||||||
|
'''
|
||||||
|
Return value will be replace matrix update if supplied
|
||||||
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def before_hid_send(self, keyboard):
|
def before_hid_send(self, keyboard):
|
||||||
|
@@ -8,15 +8,13 @@ from kmk.matrix import intify_coordinate
|
|||||||
|
|
||||||
|
|
||||||
class BLE_Split(Extension):
|
class BLE_Split(Extension):
|
||||||
def __init__(
|
def __init__(self, split_flip=True, split_side=None, hid_type=HIDModes.BLE):
|
||||||
self, split_flip=True, split_side=None, split_offsets=[], hid_type=HIDModes.BLE
|
|
||||||
):
|
|
||||||
self._is_target = True
|
self._is_target = True
|
||||||
self._uart_buffer = []
|
self._uart_buffer = []
|
||||||
self.hid_type = hid_type
|
self.hid_type = hid_type
|
||||||
self.split_flip = split_flip
|
self.split_flip = split_flip
|
||||||
self.split_side = split_side
|
self.split_side = split_side
|
||||||
self.split_offsets = split_offsets
|
self.split_offset = None
|
||||||
self._ble = BLERadio()
|
self._ble = BLERadio()
|
||||||
self._ble_last_scan = ticks_ms() - 5000
|
self._ble_last_scan = ticks_ms() - 5000
|
||||||
self._is_target = True
|
self._is_target = True
|
||||||
@@ -30,28 +28,22 @@ class BLE_Split(Extension):
|
|||||||
return f'BLE_SPLIT({self._to_dict()})'
|
return f'BLE_SPLIT({self._to_dict()})'
|
||||||
|
|
||||||
def _to_dict(self):
|
def _to_dict(self):
|
||||||
return f'BLE_Split( _ble={self._ble} _ble_last_scan={self._ble_last_scan} _is_target={self._is_target} _uart_buffer={self._uart_buffer} _split_flip={self.split_flip} _split_side={self.split_side} _split_offsets={self.split_offsets} )'
|
return f'BLE_Split( _ble={self._ble} _ble_last_scan={self._ble_last_scan} _is_target={self._is_target} _uart_buffer={self._uart_buffer} _split_flip={self.split_flip} _split_side={self.split_side} )'
|
||||||
|
|
||||||
def during_bootup(self, keyboard):
|
def during_bootup(self, keyboard):
|
||||||
if self.split_side == 'Left':
|
self._is_target = bool(self.split_side == 'Left')
|
||||||
self._is_target = True
|
|
||||||
else:
|
|
||||||
self._is_target = False
|
|
||||||
|
|
||||||
if self.split_flip and not self._is_target:
|
if self.split_flip and not self._is_target:
|
||||||
keyboard.col_pins = list(reversed(keyboard.col_pins))
|
keyboard.col_pins = list(reversed(keyboard.col_pins))
|
||||||
|
|
||||||
self.connect()
|
self.split_offset = len(keyboard.col_pins)
|
||||||
|
|
||||||
# Attempt to sanely guess a coord_mapping if one is not provided.
|
# Attempt to sanely guess a coord_mapping if one is not provided.
|
||||||
if not keyboard.coord_mapping or (self.split_flip and not self._is_target):
|
if not keyboard.coord_mapping:
|
||||||
keyboard.coord_mapping = []
|
keyboard.coord_mapping = []
|
||||||
|
|
||||||
rows_to_calc = len(keyboard.row_pins)
|
rows_to_calc = len(keyboard.row_pins) * 2
|
||||||
cols_to_calc = len(keyboard.col_pins)
|
cols_to_calc = len(keyboard.col_pins) * 2
|
||||||
|
|
||||||
if self.split_offsets:
|
|
||||||
rows_to_calc *= 2
|
|
||||||
cols_to_calc *= 2
|
|
||||||
|
|
||||||
for ridx in range(rows_to_calc):
|
for ridx in range(rows_to_calc):
|
||||||
for cidx in range(cols_to_calc):
|
for cidx in range(cols_to_calc):
|
||||||
@@ -63,7 +55,8 @@ class BLE_Split(Extension):
|
|||||||
|
|
||||||
def after_matrix_scan(self, keyboard_state, matrix_update):
|
def after_matrix_scan(self, keyboard_state, matrix_update):
|
||||||
if matrix_update:
|
if matrix_update:
|
||||||
self._send(matrix_update)
|
matrix_update = self._send(matrix_update)
|
||||||
|
return matrix_update
|
||||||
|
|
||||||
def check_all_connections(self):
|
def check_all_connections(self):
|
||||||
self._connection_count = len(self._ble.connections)
|
self._connection_count = len(self._ble.connections)
|
||||||
@@ -140,7 +133,7 @@ class BLE_Split(Extension):
|
|||||||
if self._uart:
|
if self._uart:
|
||||||
try:
|
try:
|
||||||
if not self._is_target:
|
if not self._is_target:
|
||||||
update[1] += self.split_offsets[update[0]]
|
update[1] += self.split_offset
|
||||||
self._uart.write(update)
|
self._uart.write(update)
|
||||||
except OSError:
|
except OSError:
|
||||||
try:
|
try:
|
||||||
@@ -150,7 +143,7 @@ class BLE_Split(Extension):
|
|||||||
print('Connection error')
|
print('Connection error')
|
||||||
self._uart_connection = None
|
self._uart_connection = None
|
||||||
self._uart = None
|
self._uart = None
|
||||||
return
|
return update
|
||||||
|
|
||||||
def _receive(self):
|
def _receive(self):
|
||||||
if self._uart is not None and self._uart.in_waiting > 0 or self._uart_buffer:
|
if self._uart is not None and self._uart.in_waiting > 0 or self._uart_buffer:
|
||||||
@@ -158,14 +151,7 @@ class BLE_Split(Extension):
|
|||||||
self._uart_buffer.append(self._uart.read(3))
|
self._uart_buffer.append(self._uart.read(3))
|
||||||
if self._uart_buffer:
|
if self._uart_buffer:
|
||||||
update = bytearray(self._uart_buffer.pop(0))
|
update = bytearray(self._uart_buffer.pop(0))
|
||||||
|
|
||||||
return update
|
return update
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def ble_rescan_timer(self):
|
|
||||||
return bool(ticks_diff(ticks_ms(), self.ble_last_scan) > 5000)
|
|
||||||
|
|
||||||
def ble_time_reset(self):
|
|
||||||
self.ble_last_scan = ticks_ms()
|
|
||||||
return self
|
|
||||||
|
@@ -15,7 +15,7 @@ class Split(Extension):
|
|||||||
self,
|
self,
|
||||||
is_target=True,
|
is_target=True,
|
||||||
extra_data_pin=None,
|
extra_data_pin=None,
|
||||||
split_offsets=None,
|
split_offset=None,
|
||||||
split_flip=True,
|
split_flip=True,
|
||||||
split_side=None,
|
split_side=None,
|
||||||
split_type=SplitType.UART,
|
split_type=SplitType.UART,
|
||||||
@@ -26,7 +26,7 @@ class Split(Extension):
|
|||||||
):
|
):
|
||||||
self._is_target = is_target
|
self._is_target = is_target
|
||||||
self.extra_data_pin = extra_data_pin
|
self.extra_data_pin = extra_data_pin
|
||||||
self.split_offsets = split_offsets
|
self.split_offsets = split_offset
|
||||||
self.split_flip = split_flip
|
self.split_flip = split_flip
|
||||||
self.split_side = split_side
|
self.split_side = split_side
|
||||||
self.split_type = split_type
|
self.split_type = split_type
|
||||||
@@ -66,12 +66,10 @@ class Split(Extension):
|
|||||||
if not keyboard.coord_mapping:
|
if not keyboard.coord_mapping:
|
||||||
keyboard.coord_mapping = []
|
keyboard.coord_mapping = []
|
||||||
|
|
||||||
rows_to_calc = len(keyboard.row_pins)
|
self.split_offset = len(keyboard.col_pins)
|
||||||
cols_to_calc = len(keyboard.col_pins)
|
|
||||||
|
|
||||||
if self.split_offsets:
|
rows_to_calc = len(keyboard.row_pins) * 2
|
||||||
rows_to_calc *= 2
|
cols_to_calc = len(keyboard.col_pins) * 2
|
||||||
cols_to_calc *= 2
|
|
||||||
|
|
||||||
for ridx in range(rows_to_calc):
|
for ridx in range(rows_to_calc):
|
||||||
for cidx in range(cols_to_calc):
|
for cidx in range(cols_to_calc):
|
||||||
@@ -87,9 +85,9 @@ class Split(Extension):
|
|||||||
|
|
||||||
def _send(self, update):
|
def _send(self, update):
|
||||||
if self.split_target_left:
|
if self.split_target_left:
|
||||||
update[1] += self.split_offsets[update[0]]
|
update[1] += self.split_offset
|
||||||
else:
|
else:
|
||||||
update[1] -= self.split_offsets[update[0]]
|
update[1] -= self.split_offsets
|
||||||
if self._uart is not None:
|
if self._uart is not None:
|
||||||
self._uart.write(update)
|
self._uart.write(update)
|
||||||
|
|
||||||
|
@@ -36,6 +36,8 @@ class KMKKeyboard:
|
|||||||
_coord_keys_pressed = {}
|
_coord_keys_pressed = {}
|
||||||
_hid_helper = None
|
_hid_helper = None
|
||||||
_hid_pending = False
|
_hid_pending = False
|
||||||
|
_matrix_update = None
|
||||||
|
_matrix_modify = None
|
||||||
|
|
||||||
# this should almost always be PREpended to, replaces
|
# this should almost always be PREpended to, replaces
|
||||||
# former use of reversed_active_layers which had pointless
|
# former use of reversed_active_layers which had pointless
|
||||||
@@ -373,15 +375,21 @@ class KMKKeyboard:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to run pre matrix function: ', e)
|
print('Failed to run pre matrix function: ', e)
|
||||||
|
|
||||||
matrix_update = self.matrix.scan_for_changes()
|
self._matrix_update = self.matrix.scan_for_changes()
|
||||||
self._handle_matrix_report(matrix_update)
|
|
||||||
|
|
||||||
for ext in self.extensions:
|
for ext in self.extensions:
|
||||||
try:
|
try:
|
||||||
ext.after_matrix_scan(self, matrix_update)
|
self._matrix_modify = ext.after_matrix_scan(
|
||||||
|
self, self._matrix_update
|
||||||
|
)
|
||||||
|
if self._matrix_modify is not None:
|
||||||
|
self._matrix_update = self._matrix_modify
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to run post matrix function: ', e)
|
print('Failed to run post matrix function: ', e)
|
||||||
|
|
||||||
|
self._handle_matrix_report(self._matrix_update)
|
||||||
|
self._matrix_update = None
|
||||||
|
|
||||||
for ext in self.extensions:
|
for ext in self.extensions:
|
||||||
try:
|
try:
|
||||||
ext.before_hid_send(self)
|
ext.before_hid_send(self)
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
|
# OLED
|
||||||
import board
|
import board
|
||||||
|
|
||||||
|
import adafruit_displayio_ssd1306
|
||||||
|
import displayio
|
||||||
|
import terminalio
|
||||||
|
from adafruit_display_text import label
|
||||||
from kmk.boards.nice_nano.crkbd import KMKKeyboard
|
from kmk.boards.nice_nano.crkbd import KMKKeyboard
|
||||||
from kmk.extensions.ble_split import BLE_Split
|
from kmk.extensions.ble_split import BLE_Split
|
||||||
from kmk.extensions.rgb import RGB
|
from kmk.extensions.rgb import RGB
|
||||||
@@ -22,13 +27,19 @@ keyboard.tap_time = 300
|
|||||||
keyboard.debug_enabled = False
|
keyboard.debug_enabled = False
|
||||||
|
|
||||||
# TODO Get this out of here
|
# TODO Get this out of here
|
||||||
split_offsets = [6, 6, 6, 6]
|
|
||||||
rgb_pixel_pin = board.P0_06
|
rgb_pixel_pin = board.P0_06
|
||||||
rgb_ext = RGB(pixel_pin=rgb_pixel_pin, num_pixels=27, val_limit=100, hue_default=190, sat_default=100, val_default=5)
|
rgb_ext = RGB(pixel_pin=rgb_pixel_pin, num_pixels=27, val_limit=100, hue_default=190, sat_default=100, val_default=5)
|
||||||
|
|
||||||
split = BLE_Split(split_offsets=split_offsets, split_side=split_side)
|
split = BLE_Split(split_side=split_side)
|
||||||
keyboard.extensions = [split, rgb_ext]
|
keyboard.extensions = [split, rgb_ext]
|
||||||
|
|
||||||
|
displayio.release_displays()
|
||||||
|
i2c = board.I2C()
|
||||||
|
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
|
||||||
|
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
|
||||||
|
splash = displayio.Group(max_size=10)
|
||||||
|
display.show(splash)
|
||||||
|
|
||||||
keyboard.keymap = [
|
keyboard.keymap = [
|
||||||
# DVORAK
|
# DVORAK
|
||||||
# ,-----------------------------------------. ,-----------------------------------------.
|
# ,-----------------------------------------. ,-----------------------------------------.
|
||||||
|
Reference in New Issue
Block a user