Skip to content
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

Merged
merged 2 commits into from
Feb 4, 2024
Merged

feat: HyperHDR support #698

merged 2 commits into from
Feb 4, 2024

Conversation

protyposis
Copy link
Contributor

@protyposis protyposis commented Feb 3, 2024

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

  • New Features
    • Introduced support for HyperHDR's "UDP raw receiver" through a new RGB packet encoding functionality, enhancing compatibility with diverse lighting setups.

Copy link

sentry-io bot commented Feb 3, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: ledfx/devices/udp.py

Function Unhandled Issue
choose_and_send_packet OSError: [Errno 65] No route to host threading in...
Event Count: 1
choose_and_send_packet OSError: [Errno 65] No route to host ledfx.device...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

Copy link
Contributor

coderabbitai bot commented Feb 3, 2024

Walkthrough

The 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

File Path Change Summary
ledfx/devices/packets.py, ledfx/devices/udp.py Added build_rgb_packet function for generic RGB packet encoding used by HyperHDR's "UDP raw receiver." Updated udp.py to support new RGB packet type "RGB (HyperHDR)" with handling for frames ≤ 500 bytes.

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between a33e63c and 2dfdc1d.
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.

Comment on lines +61 to +75
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
Copy link
Contributor

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.

Suggested change
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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 2dfdc1d and bec7cc2.
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

@shauneccles shauneccles merged commit f1a5ffa into LedFx:main Feb 4, 2024
20 checks passed
@shauneccles
Copy link
Member

Thanks so much for the contribution, welcome to the codebase 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants