Roll back the tuple indexing change (now access by dot notation), optimize GESC and fix a bug in how it interacts with the reducer

This commit is contained in:
Josh Klar 2018-10-01 01:07:57 -07:00
parent b5457534bf
commit f80873fdd0
No known key found for this signature in database
GPG Key ID: 220F99BD7DB7A99E
4 changed files with 25 additions and 29 deletions

View File

@ -3,6 +3,11 @@ import logging
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, RawKeycodes from kmk.common.keycodes import Keycodes, RawKeycodes
GESC_TRIGGERS = {
Keycodes.Modifiers.KC_LSHIFT, Keycodes.Modifiers.KC_RSHIFT,
Keycodes.Modifiers.KC_LGUI, Keycodes.Modifiers.KC_RGUI,
}
def process_internal_key_event(state, action_type, changed_key, logger=None): def process_internal_key_event(state, action_type, changed_key, logger=None):
if logger is None: if logger is None:
@ -31,19 +36,15 @@ def process_internal_key_event(state, action_type, changed_key, logger=None):
def grave_escape(state, action_type, logger): def grave_escape(state, action_type, logger):
if action_type == KEY_DOWN_EVENT: if action_type == KEY_DOWN_EVENT:
for key in state.keys_pressed: if any(key in GESC_TRIGGERS for key in state.keys_pressed):
if key in { # if Shift is held, KC_GRAVE will become KC_TILDE on OS level
Keycodes.Modifiers.KC_LSHIFT, Keycodes.Modifiers.KC_RSHIFT, state.keys_pressed.add(Keycodes.Common.KC_GRAVE)
Keycodes.Modifiers.KC_LGUI, Keycodes.Modifiers.KC_RGUI,
}:
# if Shift is held, KC_GRAVE will become KC_TILDE on OS level
state.keys_pressed.add(Keycodes.Common.KC_GRAVE)
return state
# else return KC_ESC
state.keys_pressed.add(Keycodes.Common.KC_ESCAPE)
return state return state
# else return KC_ESC
state.keys_pressed.add(Keycodes.Common.KC_ESCAPE)
return state
elif action_type == KEY_UP_EVENT: elif action_type == KEY_UP_EVENT:
state.keys_pressed.discard(Keycodes.Common.KC_ESCAPE) state.keys_pressed.discard(Keycodes.Common.KC_ESCAPE)
state.keys_pressed.discard(Keycodes.Common.KC_GRAVE) state.keys_pressed.discard(Keycodes.Common.KC_GRAVE)

View File

@ -26,9 +26,9 @@ class ReduxStore:
self.logger.debug('Finished thunk') self.logger.debug('Finished thunk')
return None return None
self.logger.debug('Dispatching action: Type {} >> {}'.format(action[0], action)) self.logger.debug('Dispatching action: Type {} >> {}'.format(action.type, action))
self.state = self.reducer(self.state, action, logger=self.logger) self.state = self.reducer(self.state, action, logger=self.logger)
self.logger.debug('Dispatching complete: Type {}'.format(action[0])) self.logger.debug('Dispatching complete: Type {}'.format(action.type))
self.logger.debug('New state: {}'.format(self.state)) self.logger.debug('New state: {}'.format(self.state))
@ -132,10 +132,10 @@ def kmk_reducer(state=None, action=None, logger=None):
return state return state
if action[0] == NEW_MATRIX_EVENT: if action.type == NEW_MATRIX_EVENT:
matrix_keys_pressed = { matrix_keys_pressed = {
find_key_in_map(state, row, col) find_key_in_map(state, row, col)
for row, col in action[1] for row, col in action.matrix
} }
pressed = matrix_keys_pressed - state.keys_pressed pressed = matrix_keys_pressed - state.keys_pressed
@ -171,45 +171,41 @@ def kmk_reducer(state=None, action=None, logger=None):
logger=logger, logger=logger,
) )
state.matrix = action[1] state.matrix = action.matrix
state.keys_pressed |= pressed state.keys_pressed |= pressed
state.keys_pressed -= released state.keys_pressed -= released
state.hid_pending = True state.hid_pending = True
return state return state
if action[0] == KEYCODE_UP_EVENT: if action.type == KEYCODE_UP_EVENT:
state.keys_pressed.discard(action[1]) state.keys_pressed.discard(action.keycode)
state.hid_pending = True state.hid_pending = True
return state return state
if action[0] == KEYCODE_DOWN_EVENT: if action.type == KEYCODE_DOWN_EVENT:
state.keys_pressed.add(action[1]) state.keys_pressed.add(action.keycode)
state.hid_pending = True state.hid_pending = True
return state return state
if action[0] == INIT_FIRMWARE_EVENT: if action.type == INIT_FIRMWARE_EVENT:
return state.update( return state.update(
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,
unicode_mode=action.unicode_mode, unicode_mode=action.unicode_mode,
matrix=[
[False for c in action.col_pins]
for r in action.row_pins
],
) )
# HID events are non-mutating, used exclusively for listeners to know # HID events are non-mutating, used exclusively for listeners to know
# they should be doing things. This could/should arguably be folded back # they should be doing things. This could/should arguably be folded back
# into KEY_UP_EVENT and KEY_DOWN_EVENT, but for now it's nice to separate # into KEY_UP_EVENT and KEY_DOWN_EVENT, but for now it's nice to separate
# this out for debugging's sake. # this out for debugging's sake.
if action[0] == HID_REPORT_EVENT: if action.type == HID_REPORT_EVENT:
state.hid_pending = False state.hid_pending = False
return state return state
if action[0] == MACRO_COMPLETE_EVENT: if action.type == MACRO_COMPLETE_EVENT:
return state.update(macro_pending=None) return state.update(macro_pending=None)
# On unhandled events, log and do not mutate state # On unhandled events, log and do not mutate state

View File

@ -57,7 +57,6 @@ class MatrixScanner(AbstractMatrixScanner):
opin.value(0) opin.value(0)
if len(pressed) != self.last_pressed_len: if len(pressed) != self.last_pressed_len:
print('LEN PRESSED {} LEN LAST PRESSED {}'.format(len(pressed), self.last_pressed_len))
self.last_pressed_len = len(pressed) self.last_pressed_len = len(pressed)
return matrix_changed(pressed) return matrix_changed(pressed)

View File

@ -44,7 +44,7 @@ class HIDHelper:
self.report_non_mods = memoryview(self._evt)[3:] self.report_non_mods = memoryview(self._evt)[3:]
def _subscription(self, state, action): def _subscription(self, state, action):
if action[0] == HID_REPORT_EVENT: if action.type == HID_REPORT_EVENT:
self.clear_all() self.clear_all()
consumer_key = None consumer_key = None