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
|
diode_orientation = DiodeOrientation.COLUMNS
|
||||||
|
|
||||||
keymap = [
|
keymap = [
|
||||||
[KC.ESC, KC.H, KC.BACKSPACE],
|
[KC.DF, KC.H, KC.RESET],
|
||||||
[KC.TAB, KC.I, KC.ENTER],
|
[KC.MO, KC.I, KC.ENTER],
|
||||||
[KC.CTRL, KC.SPACE, KC.SHIFT],
|
[KC.CTRL, KC.SPACE, KC.SHIFT],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5,32 +5,29 @@ KEY_DOWN_EVENT = const(2)
|
|||||||
INIT_FIRMWARE_EVENT = const(3)
|
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 {
|
return {
|
||||||
'type': INIT_FIRMWARE_EVENT,
|
'type': INIT_FIRMWARE_EVENT,
|
||||||
'keymap': keymap,
|
'keymap': keymap,
|
||||||
'row_pins': row_pins,
|
'row_pins': row_pins,
|
||||||
'col_pins': col_pins,
|
'col_pins': col_pins,
|
||||||
'diode_orientation': diode_orientation,
|
'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 {
|
return {
|
||||||
'type': KEY_UP_EVENT,
|
'type': KEY_UP_EVENT,
|
||||||
'keycode': keycode,
|
'keycode': keycode,
|
||||||
'row': row,
|
'row': row,
|
||||||
'col': col,
|
'col': col,
|
||||||
'active_layers': active_layers,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def key_down_event(keycode, row, col, active_layers):
|
def key_down_event(keycode, row, col):
|
||||||
return {
|
return {
|
||||||
'type': KEY_DOWN_EVENT,
|
'type': KEY_DOWN_EVENT,
|
||||||
'keycode': keycode,
|
'keycode': keycode,
|
||||||
'row': row,
|
'row': row,
|
||||||
'col': col,
|
'col': col,
|
||||||
'active_layers': active_layers,
|
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,46 @@
|
|||||||
def process(self, state, action):
|
import logging
|
||||||
self.logger.warning(action['keycode'])
|
|
||||||
if action['keycode'].code == 1000:
|
from kmk.common.event_defs import KEY_DOWN_EVENT, KEY_UP_EVENT
|
||||||
reset(self)
|
from kmk.common.keycodes import Keycodes
|
||||||
elif action['keycode'].code == 1050:
|
|
||||||
df(self, "Filler", action)
|
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def process(state, action, logger=None):
|
||||||
self.logger.debug('Rebooting to bootloader')
|
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
|
import machine
|
||||||
machine.bootloader()
|
machine.bootloader()
|
||||||
return self
|
|
||||||
|
|
||||||
|
|
||||||
def df(self, layer, action):
|
def df(state, layer, action, logger):
|
||||||
"""Switches the default layer"""
|
"""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"""
|
"""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):
|
def lm(layer, mod):
|
||||||
|
@ -4,6 +4,7 @@ import sys
|
|||||||
from kmk.common.consts import DiodeOrientation
|
from kmk.common.consts import DiodeOrientation
|
||||||
from kmk.common.event_defs import (INIT_FIRMWARE_EVENT, KEY_DOWN_EVENT,
|
from kmk.common.event_defs import (INIT_FIRMWARE_EVENT, KEY_DOWN_EVENT,
|
||||||
KEY_UP_EVENT)
|
KEY_UP_EVENT)
|
||||||
|
from kmk.common.internal_keycodes import process as process_internal
|
||||||
|
|
||||||
|
|
||||||
class ReduxStore:
|
class ReduxStore:
|
||||||
@ -93,7 +94,7 @@ def kmk_reducer(state=None, action=None, logger=None):
|
|||||||
return state
|
return state
|
||||||
|
|
||||||
if action['type'] == KEY_UP_EVENT:
|
if action['type'] == KEY_UP_EVENT:
|
||||||
return state.copy(
|
newstate = state.copy(
|
||||||
keys_pressed=frozenset(
|
keys_pressed=frozenset(
|
||||||
key for key in state.keys_pressed if key != action['keycode']
|
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:
|
if action['type'] == KEY_DOWN_EVENT:
|
||||||
return state.copy(
|
newstate = state.copy(
|
||||||
keys_pressed=(
|
keys_pressed=(
|
||||||
state.keys_pressed | {action['keycode']}
|
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:
|
if action['type'] == INIT_FIRMWARE_EVENT:
|
||||||
return state.copy(
|
return state.copy(
|
||||||
keymap=action['keymap'],
|
keymap=action['keymap'],
|
||||||
row_pins=action['row_pins'],
|
row_pins=action['row_pins'],
|
||||||
col_pins=action['col_pins'],
|
col_pins=action['col_pins'],
|
||||||
diode_orientation=action['diode_orientation'],
|
diode_orientation=action['diode_orientation'],
|
||||||
active_layers=action['active_layers'],
|
|
||||||
matrix=[
|
matrix=[
|
||||||
[False for c in action['col_pins']]
|
[False for c in action['col_pins']]
|
||||||
for r in action['row_pins']
|
for r in action['row_pins']
|
||||||
|
@ -12,7 +12,7 @@ except ImportError:
|
|||||||
|
|
||||||
class Firmware:
|
class Firmware:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, keymap, row_pins, col_pins, active_layers,
|
self, keymap, row_pins, col_pins,
|
||||||
diode_orientation, hid=None, log_level=logging.NOTSET,
|
diode_orientation, hid=None, log_level=logging.NOTSET,
|
||||||
):
|
):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -36,7 +36,6 @@ class Firmware:
|
|||||||
keymap=keymap,
|
keymap=keymap,
|
||||||
row_pins=row_pins,
|
row_pins=row_pins,
|
||||||
col_pins=col_pins,
|
col_pins=col_pins,
|
||||||
active_layers=active_layers,
|
|
||||||
diode_orientation=diode_orientation,
|
diode_orientation=diode_orientation,
|
||||||
))
|
))
|
||||||
|
|
||||||
@ -51,7 +50,6 @@ class Firmware:
|
|||||||
self.matrix = MatrixScanner(
|
self.matrix = MatrixScanner(
|
||||||
state.col_pins,
|
state.col_pins,
|
||||||
state.row_pins,
|
state.row_pins,
|
||||||
state.active_layers,
|
|
||||||
state.diode_orientation,
|
state.diode_orientation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import string
|
|||||||
|
|
||||||
from pyb import USB_HID, delay
|
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.event_defs import KEY_DOWN_EVENT, KEY_UP_EVENT
|
||||||
from kmk.common.keycodes import Keycodes, char_lookup
|
from kmk.common.keycodes import Keycodes, char_lookup
|
||||||
|
|
||||||
@ -50,20 +49,19 @@ class HIDHelper:
|
|||||||
|
|
||||||
def _subscription(self, state, action):
|
def _subscription(self, state, action):
|
||||||
if action['type'] == KEY_DOWN_EVENT:
|
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:
|
if action['keycode'].is_modifier:
|
||||||
self.add_modifier(action['keycode'])
|
self.add_modifier(action['keycode'])
|
||||||
self.send()
|
self.send()
|
||||||
else:
|
else:
|
||||||
self.add_key(action['keycode'])
|
self.add_key(action['keycode'])
|
||||||
self.send()
|
self.send()
|
||||||
else:
|
|
||||||
self.logger.warning('Triggering KMK keycodes')
|
|
||||||
internal_keycodes.process(self, state, action)
|
|
||||||
elif action['type'] == KEY_UP_EVENT:
|
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:
|
if action['keycode'].is_modifier:
|
||||||
self.remove_modifier(action['keycode'])
|
self.remove_modifier(action['keycode'])
|
||||||
self.send()
|
self.send()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user