Skip to content

updates since my previous PR #1

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 33 commits into from
Aug 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7669478
Added IO_push
jasonlshelton Apr 29, 2019
74b4c5c
fixed pylint issues
jasonlshelton Apr 29, 2019
0464b87
more pylint corrections
jasonlshelton Apr 29, 2019
989d77c
updated docs config
jasonlshelton Apr 29, 2019
77cd194
Merge pull request #1 from jasonlshelton/Add_Push_IO
jasonlshelton May 1, 2019
a748fb0
Added exception catching to network related function calls to account…
jasonlshelton May 1, 2019
569adef
Improved error handling allowing pyportal to retry connections that f…
jasonlshelton May 3, 2019
eb23859
Style changes as requested
jasonlshelton May 6, 2019
eebcd41
Merge pull request #2 from jasonlshelton/Add_Push_IO
jasonlshelton May 31, 2019
d2ab7fd
Style changes as requested
jasonlshelton Jun 4, 2019
ba20f85
Merge pull request #3 from jasonlshelton/Add_Push_IO
jasonlshelton Jun 4, 2019
b1718ca
Merge pull request #36 from jasonlshelton/master
brentru Jun 6, 2019
ace8e0d
Update README.rst
ladyada Jul 9, 2019
0879104
Add set_headers
dastels Jul 15, 2019
808c5e2
Merge pull request #43 from dastels/master
dastels Jul 15, 2019
9850a57
update IO circuitpython method names
Jul 23, 2019
32fd0b7
replace restclient
Jul 23, 2019
b539f43
Merge pull request #44 from brentru/patch-restclient-method
brentru Jul 23, 2019
6b6bbc8
update for compat with pybadge/pygamer with cursor instead of touchsc…
Jul 24, 2019
e4aac2f
fix errors on pr per @ladyada review
Jul 24, 2019
b50095a
travis
Jul 24, 2019
87a67f4
fix docs
Jul 24, 2019
133024f
Merge pull request #45 from brentru/pygamer-pybadge-compat
brentru Jul 24, 2019
c625dba
Merge pull request #42 from adafruit/ladyada-patch-1
ladyada Jul 28, 2019
dfd1cb4
choose between touchscreen and cursor manager
jerryneedell Jul 28, 2019
3d58880
pylint - move imports
jerryneedell Jul 28, 2019
30b1a53
pylint - gotta love pylint
jerryneedell Jul 28, 2019
63bcbc1
pylint - grr -- it passed on my pylint
jerryneedell Jul 28, 2019
e1e4718
fix tft-in-use-error
Jul 29, 2019
65b1e9f
Merge pull request #47 from jerryneedell/jerryn_fixcursor
brentru Jul 29, 2019
cf6c110
Merge pull request #49 from brentru/fix-tft-in-use
brentru Jul 29, 2019
23b2c76
update to requests
Jul 29, 2019
1416bc0
Merge pull request #50 from brentru/switch-requests
brentru Jul 29, 2019
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
49 changes: 0 additions & 49 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,3 @@ Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/master/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.

Building locally
================

Zip release files
-----------------

To build this library locally you'll need to install the
`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.

.. code-block:: shell

python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools

Once installed, make sure you are in the virtual environment:

.. code-block:: shell

source .env/bin/activate

Then run the build:

.. code-block:: shell

circuitpython-build-bundles --filename_prefix adafruit-circuitpython-pyportal --library_location .

Sphinx documentation
-----------------------

Sphinx is used to build the documentation based on rST files and comments in the code. First,
install dependencies (feel free to reuse the virtual environment from above):

.. code-block:: shell

python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme

Now, once you have the virtual environment activated:

.. code-block:: shell

cd docs
sphinx-build -E -W -b html . _build/html

This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
125 changes: 100 additions & 25 deletions adafruit_pyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,32 @@
import busio
from digitalio import DigitalInOut
import pulseio
import adafruit_touchscreen
import neopixel
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_requests as requests
import storage
import displayio
import audioio
import rtc
import supervisor
from adafruit_bitmap_font import bitmap_font
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
import adafruit_sdcard



if hasattr(board, 'TOUCH_XL'):
import adafruit_touchscreen
elif hasattr(board, 'BUTTON_CLOCK'):
from adafruit_cursorcontrol.cursorcontrol import Cursor
from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager

from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_requests as requests
try:
from adafruit_display_text.text_area import TextArea # pylint: disable=unused-import
print("*** WARNING ***\nPlease update your library bundle to the latest 'adafruit_display_text' version as we've deprecated 'text_area' in favor of 'label'") # pylint: disable=line-too-long
except ImportError:
from adafruit_display_text.Label import Label
from adafruit_bitmap_font import bitmap_font

import storage
import adafruit_sdcard
import displayio
import audioio
import rtc
import supervisor

try:
from secrets import secrets
Expand Down Expand Up @@ -162,7 +170,10 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
self._debug = debug

try:
self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member
if hasattr(board, 'TFT_BACKLIGHT'):
self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member
elif hasattr(board, 'TFT_LITE'):
self._backlight = pulseio.PWMOut(board.TFT_LITE) # pylint: disable=no-member
except ValueError:
self._backlight = None
self.set_backlight(1.0) # turn on backlight
Expand Down Expand Up @@ -222,7 +233,12 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,

self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE)
self._speaker_enable.switch_to_output(False)
self.audio = audioio.AudioOut(board.AUDIO_OUT)
if hasattr(board, 'AUDIO_OUT'):
self.audio = audioio.AudioOut(board.AUDIO_OUT)
elif hasattr(board, 'SPEAKER'):
self.audio = audioio.AudioOut(board.SPEAKER)
else:
raise AttributeError('Board does not have a builtin speaker!')
try:
self.play_file("pyportal_startup.wav")
except OSError:
Expand Down Expand Up @@ -258,11 +274,14 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
self._esp.reset()
else:
raise RuntimeError("Was not able to find ESP32")
requests.set_interface(self._esp)
requests.set_socket(socket, self._esp)

if url and not self._uselocal:
self._connect_esp()

if self._debug:
print("My IP address is", self._esp.pretty_ip(self._esp.ip_address))

# set the default background
self.set_background(self._default_bg)
board.DISPLAY.show(self.splash)
Expand Down Expand Up @@ -342,20 +361,35 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
self._image_position = (0, 0) # default to top corner
if not self._image_resize:
self._image_resize = (320, 240) # default to full screen
if hasattr(board, 'TOUCH_XL'):
if self._debug:
print("Init touchscreen")
# pylint: disable=no-member
self.touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
board.TOUCH_YD, board.TOUCH_YU,
calibration=((5200, 59000),
(5800, 57000)),
size=(320, 240))
# pylint: enable=no-member

self.set_backlight(1.0) # turn on backlight
elif hasattr(board, 'BUTTON_CLOCK'):
if self._debug:
print("Init cursor")
self.mouse_cursor = Cursor(board.DISPLAY, display_group=self.splash, cursor_speed=8)
self.mouse_cursor.hide()
self.cursor = CursorManager(self.mouse_cursor)
else:
raise AttributeError('PyPortal module requires either a touchscreen or gamepad.')

if self._debug:
print("Init touchscreen")
# pylint: disable=no-member
self.touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
board.TOUCH_YD, board.TOUCH_YU,
calibration=((5200, 59000),
(5800, 57000)),
size=(320, 240))
# pylint: enable=no-member
gc.collect()

self.set_backlight(1.0) # turn on backlight
def set_headers(self, headers):
"""Set the headers used by fetch().

gc.collect()
:param headers: The new header dictionary
"""
self._headers = headers

def set_background(self, file_or_color, position=None):
"""The background image to a bitmap file.
Expand Down Expand Up @@ -662,6 +696,47 @@ def image_converter_url(image_url, width, height, color_depth=16):
width, height,
color_depth, image_url)

def push_to_io(self, feed_key, data):
# pylint: disable=line-too-long
"""Push data to an adafruit.io feed

:param str feed_key: Name of feed key to push data to.
:param data: data to send to feed

"""
# pylint: enable=line-too-long

try:
aio_username = secrets['aio_username']
aio_key = secrets['aio_key']
except KeyError:
raise KeyError("Adafruit IO secrets are kept in secrets.py, please add them there!\n\n")

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(self._esp, secrets, None)
io_client = IO_HTTP(aio_username, aio_key, wifi)

while True:
try:
feed_id = io_client.get_feed(feed_key)
except AdafruitIO_RequestError:
# If no feed exists, create one
feed_id = io_client.create_new_feed(feed_key)
except RuntimeError as exception:
print("An error occured, retrying! 1 -", exception)
continue
break

while True:
try:
io_client.send_data(feed_id['key'], data)
except RuntimeError as exception:
print("An error occured, retrying! 2 -", exception)
continue
except NameError as exception:
print(feed_id['key'], data, exception)
continue
break

def fetch(self, refresh_url=None):
"""Fetch data from the url we initialized with, perfom any parsing,
and display text or graphics. This function does pretty much everything
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
autodoc_mock_imports = ["rtc", "supervisor", "pulseio", "audioio", "displayio", "neopixel",
"microcontroller", "adafruit_touchscreen", "adafruit_bitmap_font",
"adafruit_display_text", "adafruit_esp32spi", "secrets",
"adafruit_sdcard", "storage"]
"adafruit_sdcard", "storage", "adafruit_io", "adafruit_cursorcontrol",
"adafruit_requests"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
Expand Down