Crate laser_dac

Crate laser_dac 

Source
Expand description

Unified DAC backend abstraction for laser projectors.

This crate provides a common interface for communicating with various laser DAC (Digital-to-Analog Converter) hardware, allowing you to write laser frames without worrying about device-specific protocols.

§Getting Started

The easiest way to use this crate is with DacDiscoveryWorker, which handles device discovery and connection in the background:

use laser_dac::{DacDiscoveryWorker, EnabledDacTypes, LaserFrame, LaserPoint};
use std::thread;
use std::time::Duration;

// Start background discovery for all DAC types
let discovery = DacDiscoveryWorker::builder()
    .enabled_types(EnabledDacTypes::all())
    .build();

// Collect discovered devices
let mut workers = Vec::new();
for _ in 0..50 {
    for worker in discovery.poll_new_workers() {
        println!("Found: {} ({})", worker.device_name(), worker.dac_type());
        workers.push(worker);
    }
    thread::sleep(Duration::from_millis(100));
}

// Create a frame (simple square)
let points = vec![
    LaserPoint::blanked(-0.5, -0.5),
    LaserPoint::new(-0.5, -0.5, 65535, 0, 0, 65535),
    LaserPoint::new(0.5, -0.5, 0, 65535, 0, 65535),
    LaserPoint::new(0.5, 0.5, 0, 0, 65535, 65535),
    LaserPoint::new(-0.5, 0.5, 65535, 65535, 0, 65535),
    LaserPoint::new(-0.5, -0.5, 65535, 0, 0, 65535),
];
let frame = LaserFrame::new(30000, points);

// Send frames to all connected DACs
loop {
    for worker in &mut workers {
        worker.update();
        worker.submit_frame(frame.clone());
    }
    thread::sleep(Duration::from_millis(33));
}

For more control over discovery and connection, use DacDiscovery directly:

use laser_dac::{DacDiscovery, DacWorker, EnabledDacTypes, LaserFrame, LaserPoint};

let mut discovery = DacDiscovery::new(EnabledDacTypes::all());
let devices = discovery.scan();

for device in devices {
    let name = device.name().to_string();
    let dac_type = device.dac_type();
    let backend = discovery.connect(device).expect("connection failed");
    let mut worker = DacWorker::new(name, dac_type, backend);

    // Use worker.update() and worker.submit_frame() in your render loop
}

§Supported DACs

  • Helios - USB laser DAC (feature: helios)
  • Ether Dream - Network laser DAC (feature: ether-dream)
  • IDN - ILDA Digital Network protocol (feature: idn)
  • LaserCube WiFi - WiFi-connected laser DAC (feature: lasercube-wifi)
  • LaserCube USB - USB laser DAC / LaserDock (feature: lasercube-usb)

§Features

  • all-dacs (default): Enable all DAC protocols
  • usb-dacs: Enable USB DACs (Helios, LaserCube USB)
  • network-dacs: Enable network DACs (Ether Dream, IDN, LaserCube WiFi)

§Coordinate System

All backends use normalized coordinates:

  • X: -1.0 (left) to 1.0 (right)
  • Y: -1.0 (bottom) to 1.0 (top)
  • Colors: 0-65535 for R, G, B, and intensity

Each backend handles conversion to its native format internally.

Re-exports§

pub use backend::DacBackend;
pub use backend::WriteResult;
pub use discovery::CustomDiscoverySource;
pub use discovery::DacDiscovery;
pub use discovery::DiscoveredDevice;
pub use discovery::DiscoveredDeviceInfo;
pub use discovery_worker::DacDiscoveryWorker;
pub use discovery_worker::DacDiscoveryWorkerBuilder;
pub use worker::CallbackContext;
pub use worker::CallbackError;
pub use worker::DacCallbackWorker;
pub use worker::DacWorker;
pub use worker::WorkerCommand;
pub use worker::WorkerStatus;
pub use types::DacConnectionState;
pub use types::DacDevice;
pub use types::DacType;
pub use types::DiscoveredDac;
pub use types::EnabledDacTypes;
pub use types::LaserFrame;
pub use types::LaserPoint;
pub use backend::HeliosBackend;
pub use protocols::helios;
pub use backend::EtherDreamBackend;
pub use protocols::ether_dream;
pub use backend::IdnBackend;
pub use protocols::idn;
pub use backend::LasercubeWifiBackend;
pub use protocols::lasercube_wifi;
pub use backend::LasercubeUsbBackend;
pub use protocols::lasercube_usb;
pub use protocols::lasercube_usb::rusb;

Modules§

backend
DAC backend abstraction and point conversion.
discovery
DAC device discovery.
discovery_worker
Background worker for non-blocking DAC device discovery.
protocols
Protocol implementations for various laser DAC types.
types
DAC types for laser output.
worker
Background workers for non-blocking DAC frame writing.

Enums§

Error
Crate-level error type.

Type Aliases§

Result
Crate-level result type.