memory improvements and fstring
This commit is contained in:
@@ -64,19 +64,7 @@ class LED(Extension):
|
|||||||
return 'LED({})'.format(self._to_dict())
|
return 'LED({})'.format(self._to_dict())
|
||||||
|
|
||||||
def _to_dict(self):
|
def _to_dict(self):
|
||||||
return (
|
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} )'
|
||||||
'LED('
|
|
||||||
f'_brightness={self._brightness} '
|
|
||||||
f'_pos={self._pos} '
|
|
||||||
f'brightness_step={self.brightness_step} '
|
|
||||||
f'brightness_limit={self.brightness_limit} '
|
|
||||||
f'animation_mode={self.animation_mode} '
|
|
||||||
f'animation_speed={self.animation_speed} '
|
|
||||||
f'breathe_center={self.breathe_center} '
|
|
||||||
f'val={self.val} '
|
|
||||||
')'
|
|
||||||
)
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _init_effect(self):
|
def _init_effect(self):
|
||||||
self._pos = 0
|
self._pos = 0
|
||||||
|
@@ -15,16 +15,7 @@ class Power(Extension):
|
|||||||
return f'Power({self._to_dict()})'
|
return f'Power({self._to_dict()})'
|
||||||
|
|
||||||
def _to_dict(self):
|
def _to_dict(self):
|
||||||
return (
|
return f'Power( enable={self.enable} powersave_pin={self.powersave_pin} is_target={self.is_target} _powersave_start={self._powersave_start} _usb_last_scan={self._usb_last_scan} _psp={self._psp} )'
|
||||||
'Power( '
|
|
||||||
f'enable={self.enable} '
|
|
||||||
f'powersave_pin={self.powersave_pin} '
|
|
||||||
f'is_target={self.is_target} '
|
|
||||||
f'_powersave_start={self._powersave_start} '
|
|
||||||
f'_usb_last_scan={self._usb_last_scan} '
|
|
||||||
f'_psp={self._psp} '
|
|
||||||
')'
|
|
||||||
)
|
|
||||||
|
|
||||||
def during_bootup(self, keyboard):
|
def during_bootup(self, keyboard):
|
||||||
self.enable = not bool(self.usb_scan)
|
self.enable = not bool(self.usb_scan)
|
||||||
|
@@ -28,6 +28,8 @@ class KMKKeyboard:
|
|||||||
unicode_mode = UnicodeMode.NOOP
|
unicode_mode = UnicodeMode.NOOP
|
||||||
tap_time = 300
|
tap_time = 300
|
||||||
|
|
||||||
|
extensions = []
|
||||||
|
|
||||||
#####
|
#####
|
||||||
# Internal State
|
# Internal State
|
||||||
_keys_pressed = set()
|
_keys_pressed = set()
|
||||||
@@ -302,7 +304,7 @@ class KMKKeyboard:
|
|||||||
and do an isinstance check, but instead do string detection
|
and do an isinstance check, but instead do string detection
|
||||||
'''
|
'''
|
||||||
if any(
|
if any(
|
||||||
x.__class__.__module__ == 'kmk.extensions.split' for x in self._extensions
|
x.__class__.__module__ == 'kmk.extensions.split' for x in self.extensions
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
if any(
|
if any(
|
||||||
@@ -343,24 +345,13 @@ class KMKKeyboard:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def go(self, hid_type=HIDModes.USB, **kwargs):
|
def go(self, hid_type=HIDModes.USB, **kwargs):
|
||||||
self._extensions = [] + getattr(self, 'extensions', [])
|
|
||||||
|
|
||||||
try:
|
|
||||||
if self.debug_enabled:
|
|
||||||
print('EXTENSIONS', self.extensions)
|
|
||||||
del self.extensions
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.hid_type = hid_type
|
self.hid_type = hid_type
|
||||||
|
|
||||||
self._init_sanity_check()
|
self._init_sanity_check()
|
||||||
self._init_coord_mapping()
|
self._init_coord_mapping()
|
||||||
self._init_hid()
|
self._init_hid()
|
||||||
|
|
||||||
for ext in self._extensions:
|
for ext in self.extensions:
|
||||||
try:
|
try:
|
||||||
ext.during_bootup(self)
|
ext.during_bootup(self)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -376,7 +367,7 @@ class KMKKeyboard:
|
|||||||
while True:
|
while True:
|
||||||
self.state_changed = False
|
self.state_changed = False
|
||||||
|
|
||||||
for ext in self._extensions:
|
for ext in self.extensions:
|
||||||
try:
|
try:
|
||||||
self._handle_matrix_report(ext.before_matrix_scan(self))
|
self._handle_matrix_report(ext.before_matrix_scan(self))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -385,13 +376,13 @@ class KMKKeyboard:
|
|||||||
matrix_update = self.matrix.scan_for_changes()
|
matrix_update = self.matrix.scan_for_changes()
|
||||||
self._handle_matrix_report(matrix_update)
|
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)
|
ext.after_matrix_scan(self, matrix_update)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to run post matrix function: ', e)
|
print('Failed to run post matrix function: ', e)
|
||||||
|
|
||||||
for ext in self._extensions:
|
for ext in self.extensions:
|
||||||
try:
|
try:
|
||||||
ext.before_hid_send(self)
|
ext.before_hid_send(self)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -410,7 +401,7 @@ class KMKKeyboard:
|
|||||||
if self._hid_pending:
|
if self._hid_pending:
|
||||||
self._send_hid()
|
self._send_hid()
|
||||||
|
|
||||||
for ext in self._extensions:
|
for ext in self.extensions:
|
||||||
try:
|
try:
|
||||||
ext.after_hid_send(self)
|
ext.after_hid_send(self)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@@ -27,7 +27,6 @@ import kmk.kmktime # isort:skip
|
|||||||
import kmk.types # isort:skip
|
import kmk.types # isort:skip
|
||||||
|
|
||||||
# Now handlers that will be used in keys later
|
# Now handlers that will be used in keys later
|
||||||
import kmk.handlers.layers # isort:skip
|
|
||||||
import kmk.handlers.stock # isort:skip
|
import kmk.handlers.stock # isort:skip
|
||||||
|
|
||||||
# Now stuff that depends on the above (and so on)
|
# Now stuff that depends on the above (and so on)
|
||||||
|
Reference in New Issue
Block a user