Unbreak the general idea of KC_DF and KC_MO, though still needs heavy refactors
This commit is contained in:
parent
8a55dcca04
commit
392917082a
@ -17,8 +17,8 @@ def main():
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
|
||||
keymap = [
|
||||
[KC.ESC, KC.H, KC.BACKSPACE],
|
||||
[KC.TAB, KC.I, KC.ENTER],
|
||||
[KC.DF, KC.H, KC.RESET],
|
||||
[KC.MO, KC.I, KC.ENTER],
|
||||
[KC.CTRL, KC.SPACE, KC.SHIFT],
|
||||
]
|
||||
|
||||
|
@ -5,32 +5,29 @@ KEY_DOWN_EVENT = const(2)
|
||||
INIT_FIRMWARE_EVENT = const(3)
|
||||
|
||||
|
||||
def init_firmware(keymap, row_pins, col_pins, diode_orientation, active_layers):
|
||||
def init_firmware(keymap, row_pins, col_pins, diode_orientation):
|
||||
return {
|
||||
'type': INIT_FIRMWARE_EVENT,
|
||||
'keymap': keymap,
|
||||
'row_pins': row_pins,
|
||||
'col_pins': col_pins,
|
||||
'diode_orientation': diode_orientation,
|
||||
'active_layers': active_layers,
|
||||
}
|
||||
|
||||
|
||||
def key_up_event(keycode, row, col, active_layers):
|
||||
def key_up_event(keycode, row, col):
|
||||
return {
|
||||
'type': KEY_UP_EVENT,
|
||||
'keycode': keycode,
|
||||
'row': row,
|
||||
'col': col,
|
||||
'active_layers': active_layers,
|
||||
}
|
||||
|
||||
|
||||
def key_down_event(keycode, row, col, active_layers):
|
||||
def key_down_event(keycode, row, col):
|
||||
return {
|
||||
'type': KEY_DOWN_EVENT,
|
||||
'keycode': keycode,
|
||||
'row': row,
|
||||
'col': col,
|
||||
'active_layers': active_layers,
|
||||
}
|
||||
|
@ -1,25 +1,46 @@
|
||||
def process(self, state, action):
|
||||
self.logger.warning(action['keycode'])
|
||||
if action['keycode'].code == 1000:
|
||||
reset(self)
|
||||
elif action['keycode'].code == 1050:
|
||||
df(self, "Filler", action)
|
||||
import logging
|
||||
|
||||
from kmk.common.event_defs import KEY_DOWN_EVENT, KEY_UP_EVENT
|
||||
from kmk.common.keycodes import Keycodes
|
||||
|
||||
|
||||
def reset(self):
|
||||
self.logger.debug('Rebooting to bootloader')
|
||||
def process(state, action, logger=None):
|
||||
if action['keycode'].code < 1000:
|
||||
return state
|
||||
|
||||
if logger is None:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.warning(action['keycode'])
|
||||
if action['keycode'] == Keycodes.KMK.KC_RESET:
|
||||
return reset(logger)
|
||||
elif action['keycode'] == Keycodes.Layers.KC_DF:
|
||||
return df(state, "Filler", action, logger=logger)
|
||||
elif action['keycode'] == Keycodes.Layers.KC_MO:
|
||||
return mo(state, "Filler", action, logger=logger)
|
||||
|
||||
|
||||
def reset(logger):
|
||||
logger.debug('Rebooting to bootloader')
|
||||
import machine
|
||||
machine.bootloader()
|
||||
return self
|
||||
|
||||
|
||||
def df(self, layer, action):
|
||||
def df(state, layer, action, logger):
|
||||
"""Switches the default layer"""
|
||||
self.logger.warning(action['active_layers'])
|
||||
state.active_layers = [1]
|
||||
|
||||
return state
|
||||
|
||||
|
||||
def mo(layer):
|
||||
def mo(state, layer, action, logger):
|
||||
"""Momentarily activates layer, switches off when you let go"""
|
||||
if action['type'] == KEY_UP_EVENT:
|
||||
state.active_layers = [0]
|
||||
elif action['type'] == KEY_DOWN_EVENT:
|
||||
state.active_layers = [0, 1]
|
||||
|
||||
return state
|
||||
|
||||
|
||||
def lm(layer, mod):
|
||||
|
@ -4,6 +4,7 @@ import sys
|
||||
from kmk.common.consts import DiodeOrientation
|
||||
from kmk.common.event_defs import (INIT_FIRMWARE_EVENT, KEY_DOWN_EVENT,
|
||||
KEY_UP_EVENT)
|
||||
from kmk.common.internal_keycodes import process as process_internal
|
||||
|
||||
|
||||
class ReduxStore:
|
||||
@ -93,7 +94,7 @@ def kmk_reducer(state=None, action=None, logger=None):
|
||||
return state
|
||||
|
||||
if action['type'] == KEY_UP_EVENT:
|
||||
return state.copy(
|
||||
newstate = state.copy(
|
||||
keys_pressed=frozenset(
|
||||
key for key in state.keys_pressed if key != action['keycode']
|
||||
),
|
||||
@ -106,8 +107,13 @@ def kmk_reducer(state=None, action=None, logger=None):
|
||||
],
|
||||
)
|
||||
|
||||
if action['keycode'].code >= 1000:
|
||||
return process_internal(newstate, action, logger=logger)
|
||||
|
||||
return newstate
|
||||
|
||||
if action['type'] == KEY_DOWN_EVENT:
|
||||
return state.copy(
|
||||
newstate = state.copy(
|
||||
keys_pressed=(
|
||||
state.keys_pressed | {action['keycode']}
|
||||
),
|
||||
@ -120,13 +126,17 @@ def kmk_reducer(state=None, action=None, logger=None):
|
||||
],
|
||||
)
|
||||
|
||||
if action['keycode'].code >= 1000:
|
||||
return process_internal(newstate, action, logger=logger)
|
||||
|
||||
return newstate
|
||||
|
||||
if action['type'] == INIT_FIRMWARE_EVENT:
|
||||
return state.copy(
|
||||
keymap=action['keymap'],
|
||||
row_pins=action['row_pins'],
|
||||
col_pins=action['col_pins'],
|
||||
diode_orientation=action['diode_orientation'],
|
||||
active_layers=action['active_layers'],
|
||||
matrix=[
|
||||
[False for c in action['col_pins']]
|
||||
for r in action['row_pins']
|
||||
|
@ -12,7 +12,7 @@ except ImportError:
|
||||
|
||||
class Firmware:
|
||||
def __init__(
|
||||
self, keymap, row_pins, col_pins, active_layers,
|
||||
self, keymap, row_pins, col_pins,
|
||||
diode_orientation, hid=None, log_level=logging.NOTSET,
|
||||
):
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -36,7 +36,6 @@ class Firmware:
|
||||
keymap=keymap,
|
||||
row_pins=row_pins,
|
||||
col_pins=col_pins,
|
||||
active_layers=active_layers,
|
||||
diode_orientation=diode_orientation,
|
||||
))
|
||||
|
||||
@ -51,7 +50,6 @@ class Firmware:
|
||||
self.matrix = MatrixScanner(
|
||||
state.col_pins,
|
||||
state.row_pins,
|
||||
state.active_layers,
|
||||
state.diode_orientation,
|
||||
)
|
||||
|
||||
|
@ -3,7 +3,6 @@ import string
|
||||
|
||||
from pyb import USB_HID, delay
|
||||
|
||||
import kmk.common.internal_keycodes as internal_keycodes
|
||||
from kmk.common.event_defs import KEY_DOWN_EVENT, KEY_UP_EVENT
|
||||
from kmk.common.keycodes import Keycodes, char_lookup
|
||||
|
||||
@ -50,20 +49,19 @@ class HIDHelper:
|
||||
|
||||
def _subscription(self, state, action):
|
||||
if action['type'] == KEY_DOWN_EVENT:
|
||||
# If keycode is 1000 or over, these are internal keys
|
||||
if action['keycode'].code < 1000:
|
||||
if action['keycode'].code >= 1000:
|
||||
return
|
||||
|
||||
if action['keycode'].is_modifier:
|
||||
self.add_modifier(action['keycode'])
|
||||
self.send()
|
||||
else:
|
||||
self.add_key(action['keycode'])
|
||||
self.send()
|
||||
else:
|
||||
self.logger.warning('Triggering KMK keycodes')
|
||||
internal_keycodes.process(self, state, action)
|
||||
elif action['type'] == KEY_UP_EVENT:
|
||||
# If keycode is 1000 or over, these are internal keys
|
||||
if action['keycode'].code < 1000:
|
||||
if action['keycode'].code >= 1000:
|
||||
return
|
||||
|
||||
if action['keycode'].is_modifier:
|
||||
self.remove_modifier(action['keycode'])
|
||||
self.send()
|
||||
|
Loading…
x
Reference in New Issue
Block a user