Run black against source tree
This commit is contained in:
parent
5c0c13e8d0
commit
aaeaa74a0c
@ -7,14 +7,7 @@ from kmk.util import intify_coordinate as ic
|
|||||||
# board, by flipping various row3 (bottom physical row) keys so their
|
# board, by flipping various row3 (bottom physical row) keys so their
|
||||||
# coord_mapping matches what the user pressed (even if the wiring
|
# coord_mapping matches what the user pressed (even if the wiring
|
||||||
# underneath is sending different coordinates)
|
# underneath is sending different coordinates)
|
||||||
_r3_swap_conversions = {
|
_r3_swap_conversions = {3: 9, 4: 10, 5: 11, 9: 3, 10: 4, 11: 5}
|
||||||
3: 9,
|
|
||||||
4: 10,
|
|
||||||
5: 11,
|
|
||||||
9: 3,
|
|
||||||
10: 4,
|
|
||||||
11: 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def r3_swap(col):
|
def r3_swap(col):
|
||||||
|
@ -114,7 +114,9 @@ def tt_pressed(key, state, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def tt_released(key, state, *args, **kwargs):
|
def tt_released(key, state, *args, **kwargs):
|
||||||
tap_timed_out = ticks_diff(ticks_ms(), state.start_time['tt']) >= state.config.tap_time
|
tap_timed_out = (
|
||||||
|
ticks_diff(ticks_ms(), state.start_time['tt']) >= state.config.tap_time
|
||||||
|
)
|
||||||
if state.start_time['tt'] is None or tap_timed_out:
|
if state.start_time['tt'] is None or tap_timed_out:
|
||||||
# On first press, works like MO. On second press, does nothing unless let up within
|
# On first press, works like MO. On second press, does nothing unless let up within
|
||||||
# time window, then acts like TG.
|
# time window, then acts like TG.
|
||||||
|
@ -14,7 +14,7 @@ def mt_released(key, state, *args, **kwargs):
|
|||||||
state.keys_pressed.discard(key.meta.mods)
|
state.keys_pressed.discard(key.meta.mods)
|
||||||
timer_name = 'mod_tap'
|
timer_name = 'mod_tap'
|
||||||
if state.start_time[timer_name] and (
|
if state.start_time[timer_name] and (
|
||||||
ticks_diff(ticks_ms(), state.start_time[timer_name]) < state.config.tap_time
|
ticks_diff(ticks_ms(), state.start_time[timer_name]) < state.config.tap_time
|
||||||
):
|
):
|
||||||
state.hid_pending = True
|
state.hid_pending = True
|
||||||
state.tap_key(key.meta.kc)
|
state.tap_key(key.meta.kc)
|
||||||
|
@ -64,10 +64,7 @@ def unicode_string_sequence(unistring):
|
|||||||
Allows sending things like (╯°□°)╯︵ ┻━┻ directly, without
|
Allows sending things like (╯°□°)╯︵ ┻━┻ directly, without
|
||||||
manual conversion to Unicode codepoints.
|
manual conversion to Unicode codepoints.
|
||||||
'''
|
'''
|
||||||
return unicode_codepoint_sequence([
|
return unicode_codepoint_sequence([hex(get_wide_ordinal(s))[2:] for s in unistring])
|
||||||
hex(get_wide_ordinal(s))[2:]
|
|
||||||
for s in unistring
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
def generate_codepoint_keysym_seq(codepoint, expected_length=4):
|
def generate_codepoint_keysym_seq(codepoint, expected_length=4):
|
||||||
@ -95,31 +92,22 @@ def generate_leader_dictionary_seq(string):
|
|||||||
|
|
||||||
|
|
||||||
def unicode_codepoint_sequence(codepoints):
|
def unicode_codepoint_sequence(codepoints):
|
||||||
kc_seqs = (
|
kc_seqs = (generate_codepoint_keysym_seq(codepoint) for codepoint in codepoints)
|
||||||
generate_codepoint_keysym_seq(codepoint)
|
|
||||||
for codepoint in codepoints
|
|
||||||
)
|
|
||||||
|
|
||||||
kc_macros = [
|
kc_macros = [simple_key_sequence(kc_seq) for kc_seq in kc_seqs]
|
||||||
simple_key_sequence(kc_seq)
|
|
||||||
for kc_seq in kc_seqs
|
|
||||||
]
|
|
||||||
|
|
||||||
def _unicode_sequence(key, state, *args, **kwargs):
|
def _unicode_sequence(key, state, *args, **kwargs):
|
||||||
if state.config.unicode_mode == UnicodeMode.IBUS:
|
if state.config.unicode_mode == UnicodeMode.IBUS:
|
||||||
state.process_key(
|
state.process_key(
|
||||||
simple_key_sequence(_ibus_unicode_sequence(kc_macros, state)),
|
simple_key_sequence(_ibus_unicode_sequence(kc_macros, state)), True
|
||||||
True,
|
|
||||||
)
|
)
|
||||||
elif state.config.unicode_mode == UnicodeMode.RALT:
|
elif state.config.unicode_mode == UnicodeMode.RALT:
|
||||||
state.process_key(
|
state.process_key(
|
||||||
simple_key_sequence(_ralt_unicode_sequence(kc_macros, state)),
|
simple_key_sequence(_ralt_unicode_sequence(kc_macros, state)), True
|
||||||
True,
|
|
||||||
)
|
)
|
||||||
elif state.config.unicode_mode == UnicodeMode.WINC:
|
elif state.config.unicode_mode == UnicodeMode.WINC:
|
||||||
state.process_key(
|
state.process_key(
|
||||||
simple_key_sequence(_winc_unicode_sequence(kc_macros, state)),
|
simple_key_sequence(_winc_unicode_sequence(kc_macros, state)), True
|
||||||
True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return make_key(on_press=_unicode_sequence)
|
return make_key(on_press=_unicode_sequence)
|
||||||
|
@ -22,10 +22,7 @@ class USB_HID:
|
|||||||
self.post_init()
|
self.post_init()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '{}(REPORT_BYTES={})'.format(
|
return '{}(REPORT_BYTES={})'.format(self.__class__.__name__, self.REPORT_BYTES)
|
||||||
self.__class__.__name__,
|
|
||||||
self.REPORT_BYTES,
|
|
||||||
)
|
|
||||||
|
|
||||||
def post_init(self):
|
def post_init(self):
|
||||||
pass
|
pass
|
||||||
@ -157,10 +154,12 @@ class USB_HID:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import usb_hid
|
import usb_hid
|
||||||
|
|
||||||
PLATFORM_CIRCUITPYTHON = True
|
PLATFORM_CIRCUITPYTHON = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
PLATFORM_CIRCUITPYTHON = False
|
PLATFORM_CIRCUITPYTHON = False
|
||||||
else:
|
else:
|
||||||
|
|
||||||
class CircuitPythonUSB_HID(USB_HID):
|
class CircuitPythonUSB_HID(USB_HID):
|
||||||
REPORT_BYTES = 9
|
REPORT_BYTES = 9
|
||||||
|
|
||||||
@ -192,5 +191,5 @@ else:
|
|||||||
reporting_device_const = self.report_device[0]
|
reporting_device_const = self.report_device[0]
|
||||||
|
|
||||||
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]
|
||||||
)
|
)
|
||||||
|
@ -18,13 +18,7 @@ class InternalState:
|
|||||||
# overhead (the underlying list was never used anyway)
|
# overhead (the underlying list was never used anyway)
|
||||||
active_layers = [0]
|
active_layers = [0]
|
||||||
|
|
||||||
start_time = {
|
start_time = {'lt': None, 'tg': None, 'tt': None, 'lm': None, 'leader': None}
|
||||||
'lt': None,
|
|
||||||
'tg': None,
|
|
||||||
'tt': None,
|
|
||||||
'lm': None,
|
|
||||||
'leader': None,
|
|
||||||
}
|
|
||||||
timeouts = {}
|
timeouts = {}
|
||||||
tapping = False
|
tapping = False
|
||||||
tap_dance_counts = {}
|
tap_dance_counts = {}
|
||||||
@ -72,11 +66,7 @@ class InternalState:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
if self.config.debug_enabled:
|
if self.config.debug_enabled:
|
||||||
print(
|
print(
|
||||||
'CoordMappingNotFound(ic={}, row={}, col={})'.format(
|
'CoordMappingNotFound(ic={}, row={}, col={})'.format(ic, row, col)
|
||||||
ic,
|
|
||||||
row,
|
|
||||||
col,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@ -128,11 +118,7 @@ class InternalState:
|
|||||||
|
|
||||||
def matrix_changed(self, row, col, is_pressed):
|
def matrix_changed(self, row, col, is_pressed):
|
||||||
if self.config.debug_enabled:
|
if self.config.debug_enabled:
|
||||||
print('MatrixChange(col={} row={} pressed={})'.format(
|
print('MatrixChange(col={} row={} pressed={})'.format(col, row, is_pressed))
|
||||||
col,
|
|
||||||
row,
|
|
||||||
is_pressed,
|
|
||||||
))
|
|
||||||
|
|
||||||
int_coord = intify_coordinate(row, col)
|
int_coord = intify_coordinate(row, col)
|
||||||
kc_changed = self._find_key_in_map(row, col)
|
kc_changed = self._find_key_in_map(row, col)
|
||||||
@ -189,10 +175,13 @@ class InternalState:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
if (
|
if (
|
||||||
changed_key not in self.tap_dance_counts or not self.tap_dance_counts[changed_key]
|
changed_key not in self.tap_dance_counts
|
||||||
|
or not self.tap_dance_counts[changed_key]
|
||||||
):
|
):
|
||||||
self.tap_dance_counts[changed_key] = 1
|
self.tap_dance_counts[changed_key] = 1
|
||||||
self.set_timeout(self.config.tap_time, lambda: self._end_tap_dance(changed_key))
|
self.set_timeout(
|
||||||
|
self.config.tap_time, lambda: self._end_tap_dance(changed_key)
|
||||||
|
)
|
||||||
self.tapping = True
|
self.tapping = True
|
||||||
else:
|
else:
|
||||||
self.tap_dance_counts[changed_key] += 1
|
self.tap_dance_counts[changed_key] += 1
|
||||||
@ -201,7 +190,9 @@ class InternalState:
|
|||||||
self.tap_side_effects[changed_key] = None
|
self.tap_side_effects[changed_key] = None
|
||||||
else:
|
else:
|
||||||
has_side_effects = self.tap_side_effects[changed_key] is not None
|
has_side_effects = self.tap_side_effects[changed_key] is not None
|
||||||
hit_max_defined_taps = self.tap_dance_counts[changed_key] == len(changed_key.codes)
|
hit_max_defined_taps = self.tap_dance_counts[changed_key] == len(
|
||||||
|
changed_key.codes
|
||||||
|
)
|
||||||
|
|
||||||
if has_side_effects or hit_max_defined_taps:
|
if has_side_effects or hit_max_defined_taps:
|
||||||
self._end_tap_dance(changed_key)
|
self._end_tap_dance(changed_key)
|
||||||
@ -241,7 +232,9 @@ class InternalState:
|
|||||||
self.config.leader_mode += 1
|
self.config.leader_mode += 1
|
||||||
|
|
||||||
if self.config.leader_mode == LeaderMode.TIMEOUT_ACTIVE:
|
if self.config.leader_mode == LeaderMode.TIMEOUT_ACTIVE:
|
||||||
self.set_timeout(self.config.leader_timeout, self._handle_leader_sequence)
|
self.set_timeout(
|
||||||
|
self.config.leader_timeout, self._handle_leader_sequence
|
||||||
|
)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -256,8 +249,7 @@ class InternalState:
|
|||||||
self.process_key(self.config.leader_dictionary[lmh], True)
|
self.process_key(self.config.leader_dictionary[lmh], True)
|
||||||
|
|
||||||
self.set_timeout(
|
self.set_timeout(
|
||||||
False,
|
False, lambda: self.remove_key(self.config.leader_dictionary[lmh])
|
||||||
lambda: self.remove_key(self.config.leader_dictionary[lmh]),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@ -273,9 +265,7 @@ class InternalState:
|
|||||||
self.leader_last_len = len(self.keys_pressed)
|
self.leader_last_len = len(self.keys_pressed)
|
||||||
|
|
||||||
for key in keys_pressed:
|
for key in keys_pressed:
|
||||||
if (
|
if self.config.leader_mode == LeaderMode.ENTER_ACTIVE and key == KC.ENT:
|
||||||
self.config.leader_mode == LeaderMode.ENTER_ACTIVE and key == KC.ENT
|
|
||||||
):
|
|
||||||
self._handle_leader_sequence()
|
self._handle_leader_sequence()
|
||||||
break
|
break
|
||||||
elif key == KC.ESC or key == KC.GESC:
|
elif key == KC.ESC or key == KC.GESC:
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
from kmk.types import (KeySeqSleepMeta, LayerKeyMeta, ModTapKeyMeta,
|
from kmk.types import (
|
||||||
TapDanceKeyMeta, UnicodeModeKeyMeta)
|
KeySeqSleepMeta,
|
||||||
|
LayerKeyMeta,
|
||||||
|
ModTapKeyMeta,
|
||||||
|
TapDanceKeyMeta,
|
||||||
|
UnicodeModeKeyMeta,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def key_seq_sleep_validator(ms):
|
def key_seq_sleep_validator(ms):
|
||||||
|
@ -156,12 +156,11 @@ class KeyboardConfig:
|
|||||||
|
|
||||||
print(self)
|
print(self)
|
||||||
print(self._state)
|
print(self._state)
|
||||||
print('GCStats(pre_alloc={} pre_free={} alloc={} free={})'.format(
|
print(
|
||||||
pre_alloc,
|
'GCStats(pre_alloc={} pre_free={} alloc={} free={})'.format(
|
||||||
pre_free,
|
pre_alloc, pre_free, gc.mem_alloc(), gc.mem_free()
|
||||||
gc.mem_alloc(),
|
)
|
||||||
gc.mem_free(),
|
)
|
||||||
))
|
|
||||||
|
|
||||||
def _send_hid(self):
|
def _send_hid(self):
|
||||||
self._hid_helper_inst.create_report(self._state.keys_pressed).send()
|
self._hid_helper_inst.create_report(self._state.keys_pressed).send()
|
||||||
@ -183,11 +182,7 @@ class KeyboardConfig:
|
|||||||
'''
|
'''
|
||||||
if update is not None:
|
if update is not None:
|
||||||
|
|
||||||
self._state.matrix_changed(
|
self._state.matrix_changed(update[0], update[1], update[2])
|
||||||
update[0],
|
|
||||||
update[1],
|
|
||||||
update[2],
|
|
||||||
)
|
|
||||||
|
|
||||||
def _send_to_master(self, update):
|
def _send_to_master(self, update):
|
||||||
if self.split_master_left:
|
if self.split_master_left:
|
||||||
@ -202,6 +197,7 @@ class KeyboardConfig:
|
|||||||
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
|
||||||
import microcontroller
|
import microcontroller
|
||||||
|
|
||||||
microcontroller.reset()
|
microcontroller.reset()
|
||||||
|
|
||||||
while self.uart.in_waiting >= 3:
|
while self.uart.in_waiting >= 3:
|
||||||
|
81
kmk/keys.py
81
kmk/keys.py
@ -4,9 +4,13 @@ import kmk.handlers.layers as layers
|
|||||||
import kmk.handlers.modtap as modtap
|
import kmk.handlers.modtap as modtap
|
||||||
import kmk.handlers.stock as handlers
|
import kmk.handlers.stock as handlers
|
||||||
from kmk.consts import UnicodeMode
|
from kmk.consts import UnicodeMode
|
||||||
from kmk.key_validators import (key_seq_sleep_validator, layer_key_validator,
|
from kmk.key_validators import (
|
||||||
mod_tap_validator, tap_dance_key_validator,
|
key_seq_sleep_validator,
|
||||||
unicode_mode_key_validator)
|
layer_key_validator,
|
||||||
|
mod_tap_validator,
|
||||||
|
tap_dance_key_validator,
|
||||||
|
unicode_mode_key_validator,
|
||||||
|
)
|
||||||
from kmk.types import AttrDict, UnicodeModeKeyMeta
|
from kmk.types import AttrDict, UnicodeModeKeyMeta
|
||||||
|
|
||||||
FIRST_KMK_INTERNAL_KEY = 1000
|
FIRST_KMK_INTERNAL_KEY = 1000
|
||||||
@ -231,16 +235,14 @@ class ModifierKey(Key):
|
|||||||
if modified_code.has_modifiers:
|
if modified_code.has_modifiers:
|
||||||
new_keycode.has_modifiers |= modified_code.has_modifiers
|
new_keycode.has_modifiers |= modified_code.has_modifiers
|
||||||
else:
|
else:
|
||||||
new_keycode = Key(
|
new_keycode = Key(self.code, no_press=no_press, no_release=no_release)
|
||||||
self.code,
|
|
||||||
no_press=no_press,
|
|
||||||
no_release=no_release,
|
|
||||||
)
|
|
||||||
|
|
||||||
return new_keycode
|
return new_keycode
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'ModifierKey(code={}, has_modifiers={})'.format(self.code, self.has_modifiers)
|
return 'ModifierKey(code={}, has_modifiers={})'.format(
|
||||||
|
self.code, self.has_modifiers
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ConsumerKey(Key):
|
class ConsumerKey(Key):
|
||||||
@ -268,12 +270,7 @@ def register_key_names(key, names=tuple()): # NOQA
|
|||||||
return key
|
return key
|
||||||
|
|
||||||
|
|
||||||
def make_key(
|
def make_key(code=None, names=tuple(), type=KEY_SIMPLE, **kwargs): # NOQA
|
||||||
code=None,
|
|
||||||
names=tuple(), # NOQA
|
|
||||||
type=KEY_SIMPLE,
|
|
||||||
**kwargs,
|
|
||||||
):
|
|
||||||
'''
|
'''
|
||||||
Create a new key, aliased by `names` in the KC lookup table.
|
Create a new key, aliased by `names` in the KC lookup table.
|
||||||
|
|
||||||
@ -348,10 +345,7 @@ def make_argumented_key(
|
|||||||
|
|
||||||
if meta:
|
if meta:
|
||||||
key = Key(
|
key = Key(
|
||||||
NEXT_AVAILABLE_KEY,
|
NEXT_AVAILABLE_KEY, meta=meta, *constructor_args, **constructor_kwargs
|
||||||
meta=meta,
|
|
||||||
*constructor_args,
|
|
||||||
**constructor_kwargs,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
NEXT_AVAILABLE_KEY += 1
|
NEXT_AVAILABLE_KEY += 1
|
||||||
@ -362,7 +356,7 @@ def make_argumented_key(
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Argumented key validator failed for unknown reasons. '
|
'Argumented key validator failed for unknown reasons. '
|
||||||
"This may not be the keymap's fault, as a more specific error "
|
"This may not be the keymap's fault, as a more specific error "
|
||||||
'should have been raised.',
|
'should have been raised.'
|
||||||
)
|
)
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
@ -584,7 +578,9 @@ make_consumer_key(code=234, names=('AUDIO_VOL_DOWN', 'VOLD')) # 0xEA
|
|||||||
make_consumer_key(code=181, names=('MEDIA_NEXT_TRACK', 'MNXT')) # 0xB5
|
make_consumer_key(code=181, names=('MEDIA_NEXT_TRACK', 'MNXT')) # 0xB5
|
||||||
make_consumer_key(code=182, names=('MEDIA_PREV_TRACK', 'MPRV')) # 0xB6
|
make_consumer_key(code=182, names=('MEDIA_PREV_TRACK', 'MPRV')) # 0xB6
|
||||||
make_consumer_key(code=183, names=('MEDIA_STOP', 'MSTP')) # 0xB7
|
make_consumer_key(code=183, names=('MEDIA_STOP', 'MSTP')) # 0xB7
|
||||||
make_consumer_key(code=205, names=('MEDIA_PLAY_PAUSE', 'MPLY')) # 0xCD (this may not be right)
|
make_consumer_key(
|
||||||
|
code=205, names=('MEDIA_PLAY_PAUSE', 'MPLY')
|
||||||
|
) # 0xCD (this may not be right)
|
||||||
make_consumer_key(code=184, names=('MEDIA_EJECT', 'EJCT')) # 0xB8
|
make_consumer_key(code=184, names=('MEDIA_EJECT', 'EJCT')) # 0xB8
|
||||||
make_consumer_key(code=179, names=('MEDIA_FAST_FORWARD', 'MFFD')) # 0xB3
|
make_consumer_key(code=179, names=('MEDIA_FAST_FORWARD', 'MFFD')) # 0xB3
|
||||||
make_consumer_key(code=180, names=('MEDIA_REWIND', 'MRWD')) # 0xB4
|
make_consumer_key(code=180, names=('MEDIA_REWIND', 'MRWD')) # 0xB4
|
||||||
@ -596,19 +592,28 @@ make_consumer_key(code=180, names=('MEDIA_REWIND', 'MRWD')) # 0xB4
|
|||||||
# two keys with the exact same functionality
|
# two keys with the exact same functionality
|
||||||
for names in (('NO',), ('TRANSPARENT', 'TRNS')):
|
for names in (('NO',), ('TRANSPARENT', 'TRNS')):
|
||||||
make_key(
|
make_key(
|
||||||
names=names,
|
names=names, on_press=handlers.passthrough, on_release=handlers.passthrough
|
||||||
on_press=handlers.passthrough,
|
|
||||||
on_release=handlers.passthrough,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
make_key(names=('RESET',), on_press=handlers.reset)
|
make_key(names=('RESET',), on_press=handlers.reset)
|
||||||
make_key(names=('BOOTLOADER',), on_press=handlers.bootloader)
|
make_key(names=('BOOTLOADER',), on_press=handlers.bootloader)
|
||||||
make_key(names=('DEBUG', 'DBG'), on_press=handlers.debug_pressed, on_release=handlers.passthrough)
|
make_key(
|
||||||
|
names=('DEBUG', 'DBG'),
|
||||||
|
on_press=handlers.debug_pressed,
|
||||||
|
on_release=handlers.passthrough,
|
||||||
|
)
|
||||||
|
|
||||||
make_key(names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released)
|
make_key(
|
||||||
make_key(names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released)
|
names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released
|
||||||
make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed,
|
)
|
||||||
on_release=handlers.gesc_released)
|
make_key(
|
||||||
|
names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released
|
||||||
|
)
|
||||||
|
make_key(
|
||||||
|
names=('GESC', 'GRAVE_ESC'),
|
||||||
|
on_press=handlers.gesc_pressed,
|
||||||
|
on_release=handlers.gesc_released,
|
||||||
|
)
|
||||||
make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog)
|
make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog)
|
||||||
make_key(names=('RGB_HUI',), on_press=handlers.rgb_hui)
|
make_key(names=('RGB_HUI',), on_press=handlers.rgb_hui)
|
||||||
make_key(names=('RGB_HUD',), on_press=handlers.rgb_hud)
|
make_key(names=('RGB_HUD',), on_press=handlers.rgb_hud)
|
||||||
@ -621,8 +626,10 @@ make_key(names=('RGB_AND',), on_press=handlers.rgb_and)
|
|||||||
make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static)
|
make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static)
|
||||||
make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe)
|
make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe)
|
||||||
make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow)
|
make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow)
|
||||||
make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'),
|
make_key(
|
||||||
on_press=handlers.rgb_mode_breathe_rainbow)
|
names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'),
|
||||||
|
on_press=handlers.rgb_mode_breathe_rainbow,
|
||||||
|
)
|
||||||
make_key(names=('RGB_MODE_SWIRL', 'RGB_M_S'), on_press=handlers.rgb_mode_swirl)
|
make_key(names=('RGB_MODE_SWIRL', 'RGB_M_S'), on_press=handlers.rgb_mode_swirl)
|
||||||
make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight)
|
make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight)
|
||||||
|
|
||||||
@ -650,9 +657,7 @@ make_argumented_key(
|
|||||||
on_release=layers.mo_released,
|
on_release=layers.mo_released,
|
||||||
)
|
)
|
||||||
make_argumented_key(
|
make_argumented_key(
|
||||||
validator=layer_key_validator,
|
validator=layer_key_validator, names=('DF',), on_press=layers.df_pressed
|
||||||
names=('DF',),
|
|
||||||
on_press=layers.df_pressed,
|
|
||||||
)
|
)
|
||||||
make_argumented_key(
|
make_argumented_key(
|
||||||
validator=layer_key_validator,
|
validator=layer_key_validator,
|
||||||
@ -667,14 +672,10 @@ make_argumented_key(
|
|||||||
on_release=layers.lt_released,
|
on_release=layers.lt_released,
|
||||||
)
|
)
|
||||||
make_argumented_key(
|
make_argumented_key(
|
||||||
validator=layer_key_validator,
|
validator=layer_key_validator, names=('TG',), on_press=layers.tg_pressed
|
||||||
names=('TG',),
|
|
||||||
on_press=layers.tg_pressed,
|
|
||||||
)
|
)
|
||||||
make_argumented_key(
|
make_argumented_key(
|
||||||
validator=layer_key_validator,
|
validator=layer_key_validator, names=('TO',), on_press=layers.to_pressed
|
||||||
names=('TO',),
|
|
||||||
on_press=layers.to_pressed,
|
|
||||||
)
|
)
|
||||||
make_argumented_key(
|
make_argumented_key(
|
||||||
validator=layer_key_validator,
|
validator=layer_key_validator,
|
||||||
|
@ -5,7 +5,9 @@ from kmk.consts import DiodeOrientation
|
|||||||
|
|
||||||
class MatrixScanner:
|
class MatrixScanner:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, cols, rows,
|
self,
|
||||||
|
cols,
|
||||||
|
rows,
|
||||||
diode_orientation=DiodeOrientation.COLUMNS,
|
diode_orientation=DiodeOrientation.COLUMNS,
|
||||||
rollover_cols_every_rows=None,
|
rollover_cols_every_rows=None,
|
||||||
):
|
):
|
||||||
@ -33,9 +35,9 @@ class MatrixScanner:
|
|||||||
self.inputs = self.cols
|
self.inputs = self.cols
|
||||||
self.translate_coords = False
|
self.translate_coords = False
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid DiodeOrientation: {}'.format(
|
raise ValueError(
|
||||||
self.diode_orientation,
|
'Invalid DiodeOrientation: {}'.format(self.diode_orientation)
|
||||||
))
|
)
|
||||||
|
|
||||||
for pin in self.outputs:
|
for pin in self.outputs:
|
||||||
pin.switch_to_output()
|
pin.switch_to_output()
|
||||||
@ -81,7 +83,9 @@ class MatrixScanner:
|
|||||||
|
|
||||||
if old_val != new_val:
|
if old_val != new_val:
|
||||||
if self.translate_coords:
|
if self.translate_coords:
|
||||||
new_oidx = oidx + self.len_cols * (iidx // self.rollover_cols_every_rows)
|
new_oidx = oidx + self.len_cols * (
|
||||||
|
iidx // self.rollover_cols_every_rows
|
||||||
|
)
|
||||||
new_iidx = iidx - self.rollover_cols_every_rows * (
|
new_iidx = iidx - self.rollover_cols_every_rows * (
|
||||||
iidx // self.rollover_cols_every_rows
|
iidx // self.rollover_cols_every_rows
|
||||||
)
|
)
|
||||||
|
22
kmk/rgb.py
22
kmk/rgb.py
@ -51,10 +51,13 @@ class RGB:
|
|||||||
def __init__(self, config, pixel_pin):
|
def __init__(self, config, pixel_pin):
|
||||||
try:
|
try:
|
||||||
import neopixel
|
import neopixel
|
||||||
self.neopixel = neopixel.NeoPixel(pixel_pin,
|
|
||||||
config['num_pixels'],
|
self.neopixel = neopixel.NeoPixel(
|
||||||
pixel_order=config['rgb_order'],
|
pixel_pin,
|
||||||
auto_write=False)
|
config['num_pixels'],
|
||||||
|
pixel_order=config['rgb_order'],
|
||||||
|
auto_write=False,
|
||||||
|
)
|
||||||
if len(config['rgb_order']) == 4:
|
if len(config['rgb_order']) == 4:
|
||||||
self.rgbw = True
|
self.rgbw = True
|
||||||
self.num_pixels = const(config['num_pixels'])
|
self.num_pixels = const(config['num_pixels'])
|
||||||
@ -398,7 +401,10 @@ class RGB:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _init_effect(self):
|
def _init_effect(self):
|
||||||
if self.animation_mode == 'breathing' or self.animation_mode == 'breathing_rainbow':
|
if (
|
||||||
|
self.animation_mode == 'breathing'
|
||||||
|
or self.animation_mode == 'breathing_rainbow'
|
||||||
|
):
|
||||||
self.intervals = (30, 20, 10, 5)
|
self.intervals = (30, 20, 10, 5)
|
||||||
elif self.animation_mode == 'swirl':
|
elif self.animation_mode == 'swirl':
|
||||||
self.intervals = (50, 50)
|
self.intervals = (50, 50)
|
||||||
@ -451,10 +457,8 @@ class RGB:
|
|||||||
self.disable_auto_write = True # Turn off instantly showing
|
self.disable_auto_write = True # Turn off instantly showing
|
||||||
for i in range(0, self.num_pixels):
|
for i in range(0, self.num_pixels):
|
||||||
self.set_hsv(
|
self.set_hsv(
|
||||||
(self.hue - (i * self.num_pixels)) % 360,
|
(self.hue - (i * self.num_pixels)) % 360, self.sat, self.val, i
|
||||||
self.sat,
|
)
|
||||||
self.val,
|
|
||||||
i)
|
|
||||||
|
|
||||||
# Show final results
|
# Show final results
|
||||||
self.disable_auto_write = False # Resume showing changes
|
self.disable_auto_write = False # Resume showing changes
|
||||||
|
@ -6,6 +6,7 @@ class AttrDict(dict):
|
|||||||
|
|
||||||
This is read-only on purpose.
|
This is read-only on purpose.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
return self[key]
|
return self[key]
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ class Anything:
|
|||||||
'''
|
'''
|
||||||
A stub class which will repr as a provided name
|
A stub class which will repr as a provided name
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
@ -24,19 +24,23 @@ def flatten_dict(d):
|
|||||||
def reset_keyboard():
|
def reset_keyboard():
|
||||||
try:
|
try:
|
||||||
import machine
|
import machine
|
||||||
|
|
||||||
machine.reset()
|
machine.reset()
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import microcontroller
|
import microcontroller
|
||||||
|
|
||||||
microcontroller.reset()
|
microcontroller.reset()
|
||||||
|
|
||||||
|
|
||||||
def reset_bootloader():
|
def reset_bootloader():
|
||||||
try:
|
try:
|
||||||
import machine
|
import machine
|
||||||
|
|
||||||
machine.bootloader()
|
machine.bootloader()
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import microcontroller
|
import microcontroller
|
||||||
|
|
||||||
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
||||||
microcontroller.reset()
|
microcontroller.reset()
|
||||||
|
@ -16,14 +16,6 @@ keymap = [
|
|||||||
[KC.MO(2), KC.I, KC.ENTER],
|
[KC.MO(2), KC.I, KC.ENTER],
|
||||||
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
||||||
],
|
],
|
||||||
[
|
[[KC.TRNS, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
|
||||||
[KC.TRNS, KC.B, KC.C],
|
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
|
||||||
[KC.NO, KC.D, KC.E],
|
|
||||||
[KC.F, KC.G, KC.H],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[KC.X, KC.Y, KC.Z],
|
|
||||||
[KC.TRNS, KC.N, KC.O],
|
|
||||||
[KC.R, KC.P, KC.Q],
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
|
@ -16,14 +16,6 @@ keymap = [
|
|||||||
[KC.MO(2), KC.I, KC.ENTER],
|
[KC.MO(2), KC.I, KC.ENTER],
|
||||||
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
||||||
],
|
],
|
||||||
[
|
[[KC.TRNS, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
|
||||||
[KC.TRNS, KC.B, KC.C],
|
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
|
||||||
[KC.NO, KC.D, KC.E],
|
|
||||||
[KC.F, KC.G, KC.H],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[KC.X, KC.Y, KC.Z],
|
|
||||||
[KC.TRNS, KC.N, KC.O],
|
|
||||||
[KC.R, KC.P, KC.Q],
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
|
@ -16,14 +16,6 @@ keymap = [
|
|||||||
[KC.MO(2), KC.I, KC.ENTER],
|
[KC.MO(2), KC.I, KC.ENTER],
|
||||||
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
||||||
],
|
],
|
||||||
[
|
[[KC.A, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
|
||||||
[KC.A, KC.B, KC.C],
|
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
|
||||||
[KC.NO, KC.D, KC.E],
|
|
||||||
[KC.F, KC.G, KC.H],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[KC.X, KC.Y, KC.Z],
|
|
||||||
[KC.TRNS, KC.N, KC.O],
|
|
||||||
[KC.R, KC.P, KC.Q],
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
|
@ -16,14 +16,6 @@ keymap = [
|
|||||||
[KC.MO(2), KC.I, KC.ENTER],
|
[KC.MO(2), KC.I, KC.ENTER],
|
||||||
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
||||||
],
|
],
|
||||||
[
|
[[KC.TRNS, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
|
||||||
[KC.TRNS, KC.B, KC.C],
|
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
|
||||||
[KC.NO, KC.D, KC.E],
|
|
||||||
[KC.F, KC.G, KC.H],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[KC.X, KC.Y, KC.Z],
|
|
||||||
[KC.TRNS, KC.N, KC.O],
|
|
||||||
[KC.R, KC.P, KC.Q],
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
try:
|
try:
|
||||||
import machine
|
import machine
|
||||||
|
|
||||||
machine.bootloader()
|
machine.bootloader()
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import microcontroller
|
import microcontroller
|
||||||
|
|
||||||
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
|
||||||
microcontroller.reset()
|
microcontroller.reset()
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
try:
|
try:
|
||||||
import machine
|
import machine
|
||||||
|
|
||||||
machine.reset()
|
machine.reset()
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import microcontroller
|
import microcontroller
|
||||||
|
|
||||||
microcontroller.reset()
|
microcontroller.reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user