Docs: Update lessons_learned.md with detailed direct WLED communication explanation and testing parameters

This commit is contained in:
Tobias J. Endres 2025-08-15 21:47:54 +02:00
parent 5919ee7ae7
commit b08186cf00

View File

@ -58,14 +58,79 @@ End Function
* DDP appears to be a good fit for sending raw RGB pixel data efficiently.
2. **Develop a WLED Client (`WledClient`):**
* Create a new C++ class (`WledClient`) that uses `QUdpSocket` to send data.
* Implement the DDP packet structure for sending raw RGB pixel data.
* Add a `sendImage` method to format `QImage` data into DDP packets and send them.
* The client will be configured with the WLED device's IP address and DDP port (4048).
* Created a new C++ class (`WledClient`) that uses `QUdpSocket` to send data.
* Implemented the DNRGB (WLED UDP Realtime) protocol for sending raw RGB pixel data.
* The client is configured with the WLED device's IP address and DDP port (4048).
3. **Integrate WLED Client into HyperionGrabber:**
* Modify `HyperionGrabber` to use `WledClient` instead of `HyperionClient`.
* Update the `_processFrame` method to call `WledClient`'s `sendImage` method.
* Modified `HyperionGrabber` to use `WledClient` instead of `HyperionClient`.
* Updated the `_processFrame` method to call `WledClient`'s `sendImage` method.
4. **Remove HyperionClient Dependency:**
* Once `WledClient` is integrated and working, remove the `HyperionClient` class and its related code.
* Removed the `HyperionClient` class and its related code.
### Step-by-Step: Screen to LEDs (Direct WLED Communication)
1. **Screen Capture (HyperionGrabber):**
* The `WaylandGrabber` (or an X11 grabber in the X11 version) continuously captures frames from your screen.
* Each captured frame is received by the `HyperionGrabber`'s `_processFrame` method as a `QVideoFrame`.
2. **Image Processing (HyperionGrabber):**
* The `QVideoFrame` is converted into a `QImage`.
* **Scaling:** The `QImage` is scaled down. The `_scale_m` parameter (default 8) determines the scaling factor. For example, if your screen is 1920x1080 and `_scale_m` is 8, the image will be scaled to 240x135. This is done using `Qt::SmoothTransformation` for quality.
* **Format Conversion:** The scaled image is converted to `QImage::Format_RGB888` (24-bit RGB), which is a standard format for LED data.
* **Frame Skipping (Optional):** If configured, some frames might be skipped to reduce the processing load.
3. **Direct WLED Data Transmission (WledClient):**
* The `HyperionGrabber` passes the processed (scaled and formatted) `QImage` directly to the `WledClient`'s `sendImage` method.
* The `WledClient` then:
* Iterates through the pixels of the `QImage`.
* Constructs **DNRGB packets** (WLED UDP Realtime protocol):
* Each packet starts with a 4-byte header:
* Byte 0: Protocol type (`4` for DNRGB).
* Byte 1: Timeout value (e.g., 1 second, after which WLED returns to its normal mode if no more packets are received).
* Byte 2 & 3: 16-bit starting LED index (low byte, then high byte). This allows sending parts of the image in multiple packets if the image is too large for a single UDP datagram.
* The RGB data for each pixel (3 bytes per pixel: Red, Green, Blue) is appended to the header.
* Sends these UDP datagrams to the configured WLED device's IP address and port (default 4048).
4. **WLED Device Processing:**
* The WLED device receives the DNRGB UDP packets.
* It interprets the pixel data and updates the connected LEDs accordingly.
* Any internal WLED effects or configurations (like color correction, gamma, or specific LED mapping) will be applied by the WLED firmware itself.
### Parameters for Testing with Your LED Setup:
The `Hyperion_Grabber_X11_QT` application now directly communicates with WLED.
**Parameters you need to consider for the `Hyperion_Grabber_X11_QT` application:**
* **`--address` or `-a`**: The IP address or hostname of your WLED device. (e.g., `192.168.1.177` as set in the code, but you should use your WLED's actual IP).
* **`--port` or `-p`**: The UDP port of your WLED device for the UDP Realtime protocol. (Default: `4048` for DDP, or `21324` for WARLS, but we are using DDP/DNRGB which is typically 4048).
* **`--scale` or `-s`**: The scaling factor for the captured image. This is crucial for performance vs. accuracy.
* **Recommendation:** Start with the default `8`. If the performance is good and you want more detail, you can try `4` or `2`. If performance is an issue, you might even go higher (e.g., `16`).
* **`--frameskip` or `-f`**: Number of frames to skip between processing. (Default: `0` - no skipping). You can increase this if you experience performance issues.
* **`--inactive` or `-i`**: Time in seconds after which the grabber logs an inactivity message. (Default: `0` - no inactivity timer). *Note: This currently only logs a message; it does not send a black frame or clear LEDs to WLED. This functionality would need to be added to `WledClient` if desired.*
**Example Command to run the grabber:**
```bash
./Hyperion_Grabber_X11_QT -a <YOUR_WLED_IP_ADDRESS> -p 4048 -s 8 -f 0
```
Replace `<YOUR_WLED_IP_ADDRESS>` with the actual IP address of your WLED device.
**For your LED configuration (30 at the bottom, 20 at the right, 70 at the top, 20 at the left, and another 41 at the bottom):**
This configuration is still primarily handled **within the WLED device itself**. You will need to configure the LED segments and their order within the WLED web interface to match your physical LED layout.
* **Total LEDs:** 30 + 20 + 70 + 20 + 41 = 181 LEDs.
* Ensure your WLED device is configured for this total number of LEDs and that the segments are correctly defined to match your physical setup.
* Enable "UDP Realtime" in your WLED settings and ensure it's listening on port 4048 (or the port you specify with `-p`).
**Summary of what you need to do for testing:**
1. **Configure WLED Device:**
* Ensure your WLED device has the correct total number of LEDs configured.
* Set up LED segments in WLED to match your physical layout (bottom, right, top, left).
* Enable "UDP Realtime" in WLED settings and confirm it's listening on the correct port (default 4048).
2. **Build the Grabber:** You will need to compile the modified `Hyperion_Grabber_X11_QT` project.
3. **Run the Grabber:** Execute the compiled application with the appropriate WLED IP address and port.