From 5f3f4a7853babd3b70582ae35868eb5c50f4b24c Mon Sep 17 00:00:00 2001 From: Xavier Carcelle Date: Fri, 11 Apr 2025 16:15:52 +0900 Subject: [PATCH 1/5] Add first and count params to fill - allows fill to control all or part of a led strip - inspired from Adafruit Dotstar Arduino library --- adafruit_pixelbuf.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/adafruit_pixelbuf.py b/adafruit_pixelbuf.py index c20f514..8256c4a 100644 --- a/adafruit_pixelbuf.py +++ b/adafruit_pixelbuf.py @@ -203,15 +203,29 @@ def show(self): """ return self._transmit(self._post_brightness_buffer) - def fill(self, color: ColorUnion): + def fill(self, color: ColorUnion, first: int, count: int): """ - Fills the given pixelbuf with the given color. + Fill all or part of the pixelbuf with the given color. :param pixelbuf: A pixel object. :param color: Color to set. + :param first: Index of first pixel to fill, starting from 0. Must-be in-bounds, no clipping is performed. 0 if unspecified. + :param count: Number of pixels to fill, as a positive value. Passing 0 or leaving unspecified will fill to end of strip. """ + print(f'led_count value is {self._pixels}') + print(f'first value is {first}') + print(f'count value is {count}') r, g, b, w = self._parse_color(color) - for i in range(self._pixels): + end = 0 + if (first >= self._pixels): + pass + if (count == 0): + end = self._pixels + else: + end = first + count + if (end > self._pixels): + end = self._pixels + for i in range(first, end): self._set_item(i, r, g, b, w) if self.auto_write: self.show() From 176c4441127eeabce7f4ee487f4fcc32ad9d50c7 Mon Sep 17 00:00:00 2001 From: Xavier Carcelle Date: Fri, 11 Apr 2025 16:22:06 +0900 Subject: [PATCH 2/5] removing print --- adafruit_pixelbuf.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/adafruit_pixelbuf.py b/adafruit_pixelbuf.py index 8256c4a..080728a 100644 --- a/adafruit_pixelbuf.py +++ b/adafruit_pixelbuf.py @@ -212,9 +212,6 @@ def fill(self, color: ColorUnion, first: int, count: int): :param first: Index of first pixel to fill, starting from 0. Must-be in-bounds, no clipping is performed. 0 if unspecified. :param count: Number of pixels to fill, as a positive value. Passing 0 or leaving unspecified will fill to end of strip. """ - print(f'led_count value is {self._pixels}') - print(f'first value is {first}') - print(f'count value is {count}') r, g, b, w = self._parse_color(color) end = 0 if (first >= self._pixels): From 9388268d3a437b6847dde10312ccefa5f6ba4eaa Mon Sep 17 00:00:00 2001 From: Xavier Carcelle Date: Fri, 11 Apr 2025 16:47:22 +0900 Subject: [PATCH 3/5] pylint errors corrections --- adafruit_pixelbuf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pixelbuf.py b/adafruit_pixelbuf.py index 080728a..07ff894 100644 --- a/adafruit_pixelbuf.py +++ b/adafruit_pixelbuf.py @@ -209,8 +209,8 @@ def fill(self, color: ColorUnion, first: int, count: int): :param pixelbuf: A pixel object. :param color: Color to set. - :param first: Index of first pixel to fill, starting from 0. Must-be in-bounds, no clipping is performed. 0 if unspecified. - :param count: Number of pixels to fill, as a positive value. Passing 0 or leaving unspecified will fill to end of strip. + :param first: Index of first pixel to fill, starting from 0. Must-be in-bounds + :param count: Number of pixels to fill, as a positive value. 0 or unspecified will fill all """ r, g, b, w = self._parse_color(color) end = 0 From 33855103ed7445eccd6935089540a2683e43a2f3 Mon Sep 17 00:00:00 2001 From: Xavier Carcelle Date: Fri, 11 Apr 2025 16:56:35 +0900 Subject: [PATCH 4/5] pylint python syntax corrections --- adafruit_pixelbuf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_pixelbuf.py b/adafruit_pixelbuf.py index 07ff894..3bee2c2 100644 --- a/adafruit_pixelbuf.py +++ b/adafruit_pixelbuf.py @@ -214,13 +214,13 @@ def fill(self, color: ColorUnion, first: int, count: int): """ r, g, b, w = self._parse_color(color) end = 0 - if (first >= self._pixels): + if first >= self._pixels: pass if (count == 0): end = self._pixels else: end = first + count - if (end > self._pixels): + if end > self._pixels: end = self._pixels for i in range(first, end): self._set_item(i, r, g, b, w) From 73ac92b06590ef8e6c7bb8a09c1f5a76950dd8ff Mon Sep 17 00:00:00 2001 From: Xavier Carcelle Date: Fri, 11 Apr 2025 17:00:28 +0900 Subject: [PATCH 5/5] more pylint syntax corrections --- adafruit_pixelbuf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_pixelbuf.py b/adafruit_pixelbuf.py index 3bee2c2..725e7db 100644 --- a/adafruit_pixelbuf.py +++ b/adafruit_pixelbuf.py @@ -216,7 +216,7 @@ def fill(self, color: ColorUnion, first: int, count: int): end = 0 if first >= self._pixels: pass - if (count == 0): + if count == 0: end = self._pixels else: end = first + count