pub mod backend;
pub mod dac;
pub mod error;
pub mod protocol;
pub use crate::protocols::lasercube_usb::dac::{DeviceInfo, DeviceStatus, FirmwareVersion, Stream};
pub use crate::protocols::lasercube_usb::error::{Error, Result};
pub use crate::protocols::lasercube_usb::protocol::Sample;
pub use backend::LasercubeUsbBackend;
pub use rusb;
use crate::types::{DacCapabilities, OutputModel};
pub fn default_capabilities() -> DacCapabilities {
DacCapabilities {
pps_min: 1,
pps_max: 35_000,
max_points_per_chunk: 4096,
output_model: OutputModel::NetworkFifo,
}
}
use protocol::{CONTROL_TIMEOUT, LASERDOCK_PID, LASERDOCK_VID};
use rusb::UsbContext;
pub struct DacController {
context: rusb::Context,
}
impl DacController {
pub fn new() -> Result<Self> {
Ok(DacController {
context: rusb::Context::new()?,
})
}
pub fn list_devices(&self) -> Result<Vec<rusb::Device<rusb::Context>>> {
let devices = self.context.devices()?;
let mut dacs = Vec::new();
for device in devices.iter() {
let descriptor = device.device_descriptor()?;
if descriptor.vendor_id() == LASERDOCK_VID && descriptor.product_id() == LASERDOCK_PID {
dacs.push(device);
}
}
Ok(dacs)
}
}
pub fn get_serial_number<T: UsbContext>(device: &rusb::Device<T>) -> Option<String> {
let descriptor = device.device_descriptor().ok()?;
descriptor.serial_number_string_index()?;
let handle = device.open().ok()?;
let languages = handle.read_languages(CONTROL_TIMEOUT).ok()?;
let lang = languages.first()?;
handle
.read_serial_number_string(*lang, &descriptor, CONTROL_TIMEOUT)
.ok()
}