Skip to content

Commit

Permalink
Merge pull request #39 from FoamyGuy/allow_reuse_shiftregisterkeys
Browse files Browse the repository at this point in the history
accept an initialized ShiftRegisterKeys
  • Loading branch information
FoamyGuy authored Nov 13, 2024
2 parents ec944e4 + 3b7dea2 commit 2704c15
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions adafruit_cursorcontrol/cursorcontrol_cursormanager.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git"


# PyBadge
PYBADGE_BUTTON_LEFT = const(7)
PYBADGE_BUTTON_UP = const(6)
Expand All @@ -41,18 +40,23 @@ class CursorManager:
"""Simple interaction user interface interaction for Adafruit_CursorControl.
:param Cursor cursor: The cursor object we are using.
:param ShiftRegisterKeys shift_register_keys: Optional initialized ShiftRegisterKeys object
to use instead of having CursorManager initialize and control it.
"""

# pylint: disable=too-many-instance-attributes

def __init__(self, cursor: Cursor) -> None:
def __init__(
self, cursor: Cursor, shift_register_keys: Optional[ShiftRegisterKeys] = None
) -> None:
self._cursor = cursor
self._is_clicked = False
self._is_alt_clicked = False
self._is_select_clicked = False
self._is_start_clicked = False
self._pad_states = 0
self._event = Event()
self._pad = shift_register_keys
self._init_hardware()

def __enter__(self) -> "CursorManager":
Expand Down Expand Up @@ -112,13 +116,14 @@ def _init_hardware(self) -> None:
raise AttributeError(
"Board must have a D-Pad or Joystick for use with CursorManager!"
)
self._pad = ShiftRegisterKeys(
clock=board.BUTTON_CLOCK,
data=board.BUTTON_OUT,
latch=board.BUTTON_LATCH,
key_count=8,
value_when_pressed=True,
)
if self._pad is None:
self._pad = ShiftRegisterKeys(
clock=board.BUTTON_CLOCK,
data=board.BUTTON_OUT,
latch=board.BUTTON_LATCH,
key_count=8,
value_when_pressed=True,
)

@property
def is_clicked(self) -> bool:
Expand Down

0 comments on commit 2704c15

Please sign in to comment.