2018-09-03 22:50:12 +02:00
|
|
|
import logging
|
|
|
|
|
2018-09-04 00:21:34 +02:00
|
|
|
from kmk.common.event_defs import init_firmware
|
2018-10-06 12:58:19 +02:00
|
|
|
from kmk.common.internal_state import Store, kmk_reducer
|
2018-09-03 12:22:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Firmware:
|
2018-09-03 22:50:12 +02:00
|
|
|
def __init__(
|
2018-09-22 08:44:30 +02:00
|
|
|
self, keymap, row_pins, col_pins,
|
Massive refactor largely to support Unicode on Mac
This does a bunch of crazy stuff:
- The ability to set a unicode mode (right now only Linux+ibus or
MacOS-RALT) in the keymap. This will be changeable at runtime soon, to
allow a single keyboard to be able to send table flips and whatever
other crazy stuff on any OS the board is plugged into (something that's
not currently doable on QMK, so yay us?)
- As part of the above, there is now just one user-facing macro for
unicode codepoint submission,
`kmk.common.macros.unicode.unicode_sequence`. Users should never use the
platform-specific macros, partly because they just outright won't work.
There's all sorts of fun stuff in these methods now, thank goodness
MicroPython supports the `yield from` construct.
- Keycode (these should really be renamed Keysym or something) objects
that are intended to not be pressed, or not be released. Right now these
properties are completely ignored if not part of a macro, and it's
probably sane to keep it that way. This was necessary to support MacOS's
"hold RALT while typing the codepoint characters" flow.
- Other refactor-y bits, like moving macro support to `kmk/common`
rather than sitting at the top level of the tree. One day `kmk/common`
may make sense to surface at top level `kmk/`, but that's a discussion
for another day.
2018-10-01 04:33:23 +02:00
|
|
|
diode_orientation, unicode_mode=None,
|
|
|
|
hid=None, log_level=logging.NOTSET,
|
2018-10-06 10:32:17 +02:00
|
|
|
matrix_scanner=None,
|
2018-09-03 22:50:12 +02:00
|
|
|
):
|
2018-10-06 10:32:17 +02:00
|
|
|
assert matrix_scanner is not None
|
|
|
|
self.matrix_scanner = matrix_scanner
|
|
|
|
|
2018-09-17 08:20:16 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger.setLevel(log_level)
|
|
|
|
|
2018-10-01 09:31:45 +02:00
|
|
|
self.hydrated = False
|
|
|
|
|
2018-10-06 12:58:19 +02:00
|
|
|
self.store = Store(kmk_reducer, log_level=log_level)
|
2018-09-04 00:21:34 +02:00
|
|
|
self.store.subscribe(
|
|
|
|
lambda state, action: self._subscription(state, action),
|
|
|
|
)
|
2018-09-17 08:20:16 +02:00
|
|
|
|
2018-10-06 10:32:17 +02:00
|
|
|
if hid:
|
|
|
|
self.hid = hid(store=self.store, log_level=log_level)
|
|
|
|
else:
|
2018-09-17 08:20:16 +02:00
|
|
|
logger.warning(
|
|
|
|
"Must provide a HIDHelper (arg: hid), disabling HID\n"
|
|
|
|
"Board will run in debug mode",
|
|
|
|
)
|
|
|
|
|
2018-09-04 00:21:34 +02:00
|
|
|
self.store.dispatch(init_firmware(
|
|
|
|
keymap=keymap,
|
|
|
|
row_pins=row_pins,
|
|
|
|
col_pins=col_pins,
|
|
|
|
diode_orientation=diode_orientation,
|
Massive refactor largely to support Unicode on Mac
This does a bunch of crazy stuff:
- The ability to set a unicode mode (right now only Linux+ibus or
MacOS-RALT) in the keymap. This will be changeable at runtime soon, to
allow a single keyboard to be able to send table flips and whatever
other crazy stuff on any OS the board is plugged into (something that's
not currently doable on QMK, so yay us?)
- As part of the above, there is now just one user-facing macro for
unicode codepoint submission,
`kmk.common.macros.unicode.unicode_sequence`. Users should never use the
platform-specific macros, partly because they just outright won't work.
There's all sorts of fun stuff in these methods now, thank goodness
MicroPython supports the `yield from` construct.
- Keycode (these should really be renamed Keysym or something) objects
that are intended to not be pressed, or not be released. Right now these
properties are completely ignored if not part of a macro, and it's
probably sane to keep it that way. This was necessary to support MacOS's
"hold RALT while typing the codepoint characters" flow.
- Other refactor-y bits, like moving macro support to `kmk/common`
rather than sitting at the top level of the tree. One day `kmk/common`
may make sense to surface at top level `kmk/`, but that's a discussion
for another day.
2018-10-01 04:33:23 +02:00
|
|
|
unicode_mode=unicode_mode,
|
2018-09-04 00:21:34 +02:00
|
|
|
))
|
|
|
|
|
|
|
|
def _subscription(self, state, action):
|
2018-10-01 09:31:45 +02:00
|
|
|
if not self.hydrated:
|
2018-10-06 10:32:17 +02:00
|
|
|
self.matrix = self.matrix_scanner(
|
2018-09-04 00:21:34 +02:00
|
|
|
state.col_pins,
|
|
|
|
state.row_pins,
|
|
|
|
state.diode_orientation,
|
|
|
|
)
|
2018-10-01 09:31:45 +02:00
|
|
|
self.hydrated = True
|
2018-09-03 12:22:11 +02:00
|
|
|
|
|
|
|
def go(self):
|
|
|
|
while True:
|
2018-10-01 09:31:45 +02:00
|
|
|
update = self.matrix.scan_for_pressed()
|
2018-09-23 06:49:58 +02:00
|
|
|
|
|
|
|
if update:
|
|
|
|
self.store.dispatch(update)
|