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 using a streaming API that provides uniform pacing and backpressure across all device types.
§Getting Started
The streaming API provides two modes of operation:
§Blocking Mode
Use next_request() to get what to produce, then write() to send points:
use laser_dac::{list_devices, open_device, StreamConfig, LaserPoint};
// Discover devices
let devices = list_devices().unwrap();
println!("Found {} devices", devices.len());
// Open and start streaming
let device = open_device(&devices[0].id).unwrap();
let config = StreamConfig::new(30_000); // 30k points per second
let (mut stream, info) = device.start_stream(config).unwrap();
// Arm the output (allow laser to fire)
stream.control().arm().unwrap();
// Streaming loop
loop {
let req = stream.next_request().unwrap();
// Generate points for this chunk
let points: Vec<LaserPoint> = (0..req.n_points)
.map(|i| {
let t = (req.start.points() + i as u64) as f32 / req.pps as f32;
let angle = t * std::f32::consts::TAU;
LaserPoint::new(angle.cos(), angle.sin(), 65535, 0, 0, 65535)
})
.collect();
stream.write(&req, &points).unwrap();
}§Callback Mode
Use run() with a producer closure for simpler code:
use laser_dac::{list_devices, open_device, StreamConfig, LaserPoint, ChunkRequest};
let device = open_device("my-device").unwrap();
let config = StreamConfig::new(30_000);
let (stream, _info) = device.start_stream(config).unwrap();
stream.control().arm().unwrap();
let exit = stream.run(
|req: ChunkRequest| {
// Return Some(points) to continue, None to stop
let points = vec![LaserPoint::blanked(0.0, 0.0); req.n_points];
Some(points)
},
|err| eprintln!("Stream error: {}", err),
);§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 protocolsusb-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::StreamBackend;pub use backend::WriteOutcome;pub use discovery::DacDiscovery;pub use discovery::DiscoveredDevice;pub use discovery::DiscoveredDeviceInfo;pub use discovery::ExternalDevice;pub use discovery::ExternalDiscoverer;pub use types::caps_for_dac_type;pub use types::ChunkRequest;pub use types::DacCapabilities;pub use types::DacConnectionState;pub use types::DacDevice;pub use types::DacInfo;pub use types::DacType;pub use types::EnabledDacTypes;pub use types::LaserPoint;pub use types::OutputModel;pub use types::RunExit;pub use types::StreamConfig;pub use types::StreamInstant;pub use types::StreamStats;pub use types::StreamStatus;pub use types::UnderrunPolicy;pub use session::ReconnectingSession;pub use session::SessionControl;pub use stream::Dac;pub use stream::OwnedDac;pub use stream::Stream;pub use stream::StreamControl;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 trait and implementations for the streaming API.
- discovery
- DAC device discovery.
- protocols
- Protocol implementations for various laser DAC types.
- session
- Reconnecting session wrapper for automatic reconnection.
- stream
- Stream and Dac types for point output.
- types
- DAC types for laser output.
Structs§
- Frame
- A point buffer to be cycled by the adapter.
- Frame
Adapter - Converts a point buffer (frame) into a continuous stream.
- Shared
Frame Adapter - Thread-safe handle for updating frames from another thread.
Enums§
- Error
- Streaming-specific error type.
Functions§
- list_
devices - List all available DACs.
- list_
devices_ filtered - List available DACs filtered by DAC type.
- open_
device - Open a DAC by ID.
Type Aliases§
- Result
- Result type for streaming operations.