wip
This commit is contained in:
parent
3588e3f4a2
commit
08debc3899
14
src/device.old
Normal file
14
src/device.old
Normal file
@ -0,0 +1,14 @@
|
||||
mod device;
|
||||
mod helios;
|
||||
|
||||
use crate::conf::{Conf, DacFamily, EtherDreamConf, HeliosConf};
|
||||
use crate::device::device::Device;
|
||||
use crate::device::helios::HeliosDevice;
|
||||
|
||||
pub fn device_factory(config: Conf) -> Box<dyn Device> {
|
||||
let device = match config.dac {
|
||||
DacFamily::Helios(conf) => Box::new(HeliosDevice { conf }),
|
||||
DacFamily::Etherdream(conf) => todo!(),
|
||||
};
|
||||
device
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
mod common;
|
||||
mod helios;
|
||||
|
||||
use crate::conf::{Conf, DacFamily, EtherDreamConf, HeliosConf};
|
||||
use crate::device::common::Device;
|
||||
use crate::device::helios::HeliosDevice;
|
||||
|
||||
pub fn device_factory(config: Conf) -> Box<dyn Device> {
|
||||
let device = match config.dac {
|
||||
DacFamily::Helios(conf) => Box::new(HeliosDevice { conf }),
|
||||
DacFamily::Etherdream( conf) => todo!(),
|
||||
};
|
||||
|
||||
device
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
pub struct Status {
|
||||
pub active: bool,
|
||||
pub last_traced_at: String,
|
||||
pub properties: Vec<String>
|
||||
}
|
||||
|
||||
pub trait Device {
|
||||
/**
|
||||
fn intersect(&self, orig : &Vec3, dir : &Vec3) -> Option<Float>;
|
||||
fn get_surface(&self, v : &Vec3) -> Vec3;
|
||||
fn get_normal(&self, v : &Vec3) -> Vec3;
|
||||
fn get_material(&self) -> &dyn Material;
|
||||
**/
|
||||
|
||||
fn status( &self ) -> Status;
|
||||
|
||||
}
|
@ -2,35 +2,73 @@
|
||||
/// Configure udev:
|
||||
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
||||
///
|
||||
use helios_dac::NativeHeliosDacController;
|
||||
use helios_dac::{NativeHeliosDac, NativeHeliosDacController};
|
||||
use helios_dac::{
|
||||
// Coordinate,
|
||||
Color,
|
||||
DeviceStatus,
|
||||
Frame,
|
||||
Point,
|
||||
// Coordinate,
|
||||
Color,
|
||||
DeviceStatus,
|
||||
Frame,
|
||||
Point as HeliosPoint,
|
||||
};
|
||||
use crate::conf::HeliosConf;
|
||||
use crate::device::common::{Device, Status};
|
||||
use crate::device::{Device, Status};
|
||||
use crate::errors::{LJError, LJResult};
|
||||
use crate::point::Point;
|
||||
|
||||
pub struct HeliosDevice {
|
||||
pub conf: HeliosConf,
|
||||
pub conf: HeliosConf,
|
||||
dac: NativeHeliosDac,
|
||||
}
|
||||
|
||||
impl HeliosDevice {
|
||||
|
||||
pub fn new ( conf: HeliosConf) -> Self{
|
||||
Self{ conf }
|
||||
}
|
||||
|
||||
/// This is fabulous doc !
|
||||
/// # Woot
|
||||
///
|
||||
/// ` some example `
|
||||
///
|
||||
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 {
|
||||
return Err(Box::new(LJError::HeliosDeviceMissing));
|
||||
};
|
||||
dac.open()?;
|
||||
Ok(Self {
|
||||
conf,
|
||||
dac,
|
||||
})
|
||||
}
|
||||
}
|
||||
//
|
||||
// fn get_helios_device() -> LJResult<NativeHeliosDac> {
|
||||
// let controller = NativeHeliosDacController::new()?;
|
||||
// let devices = controller.list_devices()?;
|
||||
// let Some(device) = devices.into_iter().next() else {
|
||||
// return Err(Box::new(LJError::HeliosDeviceMissing));
|
||||
// };
|
||||
// let device = device.open()?;
|
||||
// Ok(device)
|
||||
// }
|
||||
|
||||
impl Device for HeliosDevice {
|
||||
fn status(&self) -> Status {
|
||||
return Status {
|
||||
active: true,
|
||||
last_traced_at: "now".to_string(),
|
||||
properties: vec!["foo".to_string()],
|
||||
};
|
||||
}
|
||||
fn status(&self) -> Status {
|
||||
return Status {
|
||||
active: true,
|
||||
last_traced_at: "now".to_string(),
|
||||
properties: vec!["foo".to_string()],
|
||||
};
|
||||
}
|
||||
|
||||
fn draw(&self,
|
||||
line: Vec<Point>,
|
||||
speed: u32,
|
||||
) -> LJResult<bool> {
|
||||
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)
|
||||
}
|
||||
}
|
45
src/device/mod.rs
Normal file
45
src/device/mod.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use crate::point::Point;
|
||||
|
||||
mod helios;
|
||||
|
||||
use crate::conf::{Conf, DacFamily, EtherDreamConf, HeliosConf};
|
||||
use crate::device::helios::HeliosDevice;
|
||||
use crate::errors::LJResult;
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
|
||||
pub struct Status {
|
||||
pub active: bool,
|
||||
pub last_traced_at: String,
|
||||
pub properties: Vec<String>
|
||||
}
|
||||
|
||||
pub trait Device {
|
||||
|
||||
fn status( &self ) -> Status;
|
||||
fn draw(
|
||||
&self,
|
||||
frame: Vec<Point>,
|
||||
speed: u32,
|
||||
) -> LJResult<bool> ;
|
||||
}
|
||||
|
||||
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!(),
|
||||
};
|
||||
device
|
||||
}
|
@ -2,3 +2,4 @@ pub mod conf;
|
||||
pub mod redis_ctrl;
|
||||
pub mod errors;
|
||||
pub mod device;
|
||||
pub mod point;
|
||||
|
45
src/main.rs
45
src/main.rs
@ -11,13 +11,7 @@ mod device;
|
||||
|
||||
use device::device_factory;
|
||||
|
||||
use helios_dac::{
|
||||
self,
|
||||
NativeHeliosDacController,
|
||||
NativeHeliosDac,
|
||||
DeviceStatus,
|
||||
Frame,
|
||||
};
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use redis_ctrl::{RedisCtrl, Order};
|
||||
@ -41,42 +35,48 @@ pub fn main() {
|
||||
}
|
||||
|
||||
fn run_all() -> LJResult<()> {
|
||||
|
||||
// Setup configuration file and set up logs
|
||||
let filename = std::env::args().nth(1).unwrap_or_else(|| {
|
||||
DEFAULT_CONF_FILE.to_string()
|
||||
});
|
||||
|
||||
let config = Conf::new(&filename);
|
||||
init_logging(&config);
|
||||
let config = config?;
|
||||
info!("*** Starting up ***");
|
||||
|
||||
// Setup Redis Service
|
||||
let mut rs = RedisCtrl::new(&config.redis_url)?;
|
||||
|
||||
// Setup handler for interrupt Signals
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let r = running.clone();
|
||||
ctrlc::set_handler(move || {
|
||||
r.store(false, Ordering::SeqCst);
|
||||
})?;
|
||||
|
||||
let mut device = get_helios_device()?;
|
||||
// Setup Laser Device based on conf
|
||||
let mut tracer = device_factory(conf)?;
|
||||
dbg!(tracer);
|
||||
|
||||
// Setup geometry transformers on points lists
|
||||
// @todo use the config
|
||||
let transformers: Vec<Box<dyn Transformers>> = vec![
|
||||
Box::new(Translate::new(CENTER.0, CENTER.1)),
|
||||
Box::new(Replicate::Until(48)),
|
||||
];
|
||||
|
||||
// Dispatch based on redis requests
|
||||
while running.load(Ordering::SeqCst) {
|
||||
|
||||
let order = rs.get_order(config.laser_id)?;
|
||||
if order != Order::Draw {
|
||||
info!("Order: {:?}", order);
|
||||
}
|
||||
|
||||
let frame = get_next_frame(&config, 1000, &transformers,
|
||||
let frame = get_next_frame(&config, &transformers,
|
||||
&mut rs, order == Order::Black)?;
|
||||
|
||||
while let Ok(DeviceStatus::NotReady) = device.status() {}
|
||||
device.write_frame(frame)?;
|
||||
// For now, draw all the time
|
||||
tracer.draw(frame : Vec<Point>, 1000);
|
||||
}
|
||||
|
||||
info!("Exiting, stoping device.");
|
||||
@ -99,23 +99,12 @@ fn init_logging(config: &LJResult<Conf>) {
|
||||
env_logger::init();
|
||||
}
|
||||
|
||||
fn get_helios_device() -> LJResult<NativeHeliosDac> {
|
||||
let controller = NativeHeliosDacController::new()?;
|
||||
let devices = controller.list_devices()?;
|
||||
let Some(device) = devices.into_iter().next() else {
|
||||
return Err(Box::new(LJError::HeliosDeviceMissing));
|
||||
};
|
||||
let device = device.open()?;
|
||||
Ok(device)
|
||||
}
|
||||
|
||||
fn get_next_frame(
|
||||
config: &Conf,
|
||||
speed: u32,
|
||||
transformers: &[Box<dyn Transformers>],
|
||||
rs: &mut RedisCtrl,
|
||||
_black: bool,
|
||||
) -> LJResult<Frame> {
|
||||
) -> LJResult<Vec<Point>> {
|
||||
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
||||
let mut line: Vec<Point> = line.into_iter().map(|tpl| tpl.into()).collect();
|
||||
for transformer in transformers {
|
||||
@ -123,7 +112,5 @@ fn get_next_frame(
|
||||
}
|
||||
|
||||
info!("Line: {:?}", line);
|
||||
|
||||
let line2: Vec<helios_dac::Point> = line.into_iter().map(|p| p.into()).collect();
|
||||
Ok(Frame::new(speed, line2))
|
||||
Ok(line)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user