requested changes

This commit is contained in:
Kyle Brown
2020-11-06 01:16:29 -08:00
parent 7a2bed8cdd
commit dea771fd7f
28 changed files with 263 additions and 158 deletions

View File

@@ -31,19 +31,20 @@ class BLE_Split(Extension):
self._advertising = False
self._uart_interval = uart_interval
self._psave_enable = False
self._debug_enabled = False
def __repr__(self):
return f'BLE_SPLIT({self._to_dict()})'
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} )
'''
return {
'_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 on_runtime_enable(self, keyboard):
return
@@ -52,15 +53,17 @@ class BLE_Split(Extension):
return
def during_bootup(self, keyboard):
self._debug_enabled = keyboard.debug_enabled
self._ble.name = str(getmount('/').label)
if self._ble.name.endswith('L'):
# If name ends in 'L' assume left and strip from name
self._is_target = True
elif self._ble.name.endswith('R'):
# If name ends in 'R' assume right and strip from name
self._is_target = False
else:
self._is_target = bool(self.split_side == 'Left')
if self.split_side is None:
if self._ble.name.endswith('L'):
# If name ends in 'L' assume left and strip from name
self._is_target = True
elif self._ble.name.endswith('R'):
# If name ends in 'R' assume right and strip from name
self._is_target = False
else:
self._is_target = bool(self.split_side == 0)
if self.split_flip and not self._is_target:
keyboard.col_pins = list(reversed(keyboard.col_pins))
@@ -127,23 +130,27 @@ class BLE_Split(Extension):
break
if not self._uart:
print('Scanning')
if self._debug_enabled:
print('Scanning')
self._ble.stop_scan()
for adv in self._ble.start_scan(ProvideServicesAdvertisement, timeout=20):
print('Scanning')
if self._debug_enabled:
print('Scanning')
if UARTService in adv.services and adv.rssi > -70:
self._uart_connection = self._ble.connect(adv)
self._uart_connection.connection_interval = 11.25
self._uart = self._uart_connection[UARTService]
self._ble.stop_scan()
print('Scan complete')
if self._debug_enabled:
print('Scan complete')
break
self._ble.stop_scan()
def _target_advertise(self):
'''Advertises the target for the initiator to find'''
self._ble.stop_advertising()
print('Advertising')
if self._debug_enabled:
print('Advertising')
# Uart must not change on this connection if reconnecting
if not self._uart:
self._uart = UARTService()
@@ -156,7 +163,8 @@ class BLE_Split(Extension):
self._connection_count = len(self._ble.connections)
if self._connection_count > 1:
self.ble_time_reset()
print('Advertising complete')
if self._debug_enabled:
print('Advertising complete')
break
self._ble.stop_advertising()
@@ -178,8 +186,11 @@ class BLE_Split(Extension):
try:
self._uart.disconnect()
except: # noqa: E722
print('UART disconnect failed')
print('Connection error')
if self._debug_enabled:
print('UART disconnect failed')
if self._debug_enabled:
print('Connection error')
self._uart_connection = None
self._uart = None
return update

View File

@@ -23,6 +23,12 @@ class Layers(Extension):
def __init__(self):
# Layers
self.start_time = {
LayerType.LT: None,
LayerType.TG: None,
LayerType.TT: None,
LayerType.LM: None,
}
make_argumented_key(
validator=layer_key_validator,
names=('MO',),
@@ -57,13 +63,6 @@ class Layers(Extension):
on_release=self._tt_released,
)
start_time = {
LayerType.LT: None,
LayerType.TG: None,
LayerType.TT: None,
LayerType.LM: None,
}
def on_runtime_enable(self, keyboard):
return

View File

@@ -64,7 +64,16 @@ class LED(Extension):
return 'LED({})'.format(self._to_dict())
def _to_dict(self):
return f'LED(_brightness={self._brightness} _pos={self._pos} brightness_step={self.brightness_step} brightness_limit={self.brightness_limit} animation_mode={self.animation_mode} animation_speed={self.animation_speed} breathe_center={self.breathe_center} val={self.val} )'
return {
'_brightness': self._brightness,
'_pos': self._pos,
'brightness_step': self.brightness_step,
'brightness_limit': self.brightness_limit,
'animation_mode': self.animation_mode,
'animation_speed': self.animation_speed,
'breathe_center': self.breathe_center,
'val': self.val,
}
def on_runtime_enable(self, keyboard):
return

View File

@@ -31,13 +31,13 @@ class Power(Extension):
return f'Power({self._to_dict()})'
def _to_dict(self):
return f'''Power(
enable={self.enable}
powersave_pin={self.powersave_pin}
_powersave_start={self._powersave_start}
_usb_last_scan={self._usb_last_scan}
_psp={self._psp} )
'''
return {
'enable': self.enable,
'powersave_pin': self.powersave_pin,
'_powersave_start': self._powersave_start,
'_usb_last_scan': self._usb_last_scan,
'_psp': self._psp,
}
def on_runtime_enable(self, keyboard):
return
@@ -82,7 +82,6 @@ class Power(Extension):
def enable_powersave(self, keyboard):
'''Enables power saving features'''
print('Psave True')
if keyboard.i2c_deinit_count >= self._i2c and self.powersave_pin:
# Allows power save to prevent RGB drain.
# Example here https://docs.nicekeyboards.com/#/nice!nano/pinout_schematic
@@ -96,7 +95,6 @@ class Power(Extension):
def disable_powersave(self):
'''Disables power saving features'''
print('Psave False')
if self.powersave_pin:
# Allows power save to prevent RGB drain.
# Example here https://docs.nicekeyboards.com/#/nice!nano/pinout_schematic

View File

@@ -52,19 +52,20 @@ class Split(Extension):
self._is_target = True
except OSError:
self._is_target = False
l_or_r = str(getmount('/').label)
if l_or_r.endswith('L'):
# If name ends in 'L' assume left and strip from name
self.split_side = 'Left'
elif l_or_r.endswith('R'):
# If name ends in 'R' assume right and strip from name
self.split_side = 'Right'
if self.split_side is None:
l_or_r = str(getmount('/').label)
if l_or_r.endswith('L'):
# If name ends in 'L' assume left and strip from name
self.split_side = 0
elif l_or_r.endswith('R'):
# If name ends in 'R' assume right and strip from name
self.split_side = 1
if self.split_flip and not self._is_target:
keyboard.col_pins = list(reversed(keyboard.col_pins))
if self.split_side == 'Left':
if self.split_side == 0:
self.split_target_left = self._is_target
elif self.split_side == 'Right':
elif self.split_side == 0:
self.split_target_left = not self._is_target
if self.uart_pin is not None: