]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/bcm283x/neopixel.py
added support for I2C bus 0,1,2 that where missing for the OPI zero2W implementation
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / bcm283x / neopixel.py
index 813a51a092706d6d54b4f86833dce9c03c4171b6..c743220d5a07affd28045dfb4baadbccb34ebf46 100644 (file)
@@ -1,3 +1,6 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """BCM283x NeoPixel Driver Class"""
 import time
 import atexit
 """BCM283x NeoPixel Driver Class"""
 import time
 import atexit
@@ -16,18 +19,24 @@ LED_STRIP = None  # We manage the color order within the neopixel library
 # a 'static' object that we will use to manage our PWM DMA channel
 # we only support one LED strip per raspi
 _led_strip = None
 # a 'static' object that we will use to manage our PWM DMA channel
 # we only support one LED strip per raspi
 _led_strip = None
+_buf = None
 
 
 def neopixel_write(gpio, buf):
     """NeoPixel Writing Function"""
     global _led_strip  # we'll have one strip we init if its not at first
 
 
 def neopixel_write(gpio, buf):
     """NeoPixel Writing Function"""
     global _led_strip  # we'll have one strip we init if its not at first
+    global _buf  # we save a reference to the buf, and if it changes we will cleanup and re-init.
+
+    if _led_strip is None or buf is not _buf:
+        # This is safe to call since it doesn't do anything if _led_strip is None
+        neopixel_cleanup()
 
 
-    if _led_strip is None:
         # Create a ws2811_t structure from the LED configuration.
         # Note that this structure will be created on the heap so you
         # need to be careful that you delete its memory by calling
         # delete_ws2811_t when it's not needed.
         _led_strip = ws.new_ws2811_t()
         # Create a ws2811_t structure from the LED configuration.
         # Note that this structure will be created on the heap so you
         # need to be careful that you delete its memory by calling
         # delete_ws2811_t when it's not needed.
         _led_strip = ws.new_ws2811_t()
+        _buf = buf
 
         # Initialize all channels to off
         for channum in range(2):
 
         # Initialize all channels to off
         for channum in range(2):