lj_rust/src/device.rs

69 lines
1.8 KiB
Rust
Raw Normal View History

2023-06-29 21:24:56 +00:00
mod dummy;
2023-07-06 20:18:44 +00:00
mod etherdream;
2023-08-23 11:13:53 +00:00
mod helios;
2023-06-12 17:23:59 +00:00
use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/};
2023-06-29 21:24:56 +00:00
use crate::device::dummy::DummyDevice;
2023-08-23 11:13:53 +00:00
use crate::device::etherdream::EtherdreamDevice;
use crate::device::helios::HeliosDevice;
use crate::errors::LJResult;
2023-06-12 17:23:59 +00:00
use crate::point::Point;
use serde::Serialize;
2023-08-23 11:13:53 +00:00
use std::fmt;
/*
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 {
2023-08-23 11:13:53 +00:00
IDLE = 0,
PREPARE = 1,
PLAYING = 2,
UNKNOWN = 99,
2023-06-12 17:23:59 +00:00
}
2023-07-16 18:28:06 +00:00
2023-06-12 17:23:59 +00:00
impl fmt::Display for PlaybackState {
2023-08-23 11:13:53 +00:00
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
2023-06-12 17:23:59 +00:00
}
2023-07-16 18:28:06 +00:00
#[derive(Debug)]
pub struct Status {
2023-08-23 11:13:53 +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-08-23 11:13:53 +00:00
fn status(&mut self) -> Status;
fn draw(&mut self, frame: Vec<Point>, speed: u32) -> LJResult<()>;
fn stop(&mut self) -> LJResult<()>;
fn grid(&mut self) -> Vec<Point>;
}
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
2023-08-23 11:13:53 +00:00
let device: Box<dyn Device> = 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)
}