From dc61988af7dfc1752c1c54d819e34649a4ec23f0 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Wed, 19 Apr 2023 12:03:27 -0400 Subject: [PATCH] start modularizing ardux core code --- ardux/__init__.py | 0 ardux/chord.py | 27 +++++++++++++++++++++++++++ kb.py => ardux/kb.py | 30 ++++-------------------------- main.py | 2 +- 4 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 ardux/__init__.py create mode 100644 ardux/chord.py rename kb.py => ardux/kb.py (59%) diff --git a/ardux/__init__.py b/ardux/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ardux/chord.py b/ardux/chord.py new file mode 100644 index 0000000..c5e0cb7 --- /dev/null +++ b/ardux/chord.py @@ -0,0 +1,27 @@ +from kmk.modules.combos import Chord + +# TODO: fix up pass by reference trick (wrapped in array) thats used below +# likely deserves a global but KmN couldnt figure it out +class ArduxChord(Chord): + # Override default constructor to allow passing of required fields + def __init__( + self, + match: Tuple[Union[Key, int], ...], + result: Key, + fast_reset=None, + per_key_timeout=None, + timeout=None, + match_coord=None, + ardux_keyboard=[], + layers=[], + ): + super().__init__(match, result, fast_reset, per_key_timeout, match_coord) + self.ardux_keyboard = ardux_keyboard + self.layers = layers + + # Override standard kmk match logic to first check active vs allowed layers + def matches(self, key: Key, int_coord: int): + if self.ardux_keyboard is None or len(self.ardux_keyboard) == 0 or len(self.layers) == 0 or any(i in self.ardux_keyboard[0].active_layers for i in self.layers): + return super().matches(key, int_coord) + + return False diff --git a/kb.py b/ardux/kb.py similarity index 59% rename from kb.py rename to ardux/kb.py index 54c0ae3..04011f1 100644 --- a/kb.py +++ b/ardux/kb.py @@ -1,38 +1,16 @@ import os + import board from kmk.quickpin.pro_micro.kb2040 import pinout as pins + from kmk.kmk_keyboard import KMKKeyboard from kmk.scanners.keypad import KeysScanner + from kmk.modules.layers import Layers from kmk.modules.combos import Combos, Chord +from ardux.chord import ArduxChord from kmk.keys import KC -@ -# TODO: fix up pass by reference trick (wrapped in array) thats used below -# likely deserves a global but KmN couldnt figure it out -class ArduxChord(Chord): - # Override default constructor to allow passing of required fields - def __init__( - self, - match: Tuple[Union[Key, int], ...], - result: Key, - fast_reset=None, - per_key_timeout=None, - timeout=None, - match_coord=None, - ardux_keyboard=[], - layers=[], - ): - super().__init__(match, result, fast_reset, per_key_timeout, match_coord) - self.ardux_keyboard = ardux_keyboard - self.layers = layers - - # Override standard kmk match logic to first check active vs allowed layers - def matches(self, key: Key, int_coord: int): - if self.ardux_keyboard is None or len(self.ardux_keyboard) == 0 or len(self.layers) == 0 or any(i in self.ardux_keyboard[0].active_layers for i in self.layers): - return super().matches(key, int_coord) - - return False class ArduxKeyboard(KMKKeyboard): coord_mapping = [ diff --git a/main.py b/main.py index 159b1ab..d857376 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import os ##### # Main keyboard object -from kb import ArduxKeyboard +from ardux.kb import ArduxKeyboard ardux_keyboard = ArduxKeyboard() #####