lj_rust/src/device/helios.rs

72 lines
1.8 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, PlaybackState};
use crate::errors::{LJError, LJResult};
use crate::point::Point;
pub struct HeliosDevice {
pub conf: HeliosConf,
dac: NativeHeliosDac,
sent_points: u16,
state: PlaybackState,
lack: String
}
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, sent_points: 0, state: PlaybackState::PREPARE, lack: "".to_string() })
}
}
impl Device for HeliosDevice {
fn status(&self) -> Status {
let lack = self.lack.clone();
Status {
last_traced_at: "now".to_string(),
properties: vec!["foo".to_string()],
playback_state: self.state,
capacity: self.sent_points,
lack,
}
}
fn draw(&mut self,
line: Vec<Point>,
speed: u32,
) -> LJResult<()> {
self.state = PlaybackState::IDLE;
while let Ok(DeviceStatus::NotReady) = self.dac.status() {}
self.state = PlaybackState::PLAYING;
let points: Vec<helios_dac::Point> = line.into_iter().map(|p| p.into()).collect();
let frame = Frame::new(speed, points.clone());
self.dac.write_frame(frame.clone())?;
self.sent_points = points.len() as u16;
Ok(())
}
fn stop(&mut self) -> LJResult<()> {
self.dac.stop()?;
Ok(())
}
}