-
Notifications
You must be signed in to change notification settings - Fork 150
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
feat: HyperHDR support #698
Conversation
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: ledfx/devices/udp.py
Did you find this useful? React with a 👍 or 👎 |
WalkthroughThe recent updates introduce a new function for encoding RGB data into bytes for transmission, specifically catering to HyperHDR's UDP raw receiver. Additionally, the system's capability to handle UDP packets has been enhanced with the inclusion of a new packet type "RGB (HyperHDR)." This allows for more efficient handling of RGB data packets, particularly for frames of size 500 or less, streamlining the process for devices utilizing HyperHDR technology. 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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- ledfx/devices/packets.py (1 hunks)
- ledfx/devices/udp.py (2 hunks)
Additional comments: 1
ledfx/devices/udp.py (1)
- 116-118: The implementation for handling the "RGB (HyperHDR)" packet type with a frame size limit of 500 is correct. However, ensure that the
frame_size
calculation and comparison logic are consistent across all packet types for maintainability and readability.
def build_rgb_packet(data: np.ndarray): | ||
""" | ||
Generic RGB packet encoding (used by HyperHDR's "UDP raw receiver") | ||
Max LEDs: 500 | ||
|
||
Header: none | ||
Byte Description | ||
0 + n*3 Red Value | ||
1 + n*3 Green Value | ||
2 + n*3 Blue Value | ||
|
||
""" | ||
byteData = data.astype(np.dtype("B")) | ||
packet = byteData.flatten().tobytes() | ||
return packet |
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.
The build_rgb_packet
function correctly implements the packet structure for HyperHDR's "UDP raw receiver" without a header, as specified. However, consider adding input validation to ensure data
is of the expected shape and type, enhancing robustness and error handling.
def build_rgb_packet(data: np.ndarray):
+ if not isinstance(data, np.ndarray):
+ raise TypeError("Data must be a numpy ndarray")
+ if data.ndim != 2 or data.shape[1] != 3:
+ raise ValueError("Data must be a 2D numpy array with 3 columns for RGB values")
byteData = data.astype(np.dtype("B"))
packet = byteData.flatten().tobytes()
return packet
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 build_rgb_packet(data: np.ndarray): | |
""" | |
Generic RGB packet encoding (used by HyperHDR's "UDP raw receiver") | |
Max LEDs: 500 | |
Header: none | |
Byte Description | |
0 + n*3 Red Value | |
1 + n*3 Green Value | |
2 + n*3 Blue Value | |
""" | |
byteData = data.astype(np.dtype("B")) | |
packet = byteData.flatten().tobytes() | |
return packet | |
def build_rgb_packet(data: np.ndarray): | |
if not isinstance(data, np.ndarray): | |
raise TypeError("Data must be a numpy ndarray") | |
if data.ndim != 2 or data.shape[1] != 3: | |
raise ValueError("Data must be a 2D numpy array with 3 columns for RGB values") | |
byteData = data.astype(np.dtype("B")) | |
packet = byteData.flatten().tobytes() | |
return packet |
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- ledfx/devices/packets.py (1 hunks)
- ledfx/devices/udp.py (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- ledfx/devices/packets.py
- ledfx/devices/udp.py
Thanks so much for the contribution, welcome to the codebase 🎉 |
Add support for HyperHDR ambient lights. HyperHDR uses a UDP protocol that is similar to
DRGB
, without the header (and thus, without a timeout parameter) (see source).In order to use HyperHDR as a device, the "UDP raw receiver" needs to be enabled under Menu > "Advanced" > "Network Services". In LedFx, create a UDP device with the new "RGB (HyperHDR)" mode. The pixel count needs to be exactly the same as configured in HyperHDR, otherwise HyperHDR discards the UDP packets.
I tested this on my local installation and it works perfectly :)
Summary by CodeRabbit