Skip to content

Commit

Permalink
Added diagonal triggers for hat switches in TestConsole
Browse files Browse the repository at this point in the history
  • Loading branch information
fasteddy516 committed Aug 20, 2021
1 parent 37b3110 commit c772463
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions joystick_xl/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c772463

Please sign in to comment.