From c77246383dca828134e7ecd5da9c04525448f14e Mon Sep 17 00:00:00 2001 From: Edward Wright Date: Thu, 19 Aug 2021 21:33:07 -0400 Subject: [PATCH] Added diagonal triggers for hat switches in TestConsole --- joystick_xl/tools.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/joystick_xl/tools.py b/joystick_xl/tools.py index 180777f..011f35e 100644 --- a/joystick_xl/tools.py +++ b/joystick_xl/tools.py @@ -103,6 +103,7 @@ def TestHats(js: Joystick, pace: float = 0.25, quiet: bool = False) -> None: def TestConsole(button_pin: Pin = board.D2): """Run JoystickXL's REPL-based, built-in test console.""" INVALID_OPERATION = "> Invalid operation." + PRESS_TIME = 0.25 button = digitalio.DigitalInOut(button_pin) button.direction = digitalio.Direction.INPUT @@ -166,7 +167,7 @@ def ValidateIndex(i: int, limit: int, name: str) -> int: continue print("> Axis", i + si, operation) js.update_axis((i, value)) - time.sleep(1) + time.sleep(PRESS_TIME) js.update_axis((i, Axis.IDLE)) # button functions @@ -179,7 +180,7 @@ def ValidateIndex(i: int, limit: int, name: str) -> int: continue print("> Button", i + si, "CLICK") js.update_button((i, True)) - time.sleep(1) + time.sleep(PRESS_TIME) js.update_button((i, False)) # hat functions @@ -190,6 +191,18 @@ def ValidateIndex(i: int, limit: int, name: str) -> int: i = ValidateIndex(num, js.num_hats, "hat switch") if i < 0: continue + elif "u" in cmd and "l" in cmd: + operation = "UP+LEFT" + value = Hat.UL + elif "u" in cmd and "r" in cmd: + operation = "UP+RIGHT" + value = Hat.UR + elif "d" in cmd and "l" in cmd: + operation = "DOWN+LEFT" + value = Hat.DL + elif "d" in cmd and "r" in cmd: + operation = "DOWN+RIGHT" + value = Hat.DR elif cmd.endswith("u"): operation = "UP" value = Hat.U @@ -207,7 +220,7 @@ def ValidateIndex(i: int, limit: int, name: str) -> int: continue print("> Hat Switch", i + si, operation) js.update_hat((i, value)) - time.sleep(1) + time.sleep(PRESS_TIME) js.update_hat((i, Hat.IDLE)) # auto-test functions