Added Numpad V1.0 and added in support for automatically pressing and releasing macros to the abstract app
This commit is contained in:
@@ -12,11 +12,8 @@ from macropad_os.app_utils import rgb_from_int, MacroSet, Macro
|
||||
|
||||
COLOR_UPDATE_RATE = 33000000 # .033 seconds
|
||||
|
||||
SWAP_MODE = lambda x: not x
|
||||
|
||||
|
||||
class NumpadApp(App):
|
||||
|
||||
def __init__(self, macropad, config):
|
||||
super().__init__(macropad, config)
|
||||
self.name = "Numpad"
|
||||
@@ -29,17 +26,17 @@ class NumpadApp(App):
|
||||
self.modifier_pressed = False
|
||||
self.macros = MacroSet(
|
||||
[
|
||||
Macro("7", Keycode.KEYPAD_SEVEN), Macro("8", Keycode.KEYPAD_EIGHT), Macro("9", Keycode.KEYPAD_NINE),
|
||||
Macro("4", Keycode.KEYPAD_FOUR), Macro("5", Keycode.KEYPAD_FIVE), Macro("6", Keycode.KEYPAD_SIX),
|
||||
Macro("1", Keycode.KEYPAD_ONE), Macro("2", Keycode.KEYPAD_TWO), Macro("3", Keycode.KEYPAD_THREE),
|
||||
Macro("0", Keycode.KEYPAD_ZERO), Macro(".", Keycode.KEYPAD_PERIOD),
|
||||
Macro("7", Keycode.SEVEN), Macro("8", Keycode.EIGHT), Macro("9", Keycode.NINE),
|
||||
Macro("4", Keycode.FOUR), Macro("5", Keycode.FIVE), Macro("6", Keycode.SIX),
|
||||
Macro("1", Keycode.ONE), Macro("2", Keycode.TWO), Macro("3", Keycode.THREE),
|
||||
Macro("0", Keycode.ZERO), Macro(".", Keycode.PERIOD),
|
||||
Macro("Mod", self.swap_modifier, released=self.swap_modifier)
|
||||
],
|
||||
encoder_up=Macro("+", Keycode.KEYPAD_PLUS),
|
||||
encoder_down=Macro("-", Keycode.KEYPAD_MINUS),
|
||||
)
|
||||
self.mod_macros = MacroSet([
|
||||
Macro("<", Keycode.LEFT_ARROW), Macro(">", Keycode.RIGHT_ARROW), Macro("&", Keycode.SHIFT, Keycode.SEVEN),
|
||||
Macro("<", Keycode.SHIFT, Keycode.COMMA), Macro(">", Keycode.SHIFT, Keycode.PERIOD), Macro("&", Keycode.SHIFT, Keycode.SEVEN),
|
||||
|
||||
Macro("(", Keycode.SHIFT, Keycode.NINE), Macro(")", Keycode.SHIFT, Keycode.ZERO),Macro("%", Keycode.SHIFT, Keycode.FIVE),
|
||||
|
||||
@@ -104,20 +101,10 @@ class NumpadApp(App):
|
||||
self.set_colors(colors)
|
||||
|
||||
def process_keys_pressed_callback(self, key_event):
|
||||
for code in self.active_macros.get_macro_from_key(key_event).codes:
|
||||
if code:
|
||||
if callable(code):
|
||||
code()
|
||||
else:
|
||||
self.keyboard.send(code)
|
||||
self.press_macro(self.active_macros.get_macro_from_key(key_event))
|
||||
|
||||
def process_keys_released_callback(self, key_event):
|
||||
release_action = self.active_macros.get_macro_from_key(key_event).released
|
||||
if release_action:
|
||||
if callable(release_action):
|
||||
release_action()
|
||||
else:
|
||||
self.keyboard.send(release_action)
|
||||
self.release_macro(self.active_macros.get_macro_from_key(key_event))
|
||||
|
||||
def process_enbcoder_changed(self, key_event):
|
||||
print(key_event)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
from time import monotonic_ns
|
||||
|
||||
import displayio
|
||||
import terminalio
|
||||
from adafruit_display_text import label
|
||||
|
||||
from time import monotonic_ns, sleep
|
||||
|
||||
from adafruit_display_text import label
|
||||
from macropad_os import AppState, InvalidStateUpdateError, Config
|
||||
from macropad_os.app_utils import Macro
|
||||
|
||||
DISPLAY = displayio.Group()
|
||||
|
||||
@@ -12,12 +13,13 @@ DISPLAY = displayio.Group()
|
||||
def convert_to_keynum(x, y):
|
||||
return 3 * x + y
|
||||
|
||||
#TODO: Limit sounds to a similar rate as well for better performance
|
||||
|
||||
# TODO: Limit sounds to a similar rate as well for better performance
|
||||
|
||||
MAX_LIGHTING_UPDATE_RATE = 33000000 # .033 seconds
|
||||
|
||||
class App(object):
|
||||
|
||||
class App(object):
|
||||
def __init__(self, macropad, config: Config):
|
||||
"""
|
||||
|
||||
@@ -259,6 +261,63 @@ class App(object):
|
||||
self._labels = labels
|
||||
# if self._layout
|
||||
|
||||
def press_macro(self, macro:Macro) -> None:
|
||||
for item in macro.codes:
|
||||
if callable(item):
|
||||
item()
|
||||
elif isinstance(item, int):
|
||||
if item >= 0:
|
||||
self.macropad.keyboard.press(item)
|
||||
else:
|
||||
self.macropad.keyboard.release(-item)
|
||||
elif isinstance(item, float):
|
||||
sleep(item)
|
||||
elif isinstance(item, str):
|
||||
self.macropad.keyboard_layout.write(item)
|
||||
elif isinstance(item, list):
|
||||
for code in item:
|
||||
if isinstance(code, int):
|
||||
self.macropad.consumer_control.release()
|
||||
self.macropad.consumer_control.press(code)
|
||||
if isinstance(code, float):
|
||||
sleep(code)
|
||||
elif isinstance(item, dict):
|
||||
if 'buttons' in item:
|
||||
if item['buttons'] >= 0:
|
||||
self.macropad.mouse.press(item['buttons'])
|
||||
else:
|
||||
self.macropad.mouse.release(-item['buttons'])
|
||||
self.macropad.mouse.move(item['x'] if 'x' in item else 0,
|
||||
item['y'] if 'y' in item else 0,
|
||||
item['wheel'] if 'wheel' in item else 0)
|
||||
if 'tone' in item:
|
||||
if item['tone'] > 0:
|
||||
self.macropad.stop_tone()
|
||||
self.macropad.start_tone(item['tone'])
|
||||
else:
|
||||
self.macropad.stop_tone()
|
||||
elif 'play' in item:
|
||||
self.macropad.play_file(item['play'])
|
||||
|
||||
def release_macro(self, macro:Macro) -> None:
|
||||
for item in macro.codes:
|
||||
if isinstance(item, int):
|
||||
if item >= 0:
|
||||
self.macropad.keyboard.release(item)
|
||||
elif isinstance(item, dict):
|
||||
if 'buttons' in item:
|
||||
if item['buttons'] >= 0:
|
||||
self.macropad.mouse.release(item['buttons'])
|
||||
elif 'tone' in item:
|
||||
self.macropad.stop_tone()
|
||||
self.macropad.consumer_control.release()
|
||||
release_action = macro.released
|
||||
if release_action:
|
||||
if callable(release_action):
|
||||
release_action()
|
||||
else:
|
||||
self.keyboard.send(release_action)
|
||||
|
||||
def register_on_key_pressed(self, function) -> None:
|
||||
self._key_pressed_callbacks.append(function)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user