From ec8162d3a73dba674d9fe5a429a708457906c7c3 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Thu, 2 May 2019 19:11:29 +0200 Subject: [PATCH 1/2] Add "were_pressed" property to cpx --- adafruit_circuitplayground/express.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index f9eeaaf..98ccd40 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -56,6 +56,8 @@ import digitalio import neopixel import touchio +import gamepad + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git" @@ -86,6 +88,7 @@ def __init__(self): self._a.switch_to_input(pull=digitalio.Pull.DOWN) self._b = digitalio.DigitalInOut(board.BUTTON_B) self._b.switch_to_input(pull=digitalio.Pull.DOWN) + self.gamepad = gamepad.GamePad(self._a, self._b) # Define switch: self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH) @@ -475,6 +478,15 @@ def button_b(self): """ return self._b.value + @property + def were_pressed(self): + ret = set() + pressed = self.gamepad.get_pressed() + for button, mask in (('A', 0x01), ('B', 0x02)): + if mask & pressed: + ret.add(button) + return ret + @property def switch(self): """ From a7bb5b238803b079c8110cdcfdee5bb39f69755b Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 7 Oct 2019 14:24:41 -0400 Subject: [PATCH 2/2] Unified all whitespace commits --- adafruit_circuitplayground/express.py | 12 ++++++++++++ docs/conf.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index 69c1af3..ccfb788 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -484,6 +484,18 @@ def button_b(self): @property def were_pressed(self): + """Returns a set of the buttons that have been pressed + + .. image :: ../docs/_static/button_b.jpg + :alt: Button B + + .. code-block:: python + + from adafruit_circuitplayground.express import cpx + + while True: + print(cpx.were_pressed) + """ ret = set() pressed = self.gamepad.get_pressed() for button, mask in (('A', 0x01), ('B', 0x02)): diff --git a/docs/conf.py b/docs/conf.py index 623fc90..30f104d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ 'NeoPixel': ('https://circuitpython.readthedocs.io/projects/neopixel/en/latest/', None)} # Libraries we depend on but don't need for generating docs. -autodoc_mock_imports = ["board", "analogio", "digitalio", "neopixel", "adafruit_thermistor", "audioio", "touchio", "adafruit_lis3dh", "busio"] +autodoc_mock_imports = ["board", "analogio", "digitalio", "neopixel", "adafruit_thermistor", "audioio", "touchio", "adafruit_lis3dh", "busio", "gamepad"] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates']