Move all remaining state into the single store, woot!
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
|
||||
from kmk.common.event_defs import init_firmware
|
||||
from kmk.common.internal_state import ReduxStore, kmk_reducer
|
||||
from kmk.common.keymap import Keymap
|
||||
|
||||
@@ -14,10 +15,31 @@ class Firmware:
|
||||
self, keymap, row_pins, col_pins, diode_orientation,
|
||||
log_level=logging.NOTSET,
|
||||
):
|
||||
self.raw_keymap = keymap
|
||||
self.keymap = Keymap(keymap)
|
||||
self.matrix = MatrixScanner(col_pins, row_pins, diode_orientation)
|
||||
self.cached_state = None
|
||||
self.store = ReduxStore(kmk_reducer, log_level=log_level)
|
||||
self.store.subscribe(
|
||||
lambda state, action: self._subscription(state, action),
|
||||
)
|
||||
self.store.dispatch(init_firmware(
|
||||
keymap=keymap,
|
||||
row_pins=row_pins,
|
||||
col_pins=col_pins,
|
||||
diode_orientation=diode_orientation,
|
||||
))
|
||||
|
||||
def _subscription(self, state, action):
|
||||
if self.cached_state is None or self.cached_state.keymap != state.keymap:
|
||||
self.keymap = Keymap(state.keymap)
|
||||
|
||||
if self.cached_state is None or any(
|
||||
getattr(self.cached_state, k) != getattr(state, k)
|
||||
for k in state.__dict__.keys()
|
||||
):
|
||||
self.matrix = MatrixScanner(
|
||||
state.col_pins,
|
||||
state.row_pins,
|
||||
state.diode_orientation,
|
||||
)
|
||||
|
||||
def go(self):
|
||||
while True:
|
||||
|
Reference in New Issue
Block a user