mod helios; mod dummy; mod etherdream; use std::fmt; use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/}; use crate::device::helios::HeliosDevice; use crate::device::dummy::DummyDevice; use crate::errors::LJResult; use crate::point::Point; use serde::Serialize; use crate::device::etherdream::EtherdreamDevice; /* 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 */ #[repr(u8)] #[derive(Debug, PartialEq, Serialize, Copy, Clone)] pub enum PlaybackState { IDLE = 0, PREPARE = 1, PLAYING = 2, UNKNOWN = 99, } impl fmt::Display for PlaybackState { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) } } #[derive(Debug)] pub struct Status { pub last_traced_at: String, pub properties: Vec, pub playback_state: PlaybackState, pub capacity: u16, pub lack: String, } // /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 { fn status(&mut self) -> Status; fn draw( &mut self, frame: Vec, speed: u32, ) -> LJResult<()>; fn stop(&mut self) -> LJResult<()>; fn grid(&mut self) -> Vec; } pub fn device_factory(config: &Conf) -> LJResult> { let device: Box = match &config.dac { DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?), DacFamily::Etherdream( conf) => Box::new( EtherdreamDevice::new(conf)?), DacFamily::Dummy => Box::new(DummyDevice::new()?) }; Ok(device) }