lj_rust/src/device.rs

69 lines
1.6 KiB
Rust
Raw Normal View History

mod helios;
2023-06-29 21:24:56 +00:00
mod dummy;
2023-06-12 17:23:59 +00:00
use std::fmt;
use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/};
use crate::device::helios::HeliosDevice;
2023-06-29 21:24:56 +00:00
use crate::device::dummy::DummyDevice;
use crate::errors::LJResult;
2023-06-12 17:23:59 +00:00
use crate::point::Point;
use serde::Serialize;
/*
self.protocol_version,
self.le_state,
self.playback_state,
self.source,
self.le_flags,
self.playback_flags,
self.source_flags,
self.fullness,
self.point_rate,
self.point_count
*/
2023-06-12 17:23:59 +00:00
#[repr(u8)]
#[derive(Debug, PartialEq, Serialize, Copy, Clone)]
pub enum PlaybackState {
IDLE = 0,
PREPARE,
PLAYING,
}
impl fmt::Display for PlaybackState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
2023-06-12 17:23:59 +00:00
#[derive(Debug)]
pub struct Status {
2023-06-12 17:23:59 +00:00
pub last_traced_at: String,
pub properties: Vec<String>,
pub playback_state: PlaybackState,
pub capacity: u16,
pub lack: String
}
2023-06-12 17:23:59 +00:00
// /lstt/lasernumber etherdream last_status.playback_state (0: idle 1: prepare 2: playing)
// /cap/lasernumber number of empty points sent to fill etherdream buffer (up to 1799)
// /lack/lasernumber "a": ACK "F": Full "I": invalid. 64 or 35 for no connection.
pub trait Device {
2023-06-12 17:23:59 +00:00
fn status(&self) -> Status;
fn draw(
&mut self,
frame: Vec<Point>,
speed: u32,
) -> LJResult<()>;
fn stop(&mut self) -> LJResult<()>;
}
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
2023-06-29 21:24:56 +00:00
let device : Box<dyn Device> = match &config.dac {
DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?),
DacFamily::Etherdream(_conf) => todo!(),
DacFamily::Dummy => Box::new(DummyDevice::new()?)
};
Ok(device)
}