lj_rust/src/device/helios.rs

63 lines
1.4 KiB
Rust

///
/// Configure udev:
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
///
use helios_dac::{NativeHeliosDac, NativeHeliosDacController};
use helios_dac::{
// Coordinate,
// Color,
DeviceStatus,
Frame,
// Point as HeliosPoint,
};
use crate::conf::HeliosConf;
use crate::device::{Device, Status};
use crate::errors::{LJError, LJResult};
use crate::point::Point;
pub struct HeliosDevice {
pub conf: HeliosConf,
dac: NativeHeliosDac,
}
impl HeliosDevice {
pub fn new(conf: &HeliosConf) -> LJResult<Self> {
let id = conf.id;
let controller = NativeHeliosDacController::new()?;
let devices = controller.list_devices()?;
let Some(device) = devices.into_iter().nth(id as usize) else {
return Err(Box::new(LJError::HeliosDeviceMissing));
};
let dac = device.open()?;
Ok(Self { conf: (*conf).clone(), dac })
}
}
impl Device for HeliosDevice {
fn status(&self) -> Status {
Status {
active: true,
last_traced_at: "now".to_string(),
properties: vec!["foo".to_string()],
}
}
fn draw(&mut self,
line: Vec<Point>,
speed: u32,
) -> LJResult<()> {
while let Ok(DeviceStatus::NotReady) = self.dac.status() {
}
let points: Vec<helios_dac::Point> = line.into_iter().map(|p| p.into()).collect();
let frame = Frame::new(speed, points);
self.dac.write_frame(frame.clone())?;
Ok(())
}
fn stop(&mut self) -> LJResult<()> {
self.dac.stop()?;
Ok(())
}
}