Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept an initialized ShiftRegisterKeys #39

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ShiftRegisterKeys = None
tekktrik marked this conversation as resolved.
Show resolved Hide resolved
) -> 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