DDPConnection

Struct DDPConnection 

Source
pub struct DDPConnection {
    pub pixel_config: PixelConfig,
    pub id: ID,
    pub receiver_packet: Receiver<Packet>,
    /* private fields */
}
Expand description

A connection to a DDP display device.

This is the main type for sending pixel data to LED strips and other DDP-compatible displays. It handles packet assembly, sequencing, and automatic chunking of large data arrays.

§Examples

§Basic usage

use ddp_rs::connection::DDPConnection;
use ddp_rs::protocol::{PixelConfig, ID};
use std::net::UdpSocket;

let mut conn = DDPConnection::try_new(
    "192.168.1.40:4048",
    PixelConfig::default(),
    ID::Default,
    UdpSocket::bind("0.0.0.0:4048")?
)?;

// Send RGB data for 3 pixels
conn.write(&[
    255, 0, 0,    // Red
    0, 255, 0,    // Green
    0, 0, 255,    // Blue
])?;

§Using offsets to update part of the strip

// Update pixels starting at byte offset 300 (pixel 100 in RGB)
conn.write_offset(&[255, 128, 64], 300)?;

Fields§

§pixel_config: PixelConfig

Pixel format configuration (RGB, RGBW, etc.)

§id: ID

Protocol ID for this connection

§receiver_packet: Receiver<Packet>

Receiver for packets coming from the display (responses)

Implementations§

Source§

impl DDPConnection

Source

pub fn write(&mut self, data: &[u8]) -> Result<usize, DDPError>

Writes pixel data to the display starting at offset 0.

Large data arrays are automatically split into multiple packets. Each packet can contain up to 1440 bytes (480 RGB pixels).

§Arguments
  • data - Raw pixel data bytes. For RGB, this should be groups of 3 bytes (R,G,B). For RGBW, groups of 4 bytes (R,G,B,W).
§Returns

The total number of bytes sent across all packets.

§Examples
// Set first 3 pixels to red, green, blue
conn.write(&[255, 0, 0, 0, 255, 0, 0, 0, 255])?;
Source

pub fn write_offset( &mut self, data: &[u8], offset: u32, ) -> Result<usize, DDPError>

Writes pixel data to the display starting at a specific byte offset.

This is useful for updating only a portion of your LED strip without resending all the data.

§Arguments
  • data - Raw pixel data bytes to send
  • offset - Starting byte offset (not pixel offset). For RGB, offset 3 = pixel 1.
§Examples
// Update pixel 10 (offset = 10 * 3 = 30) to white
conn.write_offset(&[255, 255, 255], 30)?;
Source

pub fn write_message(&mut self, msg: Message) -> Result<usize, DDPError>

Sends a JSON control message to the display.

This is useful for things like setting brightness, changing display modes, or querying configuration.

§Arguments
§Examples
// Send a control message
let json_value = serde_json::json!({"brightness": 128});
conn.write_message(Message::Parsed((ID::Control, json_value)))?;
Source

pub fn get_incoming(&self) -> Result<Packet, DDPError>

Attempts to retrieve a packet from the display (non-blocking).

Checks if any response packets have been received from the display.

§Returns
  • Ok(Packet) - A packet was available
  • Err(DDPError::NothingToReceive) - No packets waiting
  • Err(DDPError::CrossBeamError) - Channel error
Source

pub fn try_new<A>( addr: A, pixel_config: PixelConfig, id: ID, socket: UdpSocket, ) -> Result<DDPConnection, DDPError>
where A: ToSocketAddrs,

Creates a new DDP connection to a display.

§Arguments
  • addr - The display address (IP:port). DDP standard port is 4048.
  • pixel_config - Pixel format configuration (RGB, RGBW, etc.)
  • id - Protocol ID to use for this connection
  • socket - A bound UDP socket for sending/receiving data
§Returns
  • Ok(DDPConnection) - Connection created successfully
  • Err(DDPError) - Failed to resolve address or create connection
§Examples
use ddp_rs::connection::DDPConnection;
use ddp_rs::protocol::{PixelConfig, ID};
use std::net::UdpSocket;

let conn = DDPConnection::try_new(
    "192.168.1.40:4048",
    PixelConfig::default(),
    ID::Default,
    UdpSocket::bind("0.0.0.0:4048")?
)?;

Trait Implementations§

Source§

impl Debug for DDPConnection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.