Actually bring up to date with master
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import gc
|
|
||||||
|
|
||||||
from kmk.extensions import Extension, InvalidExtensionEnvironment
|
from kmk.extensions import Extension, InvalidExtensionEnvironment
|
||||||
from kmk.handlers.stock import passthrough as handler_passthrough
|
from kmk.handlers.stock import passthrough as handler_passthrough
|
||||||
from kmk.keys import KC, make_key
|
from kmk.keys import KC, make_key
|
||||||
@@ -33,8 +31,6 @@ class Leader(Extension):
|
|||||||
on_release=handler_passthrough,
|
on_release=handler_passthrough,
|
||||||
)
|
)
|
||||||
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
def after_matrix_scan(self, keyboard_state, *args):
|
def after_matrix_scan(self, keyboard_state, *args):
|
||||||
if self._mode % 2 == 1:
|
if self._mode % 2 == 1:
|
||||||
keys_pressed = keyboard_state._keys_pressed
|
keys_pressed = keyboard_state._keys_pressed
|
||||||
@@ -64,7 +60,6 @@ class Leader(Extension):
|
|||||||
keyboard_state._hid_pending = False
|
keyboard_state._hid_pending = False
|
||||||
|
|
||||||
def _compile_sequences(self, sequences):
|
def _compile_sequences(self, sequences):
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
for k, v in sequences.items():
|
for k, v in sequences.items():
|
||||||
if not isinstance(k, tuple):
|
if not isinstance(k, tuple):
|
||||||
@@ -75,8 +70,6 @@ class Leader(Extension):
|
|||||||
if not isinstance(k, tuple):
|
if not isinstance(k, tuple):
|
||||||
del sequences[k]
|
del sequences[k]
|
||||||
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
return sequences
|
return sequences
|
||||||
|
|
||||||
def _handle_leader_sequence(self, keyboard_state):
|
def _handle_leader_sequence(self, keyboard_state):
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import busio
|
import busio
|
||||||
import gc
|
|
||||||
|
|
||||||
from kmk.extensions import Extension
|
from kmk.extensions import Extension
|
||||||
from kmk.kmktime import sleep_ms
|
from kmk.kmktime import sleep_ms
|
||||||
@@ -21,7 +20,7 @@ class Split(Extension):
|
|||||||
flip=False,
|
flip=False,
|
||||||
side=None,
|
side=None,
|
||||||
stype=None,
|
stype=None,
|
||||||
master_left=True,
|
target_left=True,
|
||||||
uart_flip=True,
|
uart_flip=True,
|
||||||
uart_pin=None,
|
uart_pin=None,
|
||||||
uart_timeout=20,
|
uart_timeout=20,
|
||||||
@@ -31,8 +30,9 @@ class Split(Extension):
|
|||||||
self.split_flip = flip
|
self.split_flip = flip
|
||||||
self.split_side = side
|
self.split_side = side
|
||||||
self.split_type = stype
|
self.split_type = stype
|
||||||
self.split_master_left = master_left
|
self.split_target_left = target_left
|
||||||
self._uart = None
|
self._uart = None
|
||||||
|
self._uart_buffer = []
|
||||||
self.uart_flip = uart_flip
|
self.uart_flip = uart_flip
|
||||||
self.uart_pin = uart_pin
|
self.uart_pin = uart_pin
|
||||||
self.uart_timeout = uart_timeout
|
self.uart_timeout = uart_timeout
|
||||||
@@ -42,25 +42,25 @@ class Split(Extension):
|
|||||||
try:
|
try:
|
||||||
# Working around https://github.com/adafruit/circuitpython/issues/1769
|
# Working around https://github.com/adafruit/circuitpython/issues/1769
|
||||||
keyboard._hid_helper_inst.create_report([]).send()
|
keyboard._hid_helper_inst.create_report([]).send()
|
||||||
self._is_master = True
|
self._is_target = True
|
||||||
|
|
||||||
# Sleep 2s so master portion doesn't "appear" to boot quicker than
|
# 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)
|
# dependent portions (which will take ~2s to time out on the HID send)
|
||||||
sleep_ms(2000)
|
sleep_ms(2000)
|
||||||
except OSError:
|
except OSError:
|
||||||
self._is_master = False
|
self._is_target = False
|
||||||
|
|
||||||
if self.split_flip and not self._is_master:
|
if self.split_flip and not self._is_target:
|
||||||
keyboard.col_pins = list(reversed(self.col_pins))
|
keyboard.col_pins = list(reversed(keyboard.col_pins))
|
||||||
if self.split_side == 'Left':
|
if self.split_side == 'Left':
|
||||||
self.split_master_left = self._is_master
|
self.split_target_left = self._is_target
|
||||||
elif self.split_side == 'Right':
|
elif self.split_side == 'Right':
|
||||||
self.split_master_left = not self._is_master
|
self.split_target_left = not self._is_target
|
||||||
else:
|
else:
|
||||||
self._is_master = True
|
self._is_target = True
|
||||||
|
|
||||||
if self.uart_pin is not None:
|
if self.uart_pin is not None:
|
||||||
if self._is_master:
|
if self._is_target:
|
||||||
self._uart = busio.UART(
|
self._uart = busio.UART(
|
||||||
tx=None, rx=self.uart_pin, timeout=self.uart_timeout
|
tx=None, rx=self.uart_pin, timeout=self.uart_timeout
|
||||||
)
|
)
|
||||||
@@ -84,20 +84,35 @@ class Split(Extension):
|
|||||||
for cidx in range(cols_to_calc):
|
for cidx in range(cols_to_calc):
|
||||||
keyboard.coord_mapping.append(intify_coordinate(ridx, cidx))
|
keyboard.coord_mapping.append(intify_coordinate(ridx, cidx))
|
||||||
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
def before_matrix_scan(self, keyboard_state):
|
def before_matrix_scan(self, keyboard_state):
|
||||||
if self.split_type is not None and self._is_master:
|
if self.split_type is not None and self._is_target:
|
||||||
return self._receive_from_slave()
|
return self._receive_from_initiator()
|
||||||
|
|
||||||
def after_matrix_scan(self, keyboard_state, matrix_update):
|
def after_matrix_scan(self, keyboard_state, matrix_update):
|
||||||
if matrix_update is not None and not self._is_master:
|
if matrix_update is not None and not self._is_target:
|
||||||
self._send_to_master(matrix_update)
|
self._send_to_target(matrix_update)
|
||||||
|
|
||||||
def _send_to_master(self, update):
|
def _send_to_target(self, update):
|
||||||
if self.split_master_left:
|
if self.split_target_left:
|
||||||
update[1] += self.split_offsets[update[0]]
|
update[1] += self.split_offsets[update[0]]
|
||||||
else:
|
else:
|
||||||
update[1] -= self.split_offsets[update[0]]
|
update[1] -= self.split_offsets[update[0]]
|
||||||
if self._uart is not None:
|
if self._uart is not None:
|
||||||
self._uart.write(update)
|
self._uart.write(update)
|
||||||
|
|
||||||
|
def _receive_from_initiator(self):
|
||||||
|
if self._uart is not None and self._uart.in_waiting > 0 or self._uart_buffer:
|
||||||
|
if self._uart.in_waiting >= 60:
|
||||||
|
# This is a dirty hack to prevent crashes in unrealistic cases
|
||||||
|
import microcontroller
|
||||||
|
|
||||||
|
microcontroller.reset()
|
||||||
|
|
||||||
|
while self._uart.in_waiting >= 3:
|
||||||
|
self._uart_buffer.append(self._uart.read(3))
|
||||||
|
if self._uart_buffer:
|
||||||
|
update = bytearray(self._uart_buffer.pop(0))
|
||||||
|
|
||||||
|
return update
|
||||||
|
|
||||||
|
return None
|
||||||
|
@@ -221,3 +221,7 @@ class USBHID(AbstractHID):
|
|||||||
return self.devices[reporting_device_const].send_report(
|
return self.devices[reporting_device_const].send_report(
|
||||||
evt[1 : HID_REPORT_SIZES[reporting_device_const] + 1]
|
evt[1 : HID_REPORT_SIZES[reporting_device_const] + 1]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BLEHID(AbstractHID):
|
||||||
|
pass
|
||||||
|
@@ -3,8 +3,6 @@
|
|||||||
# a line into their keymaps.
|
# a line into their keymaps.
|
||||||
import kmk.preload_imports # isort:skip # NOQA
|
import kmk.preload_imports # isort:skip # NOQA
|
||||||
|
|
||||||
import gc
|
|
||||||
|
|
||||||
from kmk import rgb
|
from kmk import rgb
|
||||||
from kmk.consts import KMK_RELEASE, UnicodeMode
|
from kmk.consts import KMK_RELEASE, UnicodeMode
|
||||||
from kmk.hid import BLEHID, USBHID, AbstractHID, HIDModes
|
from kmk.hid import BLEHID, USBHID, AbstractHID, HIDModes
|
||||||
@@ -99,20 +97,11 @@ class KMKKeyboard:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _print_debug_cycle(self, init=False):
|
def _print_debug_cycle(self, init=False):
|
||||||
pre_alloc = gc.mem_alloc()
|
|
||||||
pre_free = gc.mem_free()
|
|
||||||
|
|
||||||
if self.debug_enabled:
|
if self.debug_enabled:
|
||||||
if init:
|
if init:
|
||||||
print('KMKInit(release={})'.format(KMK_RELEASE))
|
print('KMKInit(release={})'.format(KMK_RELEASE))
|
||||||
|
|
||||||
print(self)
|
print(self)
|
||||||
print(self)
|
|
||||||
print(
|
|
||||||
'GCStats(pre_alloc={} pre_free={} alloc={} free={})'.format(
|
|
||||||
pre_alloc, pre_free, gc.mem_alloc(), gc.mem_free()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _send_hid(self):
|
def _send_hid(self):
|
||||||
self._hid_helper_inst.create_report(self._keys_pressed).send()
|
self._hid_helper_inst.create_report(self._keys_pressed).send()
|
||||||
@@ -366,23 +355,10 @@ class KMKKeyboard:
|
|||||||
if self.hid_type == HIDModes.NOOP:
|
if self.hid_type == HIDModes.NOOP:
|
||||||
self.hid_helper = AbstractHID
|
self.hid_helper = AbstractHID
|
||||||
elif self.hid_type == HIDModes.USB:
|
elif self.hid_type == HIDModes.USB:
|
||||||
try:
|
|
||||||
from kmk.hid import USBHID
|
|
||||||
|
|
||||||
self.hid_helper = USBHID
|
self.hid_helper = USBHID
|
||||||
except ImportError:
|
|
||||||
self.hid_helper = AbstractHID
|
|
||||||
print('USB HID is unsupported ')
|
|
||||||
elif self.hid_type == HIDModes.BLE:
|
elif self.hid_type == HIDModes.BLE:
|
||||||
try:
|
|
||||||
from kmk.ble import BLEHID
|
|
||||||
|
|
||||||
self.hid_helper = BLEHID
|
self.hid_helper = BLEHID
|
||||||
except ImportError:
|
self._hid_helper_inst = self.hid_helper()
|
||||||
self.hid_helper = AbstractHID
|
|
||||||
print('Bluetooth is unsupported ')
|
|
||||||
|
|
||||||
self._hid_helper_inst = self.hid_helper(**kwargs)
|
|
||||||
|
|
||||||
def _init_matrix(self):
|
def _init_matrix(self):
|
||||||
self.matrix = MatrixScanner(
|
self.matrix = MatrixScanner(
|
||||||
@@ -402,7 +378,7 @@ class KMKKeyboard:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
gc.collect()
|
pass
|
||||||
|
|
||||||
self.hid_type = hid_type
|
self.hid_type = hid_type
|
||||||
|
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
# First, system-provided deps
|
# First, system-provided deps
|
||||||
import busio
|
import busio
|
||||||
import collections
|
import collections
|
||||||
import gc
|
|
||||||
import supervisor
|
import supervisor
|
||||||
|
|
||||||
# Now "light" KMK stuff with few/no external deps
|
# Now "light" KMK stuff with few/no external deps
|
||||||
|
Reference in New Issue
Block a user