-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Device for a Neopixel strip, controlled from RPi #948
base: main
Are you sure you want to change the base?
Conversation
…m RPi Uses "adafruit-circuitpython-neopixel" library
Added "adafruit-circuitpython-neopixel" dependency
WalkthroughThe update enhances support for RPi NEOPIXEL STRIP WS2812 LEDs by introducing the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Out of diff range and nitpick comments (1)
ledfx/devices/rpi_neopixel.py (1)
24-42
: Consider cleaning up or clarifying the purpose of the commented-out code for better maintainability.
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
pyproject.toml
is excluded by!**/*.toml
Files selected for processing (1)
- ledfx/devices/rpi_neopixel.py (1 hunks)
Additional Context Used
Ruff (2)
ledfx/devices/rpi_neopixel.py (2)
2-2:
enum.Enum
imported but unused
4-4:
numpy
imported but unused
Additional comments not posted (3)
ledfx/devices/rpi_neopixel.py (3)
44-46
: Initialization method correctly calls the superclass initializer.
62-63
: Deactivation method correctly delegates to the superclass.
65-69
: Data flushing method is implemented correctly for the Neopixel library.
@@ -0,0 +1,69 @@ | |||
import logging | |||
from enum import Enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import: Enum
.
- from enum import Enum
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
from enum import Enum |
ledfx/devices/rpi_neopixel.py
Outdated
def activate(self): | ||
try: | ||
import neopixel #Adafruit-circuitpython-neopixel library | ||
import board | ||
except ImportError: | ||
_LOGGER.warning( | ||
"Unable to load Neopixel module - are you on a Raspberry Pi?" | ||
) | ||
self.deactivate() | ||
self.strip = neopixel.NeoPixel( | ||
board.D18, #Raspberry Pi GPIO PIN 18, hardcoded | ||
self.pixel_count, #Number of pixels | ||
) | ||
super().activate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making the GPIO pin configurable to enhance flexibility.
- board.D18, #Raspberry Pi GPIO PIN 18, hardcoded
+ board.D18 if 'gpio_pin' not in self.config else self.config['gpio_pin'], # Configurable GPIO pin
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def activate(self): | |
try: | |
import neopixel #Adafruit-circuitpython-neopixel library | |
import board | |
except ImportError: | |
_LOGGER.warning( | |
"Unable to load Neopixel module - are you on a Raspberry Pi?" | |
) | |
self.deactivate() | |
self.strip = neopixel.NeoPixel( | |
board.D18, #Raspberry Pi GPIO PIN 18, hardcoded | |
self.pixel_count, #Number of pixels | |
) | |
super().activate() | |
def activate(self): | |
try: | |
import neopixel #Adafruit-circuitpython-neopixel library | |
import board | |
except ImportError: | |
_LOGGER.warning( | |
"Unable to load Neopixel module - are you on a Raspberry Pi?" | |
) | |
self.deactivate() | |
self.strip = neopixel.NeoPixel( | |
board.D18 if 'gpio_pin' not in self.config else self.config['gpio_pin'], # Configurable GPIO pin | |
self.pixel_count, #Number of pixels | |
) | |
super().activate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- ledfx/devices/rpi_neopixel.py (1 hunks)
Additional Context Used
Ruff (2)
ledfx/devices/rpi_neopixel.py (2)
2-2:
enum.Enum
imported but unused
4-4:
numpy
imported but unused
Additional comments not posted (3)
ledfx/devices/rpi_neopixel.py (3)
43-45
: Initialization method is correctly implemented.
61-62
: Deactivation method is correctly implemented.
64-70
: Data flushing method is correctly implemented.
@staticmethod | ||
@property | ||
def CONFIG_SCHEMA(): | ||
return vol.Schema( | ||
{ | ||
vol.Required( | ||
"pixel_count", | ||
description="Number of individual pixels", | ||
default=144, | ||
): vol.All(int, vol.Range(min=1)), | ||
# vol.Required( #Uncomment to test this list in the frontend. PIN is hardcoded later anyway... | ||
# "gpio_pin", | ||
# description="Raspberry Pi GPIO pin your LEDs are connected to", | ||
# ): vol.In(list([17, 18, 19])), # [18, 17, 19] Frontend doesn't allow to create a device if the first element in the list is selected | ||
# vol.Required( | ||
# "color_order", description="Color order", default="RGB" | ||
# ): vol.In(list(COLOR_ORDERS.keys())), | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider including additional configuration options for GPIO pin and color order to enhance flexibility.
Would you like me to help implement these features or should I open a GitHub issue to track this enhancement?
ledfx/devices/rpi_neopixel.py
Outdated
def activate(self): | ||
try: | ||
import board | ||
import neopixel # Adafruit-circuitpython-neopixel library | ||
except ImportError: | ||
_LOGGER.warning( | ||
"Unable to load Neopixel module - are you on a Raspberry Pi?" | ||
) | ||
self.deactivate() | ||
self.strip = neopixel.NeoPixel( | ||
board.D18, # Raspberry Pi GPIO PIN 18, hardcoded | ||
self.pixel_count, # Number of pixels | ||
) | ||
super().activate() | ||
|
||
def deactivate(self): | ||
super().deactivate() | ||
|
||
def flush(self, data): | ||
"""Flush LED data to the strip""" | ||
pixelData = [ | ||
tuple(led) for led in data.tolist() | ||
] # Convert each row to a tuple. In Neopixel library, colors for each pixel are stored as tuples. | ||
self.strip[:] = pixelData[:] | ||
self.strip.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling in activation is robust. Consider making the GPIO pin configurable to enhance flexibility.
- board.D18, #Raspberry Pi GPIO PIN 18, hardcoded
+ board.D18 if 'gpio_pin' not in self.config else self.config['gpio_pin'], # Configurable GPIO pin
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def activate(self): | |
try: | |
import board | |
import neopixel # Adafruit-circuitpython-neopixel library | |
except ImportError: | |
_LOGGER.warning( | |
"Unable to load Neopixel module - are you on a Raspberry Pi?" | |
) | |
self.deactivate() | |
self.strip = neopixel.NeoPixel( | |
board.D18, # Raspberry Pi GPIO PIN 18, hardcoded | |
self.pixel_count, # Number of pixels | |
) | |
super().activate() | |
def deactivate(self): | |
super().deactivate() | |
def flush(self, data): | |
"""Flush LED data to the strip""" | |
pixelData = [ | |
tuple(led) for led in data.tolist() | |
] # Convert each row to a tuple. In Neopixel library, colors for each pixel are stored as tuples. | |
self.strip[:] = pixelData[:] | |
self.strip.show() | |
def activate(self): | |
try: | |
import board | |
import neopixel # Adafruit-circuitpython-neopixel library | |
except ImportError: | |
_LOGGER.warning( | |
"Unable to load Neopixel module - are you on a Raspberry Pi?" | |
) | |
self.deactivate() | |
self.strip = neopixel.NeoPixel( | |
board.D18 if 'gpio_pin' not in self.config else self.config['gpio_pin'], # Configurable GPIO pin | |
self.pixel_count, # Number of pixels | |
) | |
super().activate() | |
def deactivate(self): | |
super().deactivate() | |
def flush(self, data): | |
"""Flush LED data to the strip""" | |
pixelData = [ | |
tuple(led) for led in data.tolist() | |
] # Convert each row to a tuple. In Neopixel library, colors for each pixel are stored as tuples. | |
self.strip[:] = pixelData[:] | |
self.strip.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- ledfx/devices/rpi_neopixel.py (1 hunks)
Additional Context Used
Ruff (1)
ledfx/devices/rpi_neopixel.py (1)
2-2:
enum.Enum
imported but unused
Additional comments not posted (6)
ledfx/devices/rpi_neopixel.py (6)
2-2
: Remove unused import:Enum
.
23-41
: Consider making the GPIO pin and color order configurable to enhance flexibility.
43-45
: Initialization method looks good.
46-60
: Consider making the GPIO pin configurable to enhance flexibility.
61-62
: Deactivation method is correctly implemented.
64-71
: Data flushing method is efficiently implemented.
An alternative approach to control Adafruit Neopixel strips from RPI. Using "adafruit-circuitpython-neopixel" library.