From 0c95256e70a1812d887c2356c8d7298f6c733b8c Mon Sep 17 00:00:00 2001 From: VPTechOps Date: Sat, 5 Feb 2022 14:21:38 -0700 Subject: [PATCH] Correct use of board.NEOPIXEL as status_neopixel parameter Move init of Peripherals() to be done before init of Network() so that board's neopixels are done first, then passed to Network() if status_neopixel uses board.NEOPIXEL. If any other pin is used, it will be passed as is. --- adafruit_magtag/magtag.py | 8 ++++++-- adafruit_magtag/network.py | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/adafruit_magtag/magtag.py b/adafruit_magtag/magtag.py index b1e457a..cbc0890 100755 --- a/adafruit_magtag/magtag.py +++ b/adafruit_magtag/magtag.py @@ -29,6 +29,7 @@ import gc import time +import board from adafruit_portalbase import PortalBase from adafruit_magtag.network import Network from adafruit_magtag.graphics import Graphics @@ -75,6 +76,11 @@ def __init__( debug=False, ): + self.peripherals = Peripherals() + + if status_neopixel == board.NEOPIXEL: + status_neopixel = self.peripherals.neopixels + network = Network( status_neopixel=status_neopixel, extract_values=False, @@ -99,8 +105,6 @@ def __init__( debug=debug, ) - self.peripherals = Peripherals() - gc.collect() def exit_and_deep_sleep(self, sleep_time): diff --git a/adafruit_magtag/network.py b/adafruit_magtag/network.py index 6633516..2cf73f4 100755 --- a/adafruit_magtag/network.py +++ b/adafruit_magtag/network.py @@ -55,7 +55,10 @@ def __init__( debug=False, ): if status_neopixel: - status_led = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) + if isinstance(status_neopixel, neopixel.NeoPixel): + status_led = status_neopixel + else: + status_led = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) else: status_led = None super().__init__(