Skip to content

Commit 31da0f4

Browse files
committed
adding support for PyPortal and simpletest example.
1 parent 8aca7b9 commit 31da0f4

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

adafruit_pybadger/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@
3131
from .pybadge import pybadge as pybadger
3232
elif "PyGamer" in os.uname().machine:
3333
from .pygamer import pygamer as pybadger
34+
elif "PyPortal" in os.uname().machine:
35+
from .pyportal import pyportal as pybadger

adafruit_pybadger/pyportal.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_pybadger.pyportal`
24+
================================================================================
25+
26+
Badge-focused CircuitPython helper library for PyPortal.
27+
28+
29+
* Author(s): Kattni Rembor
30+
31+
Implementation Notes
32+
--------------------
33+
34+
**Hardware:**
35+
36+
* `Adafruit PyPortal <https://www.adafruit.com/product/4116>`_
37+
38+
**Software and Dependencies:**
39+
40+
* Adafruit CircuitPython firmware for the supported boards:
41+
https://github.com/adafruit/circuitpython/releases
42+
43+
"""
44+
45+
import audioio
46+
from adafruit_pybadger.pybadger_base import PyBadgerBase
47+
48+
__version__ = "0.0.0-auto.0"
49+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
50+
51+
52+
class PyPortal(PyBadgerBase):
53+
"""Class that represents a single PyPortal."""
54+
55+
_audio_out = audioio.AudioOut
56+
_neopixel_count = 1
57+
58+
@property
59+
def _unsupported(self):
60+
"""This feature is not supported on PyPortal."""
61+
raise NotImplementedError("This feature is not supported on PyPortal.")
62+
63+
# The following is a list of the features available in other PyBadger modules but
64+
# not available for PyPortal. If called while using a PyPortal, they will result in the
65+
# NotImplementedError raised in the property above.
66+
play_file = _unsupported
67+
light = _unsupported
68+
button = _unsupported
69+
70+
71+
pyportal = PyPortal() # pylint: disable=invalid-name
72+
"""Object that is automatically created on import."""
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Simpletest examaple using Adafruit PyPortal. Uses the touchscreen to advance between examples."""
2+
import board
3+
from adafruit_pybadger import pybadger
4+
import adafruit_touchscreen
5+
6+
# pylint: disable=invalid-name
7+
8+
# These pins are used as both analog and digital! XL, XR and YU must be analog
9+
# and digital capable. YD just need to be digital
10+
ts = adafruit_touchscreen.Touchscreen(
11+
board.TOUCH_XL,
12+
board.TOUCH_XR,
13+
board.TOUCH_YD,
14+
board.TOUCH_YU,
15+
calibration=((5200, 59000), (5800, 57000)),
16+
size=(320, 240),
17+
)
18+
19+
pybadger.show_badge(
20+
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
21+
)
22+
23+
cur_example = 0
24+
prev_touch = None
25+
while True:
26+
p = ts.touch_point
27+
if p and not prev_touch:
28+
cur_example += 1
29+
if cur_example >= 3:
30+
cur_example = 0
31+
print(cur_example)
32+
prev_touch = p
33+
34+
if cur_example == 0:
35+
pybadger.show_business_card(
36+
image_name="Blinka.bmp",
37+
name_string="Blinka",
38+
name_scale=2,
39+
email_string_one="blinka@",
40+
email_string_two="adafruit.com",
41+
)
42+
elif cur_example == 1:
43+
pybadger.show_qr_code(data="https://circuitpython.org")
44+
elif cur_example == 2:
45+
pybadger.show_badge(
46+
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
47+
)

0 commit comments

Comments
 (0)