From 93d355e63285685eca8ba53c1335f19d3ba96477 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 12:21:23 -0600 Subject: [PATCH 1/2] accept an initialized ShiftRegisterKeys --- .../cursorcontrol_cursormanager.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) mode change 100755 => 100644 adafruit_cursorcontrol/cursorcontrol_cursormanager.py diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py old mode 100755 new mode 100644 index 6921c2b..900daec --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -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) @@ -41,11 +40,15 @@ 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 + ) -> None: self._cursor = cursor self._is_clicked = False self._is_alt_clicked = False @@ -53,6 +56,7 @@ def __init__(self, cursor: Cursor) -> None: self._is_start_clicked = False self._pad_states = 0 self._event = Event() + self._pad = shift_register_keys self._init_hardware() def __enter__(self) -> "CursorManager": @@ -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: From 3b7dea29d6e5305dbfd4b77dc08e2bcf9ed88b8a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 14:04:17 -0600 Subject: [PATCH 2/2] Optional annotation --- adafruit_cursorcontrol/cursorcontrol_cursormanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py index 900daec..81d97df 100644 --- a/adafruit_cursorcontrol/cursorcontrol_cursormanager.py +++ b/adafruit_cursorcontrol/cursorcontrol_cursormanager.py @@ -47,7 +47,7 @@ class CursorManager: # pylint: disable=too-many-instance-attributes def __init__( - self, cursor: Cursor, shift_register_keys: ShiftRegisterKeys = None + self, cursor: Cursor, shift_register_keys: Optional[ShiftRegisterKeys] = None ) -> None: self._cursor = cursor self._is_clicked = False