From 6f3d9e910a69e4649e6c6f7533ebd075aa5565b6 Mon Sep 17 00:00:00 2001 From: zheshelm Date: Wed, 8 May 2019 09:46:04 -0600 Subject: [PATCH 1/4] Added ability to pass ESP and SPI objects. Needed to use Wifi before calling pyportal to do required qpplication authorization for twitters API --- adafruit_pyportal.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 1a36177..3faacdc 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -76,7 +76,7 @@ the secrets dictionary must contain 'ssid' and 'password' at a minimum""") raise -__version__ = "0.0.0-auto.0" +__version__ = "3.0.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyPortal.git" # pylint: disable=line-too-long @@ -154,7 +154,7 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, image_json_path=None, image_resize=None, image_position=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, image_url_path=None, - success_callback=None, debug=False): + success_callback=None, esp=None, passed_spi=None, debug=False ): self._debug = debug @@ -225,16 +225,26 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, except OSError: pass # they deleted the file, no biggie! - # Make ESP32 connection - if self._debug: - print("Init ESP32") - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_gpio0 = DigitalInOut(board.ESP_GPIO0) - esp32_reset = DigitalInOut(board.ESP_RESET) - esp32_cs = DigitalInOut(board.ESP_CS) - spi = busio.SPI(board.SCK, board.MOSI, board.MISO) - - self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, + # If there was a passed ESP Object + if esp: + if self._debug: + print("ESP32 Passed to PyPortal") + self._esp = esp + if passed_spi: #If SPI Object Passed + spi = passed_spi + else: + spi = busio.SPI(board.SCK, board.MOSI, board.MISO) + # Else: Make ESP32 connection + else: + if self._debug: + print("Init ESP32") + esp32_ready = DigitalInOut(board.ESP_BUSY) + esp32_gpio0 = DigitalInOut(board.ESP_GPIO0) + esp32_reset = DigitalInOut(board.ESP_RESET) + esp32_cs = DigitalInOut(board.ESP_CS) + spi = busio.SPI(board.SCK, board.MOSI, board.MISO) + + self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0) #self._esp._debug = 1 for _ in range(3): # retries From e3e44e86564be0e42a22f2c097fa94760aa0324a Mon Sep 17 00:00:00 2001 From: zheshelm Date: Wed, 8 May 2019 17:27:25 -0600 Subject: [PATCH 2/4] changed the __version__ variable to match the project master --- adafruit_pyportal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 3faacdc..16bf32b 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -76,7 +76,7 @@ the secrets dictionary must contain 'ssid' and 'password' at a minimum""") raise -__version__ = "3.0.0" +__version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyPortal.git" # pylint: disable=line-too-long From 8d9b5cc53febe30dfb800185236e69d2e1cc77b5 Mon Sep 17 00:00:00 2001 From: zheshelm Date: Thu, 9 May 2019 09:51:00 -0600 Subject: [PATCH 3/4] Fixed the spacing issues found in testing --- adafruit_pyportal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index 16bf32b..b65058c 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -154,7 +154,7 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, image_json_path=None, image_resize=None, image_position=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, image_url_path=None, - success_callback=None, esp=None, passed_spi=None, debug=False ): + success_callback=None, esp=None, passed_spi=None, debug=False): self._debug = debug @@ -245,7 +245,7 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, spi = busio.SPI(board.SCK, board.MOSI, board.MISO) self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, - esp32_reset, esp32_gpio0) + esp32_reset, esp32_gpio0) #self._esp._debug = 1 for _ in range(3): # retries try: From 7ce2e4afb159ccb23526c6cb7f4da6e95faaf6b2 Mon Sep 17 00:00:00 2001 From: zheshelm Date: Thu, 9 May 2019 16:58:49 -0600 Subject: [PATCH 4/4] Moved some comments to be in line with If statement and added the optional param comments for the two variables added to the init --- adafruit_pyportal.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/adafruit_pyportal.py b/adafruit_pyportal.py index b65058c..c8182aa 100644 --- a/adafruit_pyportal.py +++ b/adafruit_pyportal.py @@ -143,6 +143,9 @@ class PyPortal: :param caption_color: The color of your caption. Must be a hex value, e.g. ``0x808000``. :param image_url_path: The HTTP traversal path for a background image to display. Defaults to ``None``. + :param esp: A passed ESP32 object, Can be used in cases where the ESP32 chip needs to be used + before calling the pyportal class. Defaults to ``None``. + :param busio.SPI external_spi: A previously declared spi object. Defaults to ``None``. :param debug: Turn on debug print outs. Defaults to False. """ @@ -154,7 +157,7 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, image_json_path=None, image_resize=None, image_position=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, image_url_path=None, - success_callback=None, esp=None, passed_spi=None, debug=False): + success_callback=None, esp=None, external_spi=None, debug=False): self._debug = debug @@ -225,16 +228,14 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, except OSError: pass # they deleted the file, no biggie! - # If there was a passed ESP Object - if esp: + if esp: # If there was a passed ESP Object if self._debug: - print("ESP32 Passed to PyPortal") + print("Passed ESP32 to PyPortal") self._esp = esp - if passed_spi: #If SPI Object Passed - spi = passed_spi - else: + if external_spi: #If SPI Object Passed + spi = external_spi + else: # Else: Make ESP32 connection spi = busio.SPI(board.SCK, board.MOSI, board.MISO) - # Else: Make ESP32 connection else: if self._debug: print("Init ESP32")