Skip to content

Commit 93d355e

Browse files
committed
accept an initialized ShiftRegisterKeys
1 parent ec944e4 commit 93d355e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

adafruit_cursorcontrol/cursorcontrol_cursormanager.py

100755100644
+14-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
__version__ = "0.0.0+auto.0"
2525
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CursorControl.git"
2626

27-
2827
# PyBadge
2928
PYBADGE_BUTTON_LEFT = const(7)
3029
PYBADGE_BUTTON_UP = const(6)
@@ -41,18 +40,23 @@ class CursorManager:
4140
"""Simple interaction user interface interaction for Adafruit_CursorControl.
4241
4342
:param Cursor cursor: The cursor object we are using.
43+
:param ShiftRegisterKeys shift_register_keys: Optional initialized ShiftRegisterKeys object
44+
to use instead of having CursorManager initialize and control it.
4445
"""
4546

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

48-
def __init__(self, cursor: Cursor) -> None:
49+
def __init__(
50+
self, cursor: Cursor, shift_register_keys: ShiftRegisterKeys = None
51+
) -> None:
4952
self._cursor = cursor
5053
self._is_clicked = False
5154
self._is_alt_clicked = False
5255
self._is_select_clicked = False
5356
self._is_start_clicked = False
5457
self._pad_states = 0
5558
self._event = Event()
59+
self._pad = shift_register_keys
5660
self._init_hardware()
5761

5862
def __enter__(self) -> "CursorManager":
@@ -112,13 +116,14 @@ def _init_hardware(self) -> None:
112116
raise AttributeError(
113117
"Board must have a D-Pad or Joystick for use with CursorManager!"
114118
)
115-
self._pad = ShiftRegisterKeys(
116-
clock=board.BUTTON_CLOCK,
117-
data=board.BUTTON_OUT,
118-
latch=board.BUTTON_LATCH,
119-
key_count=8,
120-
value_when_pressed=True,
121-
)
119+
if self._pad is None:
120+
self._pad = ShiftRegisterKeys(
121+
clock=board.BUTTON_CLOCK,
122+
data=board.BUTTON_OUT,
123+
latch=board.BUTTON_LATCH,
124+
key_count=8,
125+
value_when_pressed=True,
126+
)
122127

123128
@property
124129
def is_clicked(self) -> bool:

0 commit comments

Comments
 (0)