diff --git a/adafruit_pybadger/__init__.py b/adafruit_pybadger/__init__.py index f4a5228..b656444 100755 --- a/adafruit_pybadger/__init__.py +++ b/adafruit_pybadger/__init__.py @@ -31,3 +31,5 @@ from .pybadge import pybadge as pybadger elif "PyGamer" in os.uname().machine: from .pygamer import pygamer as pybadger +elif "PyPortal" in os.uname().machine: + from .pyportal import pyportal as pybadger diff --git a/adafruit_pybadger/pyportal.py b/adafruit_pybadger/pyportal.py new file mode 100644 index 0000000..7e7c544 --- /dev/null +++ b/adafruit_pybadger/pyportal.py @@ -0,0 +1,79 @@ +# 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 `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +import board +import analogio +import audioio +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__() + + 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.""" diff --git a/examples/Blinka_PyPortal.bmp b/examples/Blinka_PyPortal.bmp new file mode 100644 index 0000000..a547e20 Binary files /dev/null and b/examples/Blinka_PyPortal.bmp differ diff --git a/examples/pybadger_pyportal_touchscreen.py b/examples/pybadger_pyportal_touchscreen.py new file mode 100644 index 0000000..7ce96e0 --- /dev/null +++ b/examples/pybadger_pyportal_touchscreen.py @@ -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 + )