Skip to content

Commit

Permalink
Update TestConsole to use GP2 on RP2040-based devices
Browse files Browse the repository at this point in the history
  • Loading branch information
fasteddy516 committed Feb 13, 2024
1 parent 63295af commit 8a24a2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 8 additions & 7 deletions docs/start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ When the test console loads up, you will be greeted with the following:
Using 1-based indexing.
Button Clicks = 0.25s
Test Button = board.D2
Enter command (? for list)
:
Expand Down Expand Up @@ -157,13 +158,13 @@ in-game.
joystick events** it will not capture events generated from the test console
because your serial terminal will be in-focus while you are typing in it.
For cases like these, the test console provides a single digital input - by
default on pin ``D2`` - which will repeat the last typed command when activated.
You can either hook up an actual button, or just short ``D2`` to ground to
trigger commands as needed. In the game example above, you would enter the
desired command in the test console and press enter, then switch to the game
and use the button input to trigger that command while the game is in focus.
If needed, the button pin can also be changed when the test console is started
as follows:
default on pin ``D2`` (``GP2`` on RP2040-based devices) - which will repeat
the last typed command when activated. You can either hook up an actual
button, or just short the pin to ground to trigger commands as needed. In
the game example above, you would enter the desired command in the test
console and press enter, then switch to the game and use the button input to
trigger that command while the game is in focus. If needed, the button pin
can also be changed when the test console is started as follows:

.. code-block:: text
Expand Down
15 changes: 13 additions & 2 deletions joystick_xl/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ def TestHats(js: Joystick, pace: float = 0.25, quiet: bool = False) -> None:


def TestConsole(button_pin: Pin = None):
"""Run JoystickXL's REPL-based, built-in test console."""
"""
Run JoystickXL's REPL-based, built-in test console.
:param button_pin: Specify the pin to use as TestConsole's test button. Defaults
to ``board.D2`` (``board.GP2`` on RP2040-based devices).
:type button_pin: microcontroller.Pin, optional
"""
INVALID_OPERATION = "> Invalid operation."

js = Joystick()
Expand Down Expand Up @@ -133,7 +139,12 @@ def MoveAxis(axis: int, stop: int, step: int) -> None:
try:
# Attempt to configure a test button
if button_pin is None:
pin = board.D2
try:
# for most CircuitPython boards
pin = board.D2
except AttributeError:
# for RP2040-based boards
pin = board.GP2
else:
pin = button_pin
button = digitalio.DigitalInOut(pin)
Expand Down

0 comments on commit 8a24a2e

Please sign in to comment.