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