From bd1cf311287b09fb67648d4f112ec374757b70ef Mon Sep 17 00:00:00 2001 From: James Russo Date: Thu, 17 Dec 2020 00:56:47 +0000 Subject: [PATCH 1/3] re-initalize the underlying ws2811 module if the lenght of the buffer changes. --- src/adafruit_blinka/microcontroller/bcm283x/neopixel.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py b/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py index 813a51a0..1753419c 100644 --- a/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py +++ b/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py @@ -16,18 +16,24 @@ # 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_len = None 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_len # we save the length of the buf, and if it changes we will cleanup and re-initalize. + + if _led_strip is None or _buf_len != len(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() + _buf_len = len(buf) # Initialize all channels to off for channum in range(2): From 9a2678c8a2b05cda6d2874b30871177ccd60dc98 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 23 Dec 2020 09:13:12 -0800 Subject: [PATCH 2/3] Update neopixel.py --- src/adafruit_blinka/microcontroller/bcm283x/neopixel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py b/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py index 1753419c..70c9f38a 100644 --- a/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py +++ b/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py @@ -16,15 +16,15 @@ # 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_len = 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 - global _buf_len # we save the length of the buf, and if it changes we will cleanup and re-initalize. + global _buf # we save a reference to the buf, and if it changes we will cleanup and re-initalize. - if _led_strip is None or _buf_len != len(buf): + 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() @@ -33,7 +33,7 @@ def neopixel_write(gpio, buf): # 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_len = len(buf) + _buf = buf # Initialize all channels to off for channum in range(2): From 1639b90c94c44bbc6ec13e69cc3d37234a79054f Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 23 Dec 2020 09:15:54 -0800 Subject: [PATCH 3/3] Update neopixel.py Fix line too long. --- src/adafruit_blinka/microcontroller/bcm283x/neopixel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py b/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py index 70c9f38a..6c0726f8 100644 --- a/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py +++ b/src/adafruit_blinka/microcontroller/bcm283x/neopixel.py @@ -22,7 +22,7 @@ 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-initalize. + 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