From 31da0f417f5e7418e0f65a8c0bbeb4d9a89a5ab3 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Fri, 12 Jun 2020 21:23:33 -0500 Subject: [PATCH 1/5] adding support for PyPortal and simpletest example. --- adafruit_pybadger/__init__.py | 2 + adafruit_pybadger/pyportal.py | 72 +++++++++++++++++++++++ examples/pybadger_pyportal_touchscreen.py | 47 +++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 adafruit_pybadger/pyportal.py create mode 100644 examples/pybadger_pyportal_touchscreen.py 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..60841e2 --- /dev/null +++ b/adafruit_pybadger/pyportal.py @@ -0,0 +1,72 @@ +# 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 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 + + @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. + play_file = _unsupported + light = _unsupported + button = _unsupported + + +pyportal = PyPortal() # pylint: disable=invalid-name +"""Object that is automatically created on import.""" diff --git a/examples/pybadger_pyportal_touchscreen.py b/examples/pybadger_pyportal_touchscreen.py new file mode 100644 index 0000000..443d030 --- /dev/null +++ b/examples/pybadger_pyportal_touchscreen.py @@ -0,0 +1,47 @@ +"""Simpletest examaple 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.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 + ) From 4e4ca4d0c58ae90c34c242b5ca5ff977368b8232 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Sat, 13 Jun 2020 10:48:33 -0500 Subject: [PATCH 2/5] fixing light and play_file for PyPortal --- adafruit_pybadger/pyportal.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adafruit_pybadger/pyportal.py b/adafruit_pybadger/pyportal.py index 60841e2..a4ce221 100644 --- a/adafruit_pybadger/pyportal.py +++ b/adafruit_pybadger/pyportal.py @@ -42,6 +42,8 @@ """ +import board +import analogio import audioio from adafruit_pybadger.pybadger_base import PyBadgerBase @@ -55,6 +57,11 @@ class PyPortal(PyBadgerBase): _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.""" @@ -63,8 +70,6 @@ def _unsupported(self): # 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. - play_file = _unsupported - light = _unsupported button = _unsupported From 69851ece22c45f35fee19f0d9e49691561c814d1 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Sat, 13 Jun 2020 11:05:49 -0500 Subject: [PATCH 3/5] adding a properly sized blinka bmp image for PyPortal example --- examples/Blinka_PyPortal.bmp | Bin 0 -> 42102 bytes examples/pybadger_pyportal_touchscreen.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 examples/Blinka_PyPortal.bmp diff --git a/examples/Blinka_PyPortal.bmp b/examples/Blinka_PyPortal.bmp new file mode 100644 index 0000000000000000000000000000000000000000..a547e205eeb4600f9ade52a0a78779f0115348f2 GIT binary patch literal 42102 zcmeI5e_WI0`o}L&ehex#P5c35DvE)kq9STCL?z{iQbKqLq2>(K9BK%G&drStGH?eN zcGzfRJON)oWcjVLuU03GZ)z0y&Fp}FOD(mMIT5Tpr=#aw_p_h;8uU8nkJ@&>Ua))5 zo;~b&@4D{$xit)Ljhg(j0D(@HKr2)4KO{5WtA3;OFiF@USzuKMe4=%Q#r!{1`Zo z41k#s2y^h5n^OoZaQ1@)rztSUZ4%6KodTf`F(3lwz)Z#@nEEKdT(_wJ<2+#z!xu(+ zIm2Z4*)V$S81Qjf1~7gs_&CLZ3v7ay;3=3idIkhKuY=J(0KV>P0DK;SkTKI?qiYyE zHhDa(7(Wqaxy8dW9~W3LItaqYJ_$iCFTmCj8^GJ!8$w_ggn9+Q1mDNO*LylFaZdvg zYz47vB80o`gpfy4AaZ;-1Vb6Do4f$xCN70FlS5!7NMYvmnXu6}5Ee}hfO)eSuyA4& z1WgHriL<7`lhfzJ4F4IhaqR^e~4VS7^VfxfafQ#g`^P*$afP#A{>P|0dwG) zhYms2v`sV3+D$zntKyo=Opl-cn)6ni-Xw< z7Q*X3Y*;jp2{})sz$^Z-P~f{2UVO9?qNZg)$m$W0KWQ(7E?f@T{t589-ydLSz&gm8 zkqrCbE7-8g1(q#d0z01E2q8-r!>ewsuqAXJ@Mk{^{51toL8h3AqtLsjA?kZ`8J8yoh6 zbm`Y1N_Y+G(-NU{TOw2@RDdk91FBPB1NE+0NXys>jpEVp=DIK7WWl4L+Hejuuf~C5 z>!0AQ=UYI%?J(57coLd8hoNxaE6}({1n<5U4yVL%(3F=7=jD$;)AkSHIDZeQImhAi zHm4W&mBRb`n&1OoJroud!AE&2`0j02_yp@$YUjb3!aqT4sTjT}-wBtfXW-hA zU}#sq1b>y~!nKA3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{4X`E`^An<73uDrZcAC9qA&DrAX#4WIJ3j z3q$0gs@A)Ic!>bSFtDxdQrn&(^css#@w=_ckze0U>gtw!ckc_g3BdqY@7@2~|KZ|a zy%ddESk|ZDRNmta01;t_%_{c2zHE$M#-*W&S@`MkB{%{l_YyiP!a!?GRr0;W&E&1;Ly{m8Dd~pBX{Rcn8 zaa^lP7oq1+yXsOBf7d6Eo;q{p)c*0-#V+&T|J~OpdHf>%qRP3+^vG9H{N(-n_jLCj zJh=bh!OchO43Qv7q8w^hT}rjt8^(^A>MKr-nr zj!$!6mFeRCqOtL-$bq4~cfd>9)j=vNf}VLRksYtg$dDb!fiYbiTWt)_3~+cRafT#h zRwApcGsG Date: Sat, 13 Jun 2020 12:18:18 -0500 Subject: [PATCH 4/5] raise the unsupported error for acceleration and auto_dim_display on PyPortal --- adafruit_pybadger/pyportal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_pybadger/pyportal.py b/adafruit_pybadger/pyportal.py index a4ce221..7e7c544 100644 --- a/adafruit_pybadger/pyportal.py +++ b/adafruit_pybadger/pyportal.py @@ -71,6 +71,8 @@ def _unsupported(self): # 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 From dbaba83aa9e36cedf9bed1b5c67b4de4383b4200 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Wed, 17 Jun 2020 18:47:32 -0500 Subject: [PATCH 5/5] fix typo in pyportal example comment --- examples/pybadger_pyportal_touchscreen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pybadger_pyportal_touchscreen.py b/examples/pybadger_pyportal_touchscreen.py index 5ce9607..7ce96e0 100644 --- a/examples/pybadger_pyportal_touchscreen.py +++ b/examples/pybadger_pyportal_touchscreen.py @@ -1,4 +1,4 @@ -"""Simpletest examaple using Adafruit PyPortal. Uses the touchscreen to advance between examples.""" +"""Simpletest example using Adafruit PyPortal. Uses the touchscreen to advance between examples.""" import board from adafruit_pybadger import pybadger import adafruit_touchscreen