Skip to content

Commit b94fcde

Browse files
authored
Merge pull request #33 from ChewyTurtle/master
Added ability to pass ESP and SPI objects.
2 parents aeef800 + 7ce2e4a commit b94fcde

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

adafruit_pyportal.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ class PyPortal:
143143
:param caption_color: The color of your caption. Must be a hex value, e.g. ``0x808000``.
144144
:param image_url_path: The HTTP traversal path for a background image to display.
145145
Defaults to ``None``.
146+
:param esp: A passed ESP32 object, Can be used in cases where the ESP32 chip needs to be used
147+
before calling the pyportal class. Defaults to ``None``.
148+
:param busio.SPI external_spi: A previously declared spi object. Defaults to ``None``.
146149
:param debug: Turn on debug print outs. Defaults to False.
147150
148151
"""
@@ -154,7 +157,7 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
154157
image_json_path=None, image_resize=None, image_position=None,
155158
caption_text=None, caption_font=None, caption_position=None,
156159
caption_color=0x808080, image_url_path=None,
157-
success_callback=None, debug=False):
160+
success_callback=None, esp=None, external_spi=None, debug=False):
158161

159162
self._debug = debug
160163

@@ -225,17 +228,25 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
225228
except OSError:
226229
pass # they deleted the file, no biggie!
227230

228-
# Make ESP32 connection
229-
if self._debug:
230-
print("Init ESP32")
231-
esp32_ready = DigitalInOut(board.ESP_BUSY)
232-
esp32_gpio0 = DigitalInOut(board.ESP_GPIO0)
233-
esp32_reset = DigitalInOut(board.ESP_RESET)
234-
esp32_cs = DigitalInOut(board.ESP_CS)
235-
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
236-
237-
self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready,
238-
esp32_reset, esp32_gpio0)
231+
if esp: # If there was a passed ESP Object
232+
if self._debug:
233+
print("Passed ESP32 to PyPortal")
234+
self._esp = esp
235+
if external_spi: #If SPI Object Passed
236+
spi = external_spi
237+
else: # Else: Make ESP32 connection
238+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
239+
else:
240+
if self._debug:
241+
print("Init ESP32")
242+
esp32_ready = DigitalInOut(board.ESP_BUSY)
243+
esp32_gpio0 = DigitalInOut(board.ESP_GPIO0)
244+
esp32_reset = DigitalInOut(board.ESP_RESET)
245+
esp32_cs = DigitalInOut(board.ESP_CS)
246+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
247+
248+
self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready,
249+
esp32_reset, esp32_gpio0)
239250
#self._esp._debug = 1
240251
for _ in range(3): # retries
241252
try:

0 commit comments

Comments
 (0)