@@ -143,6 +143,9 @@ class PyPortal:
143
143
:param caption_color: The color of your caption. Must be a hex value, e.g. ``0x808000``.
144
144
:param image_url_path: The HTTP traversal path for a background image to display.
145
145
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``.
146
149
:param debug: Turn on debug print outs. Defaults to False.
147
150
148
151
"""
@@ -154,7 +157,7 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
154
157
image_json_path = None , image_resize = None , image_position = None ,
155
158
caption_text = None , caption_font = None , caption_position = None ,
156
159
caption_color = 0x808080 , image_url_path = None ,
157
- success_callback = None , debug = False ):
160
+ success_callback = None , esp = None , external_spi = None , debug = False ):
158
161
159
162
self ._debug = debug
160
163
@@ -225,17 +228,25 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
225
228
except OSError :
226
229
pass # they deleted the file, no biggie!
227
230
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 )
239
250
#self._esp._debug = 1
240
251
for _ in range (3 ): # retries
241
252
try :
0 commit comments