Skip to content

Commit 7a033d1

Browse files
committed
updates!
1 parent d4539cb commit 7a033d1

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

adafruit_pyportal.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,23 @@ class PyPortal:
100100
"""Class representing the Adafruit PyPortal.
101101
102102
:param url: The URL of your data source. Defaults to ``None``.
103-
:param json_path: The list of json traversal to get data out of. Can be list of lists for multiple data points. Defaults to ``None`` to not use json.
104-
:param regexp_path: The list of regexp strings to get data out (use a single regexp group). Can be list of regexps for multiple data points. Defaults to ``None`` to not use regexp.
103+
:param json_path: The list of json traversal to get data out of.
104+
Can be list of lists for multiple data points. Defaults to ``None`` to not use json.
105+
:param regexp_path: The list of regexp strings to get data out (use a single regexp group).
106+
Can be list of regexps for multiple data points. Defaults to ``None`` to not use regexp.
105107
:param default_bg: The path to your default background image file. Defaults to ``None``.
106108
:param status_neopixel: The pin for the status NeoPixel. Use ``board.NEOPIXEL`` for the
107109
on-board NeoPixel. Defaults to ``None``, no status LED
108110
:param str text_font: The path to your font file for your data text display.
109-
:param text_position: The position of your extracted text on the display in an (x, y) tuple. Can be a list of tuples for when there's a list of json_paths, for example
110-
:param text_color: The color of the text, in 0xRRGGBB format. Can be a list of colors for when there's multiple texts. Defaults to ``None``.
111+
:param text_position: The position of your extracted text on the display in an (x, y) tuple.
112+
Can be a list of tuples for when there's a list of json_paths, for example
113+
:param text_color: The color of the text, in 0xRRGGBB format. Can be a list of colors for
114+
when there's multiple texts. Defaults to ``None``.
111115
:param text_wrap: Whether or not to wrap text (for long text data chunks). Defaults to ``False``, no wrapping.
112116
:param text_maxlen: The max length of the text for text wrapping. Defaults to 0.
113117
:param image_json_path: The JSON traversal path for a background image to display. Defaults to ``None``.
114-
:param image_resize: What size to resize the image we got from the json_path, make this a tuple of the width and height you want. Defaults to ``None``.
118+
:param image_resize: What size to resize the image we got from the json_path,
119+
make this a tuple of the width and height you want. Defaults to ``None``.
115120
:param image_position: The position of the image on the display as an (x, y) tuple. Defaults to ``None``.
116121
:param success_callback: A function we'll call if you like, when we fetch data successfully. Defaults to ``None``.
117122
:param str caption_text: The text of your caption, a fixed text not changed by the data we get. Defaults to ``None``.
@@ -149,7 +154,6 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
149154
self._json_path = None
150155

151156
self._regexp_path = regexp_path
152-
self._time_between_requests = time_between_requests
153157
self._success_callback = success_callback
154158

155159
if status_neopixel:
@@ -168,16 +172,20 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
168172
if self._debug:
169173
print("Init ESP32")
170174
# pylint: disable=no-member
171-
esp32_cs = DigitalInOut(microcontroller.pin.PB14) # PB14
175+
esp32_cs = DigitalInOut(microcontroller.pin.PB14)
172176
esp32_ready = DigitalInOut(microcontroller.pin.PB16)
173177
esp32_gpio0 = DigitalInOut(microcontroller.pin.PB15)
174178
esp32_reset = DigitalInOut(microcontroller.pin.PB17)
179+
#esp32_ready = DigitalInOut(board.ESP_BUSY)
180+
#esp32_gpio0 = DigitalInOut(board.ESP_GPIO0)
181+
#esp32_reset = DigitalInOut(board.ESP_RESET)
182+
#esp32_cs = DigitalInOut(board.ESP_CS)
175183
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
176184
# pylint: enable=no-member
177185

178186
if not self._uselocal:
179-
self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset,
180-
esp32_gpio0)
187+
self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready,
188+
esp32_reset, esp32_gpio0)
181189
#self._esp._debug = 1
182190
for _ in range(3): # retries
183191
try:
@@ -278,7 +286,7 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
278286
gc.collect()
279287

280288
def set_background(self, filename):
281-
"""The background image.
289+
"""The background image to a bitmap file.
282290
283291
:param filename: The name of the chosen background image file.
284292
@@ -309,7 +317,7 @@ def set_background(self, filename):
309317
board.DISPLAY.wait_for_frame()
310318

311319
def set_backlight(self, val):
312-
"""The backlight.
320+
"""Adjust the TFT backlight.
313321
314322
:param val: The backlight brightness. Use a value between ``0`` and ``1``, where ``0`` is
315323
off, and ``1`` is 100% brightness.
@@ -325,7 +333,7 @@ def set_backlight(self, val):
325333
def preload_font(self, glyphs=None):
326334
"""Preload font.
327335
328-
:param glyphs: The font glyphs to load. Defaults to ``None``, uses built in glyphs if None.
336+
:param glyphs: The font glyphs to load. Defaults to ``None``, uses alphanumeric glyphs if None.
329337
330338
"""
331339
if not glyphs:
@@ -362,9 +370,9 @@ def set_caption(self, caption_text, caption_position, caption_color):
362370
self.splash.append(self._caption)
363371

364372
def set_text(self, val, index=0):
365-
"""Display text.
373+
"""Display text, with indexing into our list of text boxes.
366374
367-
:param str val: The text to be displayed.
375+
:param str val: The text to be displayed
368376
:param index: Defaults to 0.
369377
370378
"""
@@ -400,7 +408,7 @@ def set_text(self, val, index=0):
400408
self.splash.append(self._text[index])
401409

402410
def neo_status(self, value):
403-
"""The status NeoPixeel.
411+
"""The status NeoPixel.
404412
405413
:param value: The color to change the NeoPixel.
406414
@@ -412,7 +420,7 @@ def neo_status(self, value):
412420
def play_file(file_name):
413421
"""Play a wav file.
414422
415-
:param str file_name: The name of the wav file.
423+
:param str file_name: The name of the wav file to play on the speaker.
416424
417425
"""
418426
#self._speaker_enable.value = True
@@ -433,9 +441,10 @@ def _json_traverse(json, path):
433441
return value
434442

435443
def get_local_time(self, location=None):
436-
"""The local time.
444+
"""Fetch and "set" the local time of this microcontroller to the local
445+
time at the location, using an internet time API.
437446
438-
:param str location: Your city and state, e.g. ``"New York, New York"``.
447+
:param str location: Your city and country, e.g. ``"New York, US"``.
439448
440449
"""
441450
self._connect_esp()
@@ -467,10 +476,10 @@ def get_local_time(self, location=None):
467476
gc.collect()
468477

469478
def wget(self, url, filename):
470-
"""Obtain a stream.
479+
"""Download a url and save to filename location, like the command wget.
471480
472481
:param url: The URL from which to obtain the data.
473-
:param filename: The name of the file to save the data.
482+
:param filename: The name of the file to save the data to.
474483
475484
"""
476485
print("Fetching stream from", url)
@@ -512,7 +521,8 @@ def _connect_esp(self):
512521
self._esp.connect(settings)
513522

514523
def fetch(self):
515-
"""Fetch data."""
524+
"""Fetch data from the url we initialized with, perfom any parsing,
525+
and display text or graphics. This function does pretty much everything"""
516526
json_out = None
517527
image_url = None
518528
values = []
@@ -616,11 +626,11 @@ def fetch(self):
616626
return values
617627

618628
def show_QR(self, qr_data, qr_size=128, position=None): # pylint: disable=invalid-name
619-
"""Display a QR code.
629+
"""Display a QR code on the TFT
620630
621631
:param qr_data: The data for the QR code.
622632
:param int qr_size: The size of the QR code in pixels.
623-
:param position: The position of the QR code on the display.
633+
:param position: The (x, y) tuple position of the QR code on the display.
624634
625635
"""
626636
import adafruit_miniqr
@@ -692,7 +702,7 @@ def show_QR(self, qr_data, qr_size=128, position=None): # pylint: disable=inval
692702
# return a list of lines with wordwrapping
693703
@staticmethod
694704
def wrap_nicely(string, max_chars):
695-
"""A list of lines with word wrapping.
705+
"""A helper that will return a list of lines with word-break wrapping.
696706
697707
:param str string: The text to be wrapped.
698708
:param int max_chars: The maximum number of characters on a line before wrapping.

0 commit comments

Comments
 (0)