Skip to content

Adding PyPortal and Pew Pew M4 support #34

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 11 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions adafruit_pybadger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
from .pybadge import pybadge as pybadger
elif "PyGamer" in os.uname().machine:
from .pygamer import pygamer as pybadger
elif "PewPew M4" in os.uname().machine:
from .pewpewm4 import pewpewm4 as pybadger
elif "PyPortal" in os.uname().machine:
from .pyportal import pyportal as pybadger
6 changes: 6 additions & 0 deletions adafruit_pybadger/clue.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import audiopwmio
from gamepad import GamePad
import adafruit_lsm6ds
import neopixel
from adafruit_pybadger.pybadger_base import PyBadgerBase

__version__ = "0.0.0-auto.0"
Expand All @@ -70,6 +71,11 @@ def __init__(self):
if i2c is not None:
self._accelerometer = adafruit_lsm6ds.LSM6DS33(i2c)

# NeoPixels
self._neopixels = neopixel.NeoPixel(
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
)

self._buttons = GamePad(
digitalio.DigitalInOut(board.BUTTON_A),
digitalio.DigitalInOut(board.BUTTON_B),
Expand Down
123 changes: 123 additions & 0 deletions adafruit_pybadger/pewpewm4.py
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.clue`
================================================================================

Badge-focused CircuitPython helper library for Pew Pew M4.


* Author(s): Kattni Rembor

Implementation Notes
--------------------

**Hardware:**

* `Pew Pew M4 <https://hackaday.io/project/165032-pewpew-m4>`_

**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 audioio
from gamepad import GamePad
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", ("o", "x", "z", "right", "down", "up", "left"))


class PewPewM4(PyBadgerBase):
"""Class that represents a single Pew Pew M4."""

_audio_out = audioio.AudioOut
_neopixel_count = 0

def __init__(self):
super().__init__()

self._buttons = GamePad(
digitalio.DigitalInOut(board.BUTTON_O),
digitalio.DigitalInOut(board.BUTTON_X),
digitalio.DigitalInOut(board.BUTTON_Z),
digitalio.DigitalInOut(board.BUTTON_RIGHT),
digitalio.DigitalInOut(board.BUTTON_DOWN),
digitalio.DigitalInOut(board.BUTTON_UP),
digitalio.DigitalInOut(board.BUTTON_LEFT),
)

@property
def button(self):
"""The buttons on the board.

Example use:

.. code-block:: python

from adafruit_pybadger import pybadger

while True:
if pybadger.button.x:
print("Button X")
elif pybadger.button.o:
print("Button O")
"""
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,
)
]
)

@property
def _unsupported(self):
"""This feature is not supported on PewPew M4."""
raise NotImplementedError("This feature is not supported on PewPew M4.")

# 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.
light = _unsupported
acceleration = _unsupported
pixels = _unsupported


pewpewm4 = PewPewM4() # pylint: disable=invalid-name
"""Object that is automatically created on import."""
6 changes: 6 additions & 0 deletions adafruit_pybadger/pybadge.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import audioio
from gamepadshift import GamePadShift
import adafruit_lis3dh
import neopixel
from adafruit_pybadger.pybadger_base import PyBadgerBase

__version__ = "0.0.0-auto.0"
Expand Down Expand Up @@ -88,6 +89,11 @@ def __init__(self):
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

# NeoPixels
self._neopixels = neopixel.NeoPixel(
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
)

self._buttons = GamePadShift(
digitalio.DigitalInOut(board.BUTTON_CLOCK),
digitalio.DigitalInOut(board.BUTTON_OUT),
Expand Down
8 changes: 2 additions & 6 deletions adafruit_pybadger/pybadger_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@
import audiocore
except ImportError:
import audioio as audiocore
from adafruit_bitmap_font import bitmap_font
import displayio
import neopixel
from adafruit_display_shapes.rect import Rect
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
import terminalio
import adafruit_miniqr

Expand Down Expand Up @@ -136,10 +135,7 @@ def __init__(self):
self.display = board.DISPLAY
self._display_brightness = 1.0

# NeoPixels
self._neopixels = neopixel.NeoPixel(
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
)
self._neopixels = None

# Auto dim display based on movement
self._last_accelerometer = None
Expand Down
6 changes: 6 additions & 0 deletions adafruit_pybadger/pygamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import analogio
import digitalio
import audioio
import neopixel
from gamepadshift import GamePadShift
import adafruit_lis3dh
from adafruit_pybadger.pybadger_base import PyBadgerBase
Expand Down Expand Up @@ -76,6 +77,11 @@ def __init__(self):
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

# NeoPixels
self._neopixels = neopixel.NeoPixel(
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
)

self._buttons = GamePadShift(
digitalio.DigitalInOut(board.BUTTON_CLOCK),
digitalio.DigitalInOut(board.BUTTON_OUT),
Expand Down
83 changes: 83 additions & 0 deletions adafruit_pybadger/pyportal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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.pyportal`
================================================================================

Badge-focused CircuitPython helper library for PyPortal.


* Author(s): Kattni Rembor

Implementation Notes
--------------------

**Hardware:**

* `Adafruit PyPortal <https://www.adafruit.com/product/4116>`_

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases

"""
import board
import analogio
import audioio
import neopixel
from adafruit_pybadger.pybadger_base import PyBadgerBase

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"


class PyPortal(PyBadgerBase):
"""Class that represents a single PyPortal."""

_audio_out = audioio.AudioOut
_neopixel_count = 1

def __init__(self):
super().__init__()

# NeoPixels
self._neopixels = neopixel.NeoPixel(
board.NEOPIXEL, self._neopixel_count, brightness=1, pixel_order=neopixel.GRB
)
self._light_sensor = analogio.AnalogIn(board.LIGHT)

@property
def _unsupported(self):
"""This feature is not supported on PyPortal."""
raise NotImplementedError("This feature is not supported on PyPortal.")

# The following is a list of the features available in other PyBadger modules but
# not available for PyPortal. If called while using a PyPortal, they will result in the
# NotImplementedError raised in the property above.
button = _unsupported
acceleration = _unsupported
auto_dim_display = _unsupported


pyportal = PyPortal() # pylint: disable=invalid-name
"""Object that is automatically created on import."""
Binary file added examples/Blinka_PewPewM4.bmp
Binary file not shown.
Binary file added examples/Blinka_PyPortal.bmp
Binary file not shown.
25 changes: 25 additions & 0 deletions examples/pybadger_pewpewm4_simpletest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Simpletest example using the Pew Pew M4.
Use the O, X, and Z buttons to change between examples."""
from adafruit_pybadger import pybadger

pybadger.show_badge(
name_string="Blinka", hello_scale=3, my_name_is_scale=3, name_scale=4
)

while True:
if pybadger.button.o:
pybadger.show_business_card(
image_name="Blinka_PewPewM4.bmp",
name_string="Blinka",
name_scale=4,
email_string_one="blinka@",
email_string_two="adafruit.com",
email_scale_one=2,
email_scale_two=2,
)
elif pybadger.button.x:
pybadger.show_qr_code(data="https://circuitpython.org")
elif pybadger.button.z:
pybadger.show_badge(
name_string="Blinka", hello_scale=3, my_name_is_scale=3, name_scale=4
)
47 changes: 47 additions & 0 deletions examples/pybadger_pyportal_touchscreen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Simpletest example using Adafruit PyPortal. Uses the touchscreen to advance between examples."""
import board
from adafruit_pybadger import pybadger
import adafruit_touchscreen

# pylint: disable=invalid-name

# These pins are used as both analog and digital! XL, XR and YU must be analog
# and digital capable. YD just need to be digital
ts = adafruit_touchscreen.Touchscreen(
board.TOUCH_XL,
board.TOUCH_XR,
board.TOUCH_YD,
board.TOUCH_YU,
calibration=((5200, 59000), (5800, 57000)),
size=(320, 240),
)

pybadger.show_badge(
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
)

cur_example = 0
prev_touch = None
while True:
p = ts.touch_point
if p and not prev_touch:
cur_example += 1
if cur_example >= 3:
cur_example = 0
print(cur_example)
prev_touch = p

if cur_example == 0:
pybadger.show_business_card(
image_name="Blinka_PyPortal.bmp",
name_string="Blinka",
name_scale=2,
email_string_one="blinka@",
email_string_two="adafruit.com",
)
elif cur_example == 1:
pybadger.show_qr_code(data="https://circuitpython.org")
elif cur_example == 2:
pybadger.show_badge(
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
)