fix borrowing issue and make everything compile
This commit is contained in:
parent
08debc3899
commit
e68cc8bcbc
@ -2,7 +2,7 @@ use config::Config;
|
||||
use serde::{Serialize,Deserialize};
|
||||
use crate::errors::LJResult;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Conf {
|
||||
pub laser_id: u8,
|
||||
pub debug: bool,
|
||||
@ -10,7 +10,7 @@ pub struct Conf {
|
||||
pub dac: DacFamily
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum DacFamily {
|
||||
#[serde(rename = "helios")]
|
||||
Helios(HeliosConf),
|
||||
@ -18,12 +18,12 @@ pub enum DacFamily {
|
||||
Etherdream(EtherDreamConf),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct HeliosConf {
|
||||
pub id: u8
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct EtherDreamConf {
|
||||
pub url: String
|
||||
}
|
||||
|
@ -27,16 +27,16 @@ impl HeliosDevice {
|
||||
///
|
||||
/// ` some example `
|
||||
///
|
||||
pub fn new(conf: HeliosConf) -> LJResult<Self> {
|
||||
pub fn new(conf: &HeliosConf) -> LJResult<Self> {
|
||||
let id = conf.id;
|
||||
let controller = NativeHeliosDacController::new()?;
|
||||
let devices = controller.list_devices()?;
|
||||
let Some( dac) = devices.iter().nth(id as usize) else {
|
||||
let Some(device) = devices.into_iter().nth(id as usize) else {
|
||||
return Err(Box::new(LJError::HeliosDeviceMissing));
|
||||
};
|
||||
dac.open()?;
|
||||
let dac = device.open()?;
|
||||
Ok(Self {
|
||||
conf,
|
||||
conf: (*conf).clone(),
|
||||
dac,
|
||||
})
|
||||
}
|
||||
@ -64,11 +64,16 @@ impl Device for HeliosDevice {
|
||||
fn draw(&self,
|
||||
line: Vec<Point>,
|
||||
speed: u32,
|
||||
) -> LJResult<bool> {
|
||||
) -> 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);
|
||||
Ok(true)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn stop(&mut self) -> LJResult<()> {
|
||||
self.dac.stop()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,19 @@ pub struct Status {
|
||||
}
|
||||
|
||||
pub trait Device {
|
||||
|
||||
fn status( &self ) -> Status;
|
||||
fn draw(
|
||||
&self,
|
||||
frame: Vec<Point>,
|
||||
speed: u32,
|
||||
) -> LJResult<bool> ;
|
||||
) -> LJResult<()> ;
|
||||
fn stop(&mut self) -> LJResult<()>;
|
||||
}
|
||||
|
||||
pub fn device_factory(config: Conf) -> Box<dyn Device> {
|
||||
let device = match config.dac {
|
||||
DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf).unwrap()),
|
||||
DacFamily::Etherdream(conf) => todo!(),
|
||||
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
|
||||
let device = match &config.dac {
|
||||
DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?),
|
||||
DacFamily::Etherdream(_conf) => todo!(),
|
||||
};
|
||||
device
|
||||
Ok(device)
|
||||
}
|
10
src/main.rs
10
src/main.rs
@ -56,8 +56,10 @@ fn run_all() -> LJResult<()> {
|
||||
})?;
|
||||
|
||||
// Setup Laser Device based on conf
|
||||
let mut tracer = device_factory(conf)?;
|
||||
dbg!(tracer);
|
||||
let mut tracer = device_factory(&config)?;
|
||||
|
||||
// can't work, but we can add + Debug to Device to make it work...
|
||||
//dbg!(tracer);
|
||||
|
||||
// Setup geometry transformers on points lists
|
||||
// @todo use the config
|
||||
@ -76,11 +78,11 @@ fn run_all() -> LJResult<()> {
|
||||
&mut rs, order == Order::Black)?;
|
||||
|
||||
// For now, draw all the time
|
||||
tracer.draw(frame : Vec<Point>, 1000);
|
||||
tracer.draw(frame, 1000)?;
|
||||
}
|
||||
|
||||
info!("Exiting, stoping device.");
|
||||
device.stop()?;
|
||||
tracer.stop()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user