allow matrix sync on BLE split
typo
This commit is contained in:
@@ -22,6 +22,7 @@ class BLE_Split(Extension):
|
|||||||
self._is_target = True
|
self._is_target = True
|
||||||
self._connection_count = 0
|
self._connection_count = 0
|
||||||
self._uart = None
|
self._uart = None
|
||||||
|
self._uart_connection = None
|
||||||
self._advertisment = None
|
self._advertisment = None
|
||||||
self._advertising = False
|
self._advertising = False
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ class BLE_Split(Extension):
|
|||||||
|
|
||||||
self.connect()
|
self.connect()
|
||||||
# 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:
|
if not keyboard.coord_mapping or (self.split_flip and not self._is_target):
|
||||||
keyboard.coord_mapping = []
|
keyboard.coord_mapping = []
|
||||||
|
|
||||||
rows_to_calc = len(keyboard.row_pins)
|
rows_to_calc = len(keyboard.row_pins)
|
||||||
@@ -58,12 +59,11 @@ class BLE_Split(Extension):
|
|||||||
|
|
||||||
def before_matrix_scan(self, keyboard_state):
|
def before_matrix_scan(self, keyboard_state):
|
||||||
self.check_all_connections()
|
self.check_all_connections()
|
||||||
if self._is_target:
|
return self._receive()
|
||||||
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_target:
|
if matrix_update:
|
||||||
self._send_to_target(matrix_update)
|
self._send(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)
|
||||||
@@ -83,39 +83,30 @@ class BLE_Split(Extension):
|
|||||||
|
|
||||||
def initiator_scan(self):
|
def initiator_scan(self):
|
||||||
self._uart = None
|
self._uart = None
|
||||||
|
self._uart_connection = None
|
||||||
# See if any existing connections are providing UARTService.
|
# See if any existing connections are providing UARTService.
|
||||||
self._connection_count = len(self._ble.connections)
|
self._connection_count = len(self._ble.connections)
|
||||||
if self._connection_count > 0 and not self._uart:
|
if self._connection_count > 0 and not self._uart:
|
||||||
for connection in self._ble.connections:
|
for connection in self._ble.connections:
|
||||||
if UARTService in connection:
|
if UARTService in connection:
|
||||||
self._uart = connection
|
self._uart_connection = connection
|
||||||
|
self._uart = self._uart_connection[UARTService]
|
||||||
break
|
break
|
||||||
|
|
||||||
if not self._uart:
|
if not self._uart:
|
||||||
print('Scanning')
|
print('Scanning')
|
||||||
|
self._ble.stop_scan()
|
||||||
for adv in self._ble.start_scan(ProvideServicesAdvertisement, timeout=20):
|
for adv in self._ble.start_scan(ProvideServicesAdvertisement, timeout=20):
|
||||||
print('Scanning')
|
print('Scanning')
|
||||||
if UARTService in adv.services:
|
if UARTService in adv.services:
|
||||||
self._uart = self._ble.connect(adv)
|
self._uart_connection = self._ble.connect(adv)
|
||||||
|
self._uart = self._uart_connection[UARTService]
|
||||||
self._ble.stop_scan()
|
self._ble.stop_scan()
|
||||||
print('Scan complete')
|
print('Scan complete')
|
||||||
break
|
break
|
||||||
self._ble.stop_scan()
|
self._ble.stop_scan()
|
||||||
return
|
return
|
||||||
|
|
||||||
def send(self, data):
|
|
||||||
if self._uart and self._uart.connected:
|
|
||||||
try:
|
|
||||||
self._uart[UARTService].write(data)
|
|
||||||
except OSError:
|
|
||||||
try:
|
|
||||||
self._uart.disconnect()
|
|
||||||
except: # noqa: E722
|
|
||||||
print('UART disconnect failed')
|
|
||||||
print('Connection error')
|
|
||||||
self._uart = None
|
|
||||||
return
|
|
||||||
|
|
||||||
def target_advertise(self):
|
def target_advertise(self):
|
||||||
self._ble.stop_advertising()
|
self._ble.stop_advertising()
|
||||||
print('Advertising')
|
print('Advertising')
|
||||||
@@ -145,12 +136,23 @@ class BLE_Split(Extension):
|
|||||||
self._ble_last_scan = ticks_ms()
|
self._ble_last_scan = ticks_ms()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def _send_to_target(self, update):
|
def _send(self, update):
|
||||||
update[1] += self.split_offsets[update[0]]
|
if self._uart:
|
||||||
if self._uart is not None and self._uart.connected:
|
try:
|
||||||
self.send(update)
|
if not self._is_target:
|
||||||
|
update[1] += self.split_offsets[update[0]]
|
||||||
|
self._uart.write(update)
|
||||||
|
except OSError:
|
||||||
|
try:
|
||||||
|
self._uart.disconnect()
|
||||||
|
except: # noqa: E722
|
||||||
|
print('UART disconnect failed')
|
||||||
|
print('Connection error')
|
||||||
|
self._uart_connection = None
|
||||||
|
self._uart = None
|
||||||
|
return
|
||||||
|
|
||||||
def _receive_from_initiator(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:
|
||||||
while self._uart.in_waiting >= 3:
|
while self._uart.in_waiting >= 3:
|
||||||
self._uart_buffer.append(self._uart.read(3))
|
self._uart_buffer.append(self._uart.read(3))
|
||||||
|
@@ -2,7 +2,7 @@ from kmk.extensions import Extension
|
|||||||
from kmk.keys import make_consumer_key
|
from kmk.keys import make_consumer_key
|
||||||
|
|
||||||
|
|
||||||
class Layers(Extension):
|
class MediaKeys(Extension):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Consumer ("media") keys. Most known keys aren't supported here. A much
|
# Consumer ("media") keys. Most known keys aren't supported here. A much
|
||||||
# longer list used to exist in this file, but the codes were almost certainly
|
# longer list used to exist in this file, but the codes were almost certainly
|
||||||
|
@@ -62,8 +62,11 @@ class RGB(Extension):
|
|||||||
self.sat_step = sat_step
|
self.sat_step = sat_step
|
||||||
self.val_step = val_step
|
self.val_step = val_step
|
||||||
self.hue = hue_default
|
self.hue = hue_default
|
||||||
|
self.hue_default = hue_default
|
||||||
self.sat = sat_default
|
self.sat = sat_default
|
||||||
|
self.sat_default = sat_default
|
||||||
self.val = val_default
|
self.val = val_default
|
||||||
|
self.val_default = val_default
|
||||||
self.breathe_center = breathe_center
|
self.breathe_center = breathe_center
|
||||||
self.knight_effect_length = knight_effect_length
|
self.knight_effect_length = knight_effect_length
|
||||||
self.val_limit = val_limit
|
self.val_limit = val_limit
|
||||||
@@ -132,6 +135,11 @@ class RGB(Extension):
|
|||||||
on_press=self._rgb_mode_knight,
|
on_press=self._rgb_mode_knight,
|
||||||
on_release=handler_passthrough,
|
on_release=handler_passthrough,
|
||||||
)
|
)
|
||||||
|
make_key(
|
||||||
|
names=('RGB_RESET', 'RGB_RST'),
|
||||||
|
on_press=self._rgb_reset,
|
||||||
|
on_release=handler_passthrough,
|
||||||
|
)
|
||||||
|
|
||||||
def after_hid_send(self, keyboard):
|
def after_hid_send(self, keyboard):
|
||||||
if self.animation_mode:
|
if self.animation_mode:
|
||||||
@@ -611,3 +619,12 @@ class RGB(Extension):
|
|||||||
self.effect_init = True
|
self.effect_init = True
|
||||||
self.animation_mode = AnimationModes.KNIGHT
|
self.animation_mode = AnimationModes.KNIGHT
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
def _rgb_reset(self, key, state, *args, **kwargs):
|
||||||
|
self.hue = self.hue_default
|
||||||
|
self.sat = self.sat_default
|
||||||
|
self.val = self.val_default
|
||||||
|
if self.animation_mode == AnimationModes.STATIC_STANDBY:
|
||||||
|
self.animation_mode = AnimationModes.STATIC
|
||||||
|
self._do_update()
|
||||||
|
return state
|
||||||
|
@@ -79,13 +79,13 @@ class Split(Extension):
|
|||||||
|
|
||||||
def before_matrix_scan(self, keyboard_state):
|
def before_matrix_scan(self, keyboard_state):
|
||||||
if self._is_target:
|
if self._is_target:
|
||||||
return self._receive_from_initiator()
|
return self._receive()
|
||||||
|
|
||||||
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_target:
|
if matrix_update is not None and not self._is_target:
|
||||||
self._send_to_target(matrix_update)
|
self._send(matrix_update)
|
||||||
|
|
||||||
def _send_to_target(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_offsets[update[0]]
|
||||||
else:
|
else:
|
||||||
@@ -93,7 +93,7 @@ class Split(Extension):
|
|||||||
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):
|
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:
|
||||||
if self._uart.in_waiting >= 60:
|
if self._uart.in_waiting >= 60:
|
||||||
# This is a dirty hack to prevent crashes in unrealistic cases
|
# This is a dirty hack to prevent crashes in unrealistic cases
|
||||||
|
@@ -2,7 +2,6 @@ import board
|
|||||||
|
|
||||||
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.leader import Leader, LeaderMode
|
|
||||||
from kmk.extensions.rgb import RGB
|
from kmk.extensions.rgb import RGB
|
||||||
from kmk.handlers.sequences import send_string, simple_key_sequence
|
from kmk.handlers.sequences import send_string, simple_key_sequence
|
||||||
from kmk.hid import HIDModes
|
from kmk.hid import HIDModes
|
||||||
@@ -20,22 +19,15 @@ TAB_SB = KC.LT(5, KC.TAB)
|
|||||||
SUPER_L = KC.LM(4, KC.LGUI)
|
SUPER_L = KC.LM(4, KC.LGUI)
|
||||||
|
|
||||||
keyboard.tap_time = 300
|
keyboard.tap_time = 300
|
||||||
keyboard.leader_timeout = 2000
|
|
||||||
keyboard.debug_enabled = False
|
keyboard.debug_enabled = False
|
||||||
|
|
||||||
leader_ext = Leader(mode=LeaderMode.ENTER, sequences={
|
|
||||||
'hello': send_string('hello world from kmk macros'),
|
|
||||||
'ls': KC.LGUI(KC.HOME),
|
|
||||||
'dbg': KC.DBG,
|
|
||||||
})
|
|
||||||
|
|
||||||
# TODO Get this out of here
|
# TODO Get this out of here
|
||||||
split_offsets = [6, 6, 6, 6]
|
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_offsets=split_offsets, split_side=split_side)
|
||||||
keyboard.extensions = [leader_ext, split, rgb_ext]
|
keyboard.extensions = [split, rgb_ext]
|
||||||
|
|
||||||
keyboard.keymap = [
|
keyboard.keymap = [
|
||||||
# DVORAK
|
# DVORAK
|
||||||
@@ -55,7 +47,7 @@ keyboard.keymap = [
|
|||||||
KC.GESC, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BSPC, \
|
KC.GESC, KC.QUOT, KC.COMM, KC.DOT, KC.P, KC.Y, KC.F, KC.G, KC.C, KC.R, KC.L, KC.BSPC, \
|
||||||
TAB_SB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT, \
|
TAB_SB, KC.A, KC.O, KC.E, KC.U, KC.I, KC.D, KC.H, KC.T, KC.N, KC.S, KC.ENT, \
|
||||||
KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH, \
|
KC.LSFT, KC.SCLN, KC.Q, KC.J, KC.K, KC.X, KC.B, KC.M, KC.W, KC.V, KC.Z, KC.SLSH, \
|
||||||
KC.LALT, SUPER_L, LT1_SP, LT2_SP, KC.LCTL, KC.LEAD,
|
KC.LALT, SUPER_L, LT1_SP, LT2_SP, KC.LCTL, XXXXXXX,
|
||||||
],
|
],
|
||||||
|
|
||||||
# GAMING
|
# GAMING
|
||||||
@@ -150,9 +142,9 @@ keyboard.keymap = [
|
|||||||
#
|
#
|
||||||
[
|
[
|
||||||
# SYMBOLS
|
# SYMBOLS
|
||||||
KC.LEAD, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.DEL, \
|
_______, KC.EXLM, KC.AT, KC.HASH, KC.DLR, KC.PERC, KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.DEL, \
|
||||||
_______, KC.RGB_HUI, KC.RGB_HUD, KC.RGB_VAI, KC.RGB_VAD, _______, _______, _______, _______, KC.LBRC, KC.RBRC, _______, \
|
_______, KC.RGB_HUI, KC.RGB_HUD, KC.RGB_VAI, KC.RGB_VAD, _______, _______, _______, _______, KC.LBRC, KC.RBRC, _______, \
|
||||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
|
_______, KC.RGB_RST, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
|
||||||
KC.RGB_TOG, _______, _______, _______, _______, _______,
|
KC.RGB_TOG, _______, _______, _______, _______, _______,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user