Skip to content

Commit 97d1d63

Browse files
authored
Merge pull request #72 from dherrada/master
Added docstring to make #51 pass travis
2 parents a54bb0f + a7bb5b2 commit 97d1d63

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

adafruit_circuitplayground/express.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
import digitalio
6161
import neopixel
6262
import touchio
63+
import gamepad
64+
6365

6466
__version__ = "0.0.0-auto.0"
6567
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git"
@@ -90,6 +92,7 @@ def __init__(self):
9092
self._a.switch_to_input(pull=digitalio.Pull.DOWN)
9193
self._b = digitalio.DigitalInOut(board.BUTTON_B)
9294
self._b.switch_to_input(pull=digitalio.Pull.DOWN)
95+
self.gamepad = gamepad.GamePad(self._a, self._b)
9396

9497
# Define switch:
9598
self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
@@ -479,6 +482,27 @@ def button_b(self):
479482
"""
480483
return self._b.value
481484

485+
@property
486+
def were_pressed(self):
487+
"""Returns a set of the buttons that have been pressed
488+
489+
.. image :: ../docs/_static/button_b.jpg
490+
:alt: Button B
491+
492+
.. code-block:: python
493+
494+
from adafruit_circuitplayground.express import cpx
495+
496+
while True:
497+
print(cpx.were_pressed)
498+
"""
499+
ret = set()
500+
pressed = self.gamepad.get_pressed()
501+
for button, mask in (('A', 0x01), ('B', 0x02)):
502+
if mask & pressed:
503+
ret.add(button)
504+
return ret
505+
482506
@property
483507
def switch(self):
484508
"""

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'NeoPixel': ('https://circuitpython.readthedocs.io/projects/neopixel/en/latest/', None)}
2121

2222
# Libraries we depend on but don't need for generating docs.
23-
autodoc_mock_imports = ["board", "analogio", "digitalio", "neopixel", "adafruit_thermistor", "audioio", "touchio", "adafruit_lis3dh", "busio"]
23+
autodoc_mock_imports = ["board", "analogio", "digitalio", "neopixel", "adafruit_thermistor", "audioio", "touchio", "adafruit_lis3dh", "busio", "gamepad"]
2424

2525
# Add any paths that contain templates here, relative to this directory.
2626
templates_path = ['_templates']

0 commit comments

Comments
 (0)