-
Notifications
You must be signed in to change notification settings - Fork 25
Refactor to include CLUE #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
10f29fc
Badge and business card work on CLUE.
kattni d5cdc1e
Basically working on CLUE and PyBadge LC.
kattni 928e009
Linting, comments.
kattni 9d3d819
Update example to use new import.
kattni a6273ff
Appease Sphinx.
kattni d426bd3
Appease Sphinx.
kattni c5bf2a6
Automock all the things.
kattni b78db48
Still Sphinxing.
kattni 0aada9e
SPHINX FINALLY BUILDS. Locally...
kattni 07f6d9f
Merge remote-tracking branch 'ada/master' into clue-adaptation
rhooper bca9d76
Merge pull request #1 from rhooper/clue-adaptation
kattni 391f5d1
Update README.
kattni 18489e7
Add 'd-pad' to PyGamer, fix docs.
kattni 778828f
PyGamer joystick fix.
kattni ee0b46a
Create enable_speaker method.
kattni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
Verifies which board is being used and imports the appropriate module. | ||
""" | ||
|
||
import os | ||
|
||
if "CLUE" in os.uname().machine: | ||
from .clue import clue as pybadger | ||
elif "Pybadge" in os.uname().machine: | ||
from .pybadge import pybadge as pybadger | ||
elif "PyGamer" in os.uname().machine: | ||
from .pygamer import pygamer as pybadger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
`adafruit_pybadger.clue` | ||
================================================================================ | ||
|
||
Badge-focused CircuitPython helper library for CLUE. | ||
|
||
|
||
* Author(s): Kattni Rembor | ||
|
||
Implementation Notes | ||
-------------------- | ||
|
||
**Hardware:** | ||
|
||
* `Adafruit CLUE <https://www.adafruit.com/product/4500>`_ | ||
|
||
**Software and Dependencies:** | ||
|
||
* Adafruit CircuitPython firmware for the supported boards: | ||
https://github.com/adafruit/circuitpython/releases | ||
|
||
""" | ||
|
||
from collections import namedtuple | ||
import board | ||
import digitalio | ||
import audiopwmio | ||
from gamepad import GamePad | ||
import adafruit_lsm6ds | ||
from adafruit_pybadger.pybadger_base import PyBadgerBase | ||
|
||
__version__ = "0.0.0-auto.0" | ||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git" | ||
|
||
Buttons = namedtuple("Buttons", "a b") | ||
|
||
class Clue(PyBadgerBase): | ||
"""Class that represents a single CLUE.""" | ||
_audio_out = audiopwmio.PWMAudioOut | ||
_neopixel_count = 1 | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
i2c = board.I2C() | ||
|
||
if i2c is not None: | ||
self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c) | ||
|
||
self._buttons = GamePad(digitalio.DigitalInOut(board.BUTTON_A), | ||
digitalio.DigitalInOut(board.BUTTON_B)) | ||
|
||
@property | ||
def button(self): | ||
"""The buttons on the board. | ||
|
||
Example use: | ||
|
||
.. code-block:: python | ||
|
||
from adafruit_pybadger import pybadger | ||
|
||
while True: | ||
if pybadger.button.a: | ||
print("Button A") | ||
elif pybadger.button.b: | ||
print("Button B") | ||
""" | ||
button_values = self._buttons.get_pressed() | ||
return Buttons(button_values & PyBadgerBase.BUTTON_B, | ||
button_values & PyBadgerBase.BUTTON_A) | ||
|
||
|
||
@property | ||
def _unsupported(self): | ||
"""This feature is not supported on CLUE.""" | ||
raise NotImplementedError("This feature is not supported on CLUE.") | ||
|
||
# The following is a list of the features available in other PyBadger modules but | ||
# not available for CLUE. If called while using a CLUE, they will result in the | ||
# NotImplementedError raised in the property above. | ||
play_file = _unsupported | ||
light = _unsupported | ||
|
||
clue = Clue() # pylint: disable=invalid-name | ||
"""Object that is automatically created on import.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
`adafruit_pybadger.pybadge` | ||
================================================================================ | ||
|
||
Badge-focused CircuitPython helper library for PyBadge, PyBadge LC and EdgeBadge. | ||
All three boards are included in this module as there is no difference in the | ||
CircuitPython builds at this time, and therefore no way to differentiate | ||
the boards from within CircuitPython. | ||
|
||
|
||
* Author(s): Kattni Rembor | ||
|
||
Implementation Notes | ||
-------------------- | ||
|
||
**Hardware:** | ||
|
||
* `Adafruit PyBadge <https://www.adafruit.com/product/4200>`_ | ||
* `Adafruit PyBadge LC <https://www.adafruit.com/product/3939>`_ | ||
* `Adafruit EdgeBadge <https://www.adafruit.com/product/4400>`_ | ||
|
||
**Software and Dependencies:** | ||
|
||
* Adafruit CircuitPython firmware for the supported boards: | ||
https://github.com/adafruit/circuitpython/releases | ||
|
||
""" | ||
|
||
from collections import namedtuple | ||
import board | ||
import digitalio | ||
import analogio | ||
import audioio | ||
from gamepadshift import GamePadShift | ||
import adafruit_lis3dh | ||
from adafruit_pybadger.pybadger_base import PyBadgerBase | ||
|
||
__version__ = "0.0.0-auto.0" | ||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git" | ||
|
||
Buttons = namedtuple("Buttons", "b a start select right down up left") | ||
|
||
class PyBadge(PyBadgerBase): | ||
"""Class that represents a single PyBadge, PyBadge LC, or EdgeBadge.""" | ||
|
||
_audio_out = audioio.AudioOut | ||
_neopixel_count = 5 | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
i2c = None | ||
|
||
if i2c is None: | ||
try: | ||
i2c = board.I2C() | ||
except RuntimeError: | ||
self._accelerometer = None | ||
|
||
if i2c is not None: | ||
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) | ||
try: | ||
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1) | ||
except ValueError: | ||
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) | ||
|
||
self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK), | ||
digitalio.DigitalInOut(board.BUTTON_OUT), | ||
digitalio.DigitalInOut(board.BUTTON_LATCH)) | ||
|
||
self._light_sensor = analogio.AnalogIn(board.A7) | ||
|
||
@property | ||
def button(self): | ||
"""The buttons on the board. | ||
|
||
Example use: | ||
|
||
.. code-block:: python | ||
|
||
from adafruit_pybadger import pybadger | ||
|
||
while True: | ||
if pybadger.button.a: | ||
print("Button A") | ||
elif pybadger.button.b: | ||
print("Button B") | ||
elif pybadger.button.start: | ||
print("Button start") | ||
elif pybadger.button.select: | ||
print("Button select") | ||
|
||
""" | ||
button_values = self._buttons.get_pressed() | ||
return Buttons(*[button_values & button for button in | ||
(PyBadgerBase.BUTTON_B, PyBadgerBase.BUTTON_A, | ||
PyBadgerBase.BUTTON_START, PyBadgerBase.BUTTON_SELECT, | ||
PyBadgerBase.BUTTON_RIGHT, PyBadgerBase.BUTTON_DOWN, | ||
PyBadgerBase.BUTTON_UP, PyBadgerBase.BUTTON_LEFT)]) | ||
|
||
pybadge = PyBadge() # pylint: disable=invalid-name | ||
"""Object that is automatically created on import.""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to check if the light sensor isn't present, like for the pybadge LC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyBadge LC has a light sensor. It's at the top, next to the reset button, with a hole over it to pass the front of the sensor through to the front of the board. From the back, it is white with a green symbol printed on it.
The lack of a light sensor would only be detectable in very specific situations (depending on whether the pin is connected to something else, has pull up or down, etc), and is a complicated process to do so. Knowing that the CLUE doesn't have the same light sensor, I included it in the
unsupported
list within the CLUE module. In the case of PyBadge vs. PyBadge LC, there's no way to tell the difference as they use the same CircuitPython build - there is no separate pin definition for PyBadge LC.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh, I meant the accelerometer, not the light sensor.
If it's possible to auto detect that, then this line from the example could be modified or removed to make the experience on a PyBadge LC a little nicer.
Adafruit_CircuitPython_PyBadger/examples/pybadger_simpletest.py
Line 6 in bf25d8b
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try checking what
pybadger.acceleration
returns on the LC. I think it might end up asNone
on there but I don't have one to check with.Along the same idea of improving the auto_dim: what if pressing any button would reset the dim timer. That would help all of the boards and allow for at least one type of auto_dim on the LC device.