wip
This commit is contained in:
parent
1072ff4660
commit
3588e3f4a2
15
src/device.rs
Normal file
15
src/device.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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
|
||||||
|
}
|
31
src/device/common.rs
Normal file
31
src/device/common.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
36
src/device/helios.rs
Normal file
36
src/device/helios.rs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
///
|
||||||
|
/// Configure udev:
|
||||||
|
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
||||||
|
///
|
||||||
|
use helios_dac::NativeHeliosDacController;
|
||||||
|
use helios_dac::{
|
||||||
|
// Coordinate,
|
||||||
|
Color,
|
||||||
|
DeviceStatus,
|
||||||
|
Frame,
|
||||||
|
Point,
|
||||||
|
};
|
||||||
|
use crate::conf::HeliosConf;
|
||||||
|
use crate::device::common::{Device, Status};
|
||||||
|
|
||||||
|
pub struct HeliosDevice {
|
||||||
|
pub conf: HeliosConf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HeliosDevice {
|
||||||
|
|
||||||
|
pub fn new ( conf: HeliosConf) -> Self{
|
||||||
|
Self{ conf }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Device for HeliosDevice {
|
||||||
|
fn status(&self) -> Status {
|
||||||
|
return Status {
|
||||||
|
active: true,
|
||||||
|
last_traced_at: "now".to_string(),
|
||||||
|
properties: vec!["foo".to_string()],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
pub mod conf;
|
pub mod conf;
|
||||||
pub mod redis_ctrl;
|
pub mod redis_ctrl;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
pub mod device;
|
||||||
|
175
src/main.rs
175
src/main.rs
@ -7,122 +7,123 @@ mod conf;
|
|||||||
mod errors;
|
mod errors;
|
||||||
mod point;
|
mod point;
|
||||||
mod transformer;
|
mod transformer;
|
||||||
|
mod device;
|
||||||
|
|
||||||
|
use device::device_factory;
|
||||||
|
|
||||||
use helios_dac::{
|
use helios_dac::{
|
||||||
self,
|
self,
|
||||||
NativeHeliosDacController,
|
NativeHeliosDacController,
|
||||||
NativeHeliosDac,
|
NativeHeliosDac,
|
||||||
DeviceStatus,
|
DeviceStatus,
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use redis_ctrl::{RedisCtrl,Order};
|
use redis_ctrl::{RedisCtrl, Order};
|
||||||
use conf::Conf;
|
use conf::Conf;
|
||||||
use errors::{LJError,LJResult};
|
use errors::{LJError, LJResult};
|
||||||
use point::Point;
|
use point::Point;
|
||||||
use transformer::{Transformers,Translate,Replicate};
|
use transformer::{Transformers, Translate, Replicate};
|
||||||
use log::{LevelFilter,info,/* warn, */ error};
|
use log::{LevelFilter, info, /* warn, */ error};
|
||||||
use env_logger::Builder;
|
use env_logger::Builder;
|
||||||
|
|
||||||
const DEFAULT_CONF_FILE : &str = "settings.toml";
|
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
||||||
const CENTER : (f32,f32) = (2000.0, 2000.0);
|
const CENTER: (f32, f32) = (2000.0, 2000.0);
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
match run_all() {
|
match run_all() {
|
||||||
Ok(()) => {},
|
Ok(()) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Error: {}", err);
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_all() -> LJResult<()> {
|
fn run_all() -> LJResult<()> {
|
||||||
let filename = std::env::args().nth(1).unwrap_or_else(|| {
|
let filename = std::env::args().nth(1).unwrap_or_else(|| {
|
||||||
DEFAULT_CONF_FILE.to_string()
|
DEFAULT_CONF_FILE.to_string()
|
||||||
});
|
});
|
||||||
|
|
||||||
let config = Conf::new(&filename);
|
|
||||||
init_logging(&config);
|
|
||||||
let config = config?;
|
|
||||||
info!("*** Starting up ***");
|
|
||||||
|
|
||||||
let mut rs = RedisCtrl::new(&config.redis_url)?;
|
|
||||||
|
|
||||||
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()?;
|
let config = Conf::new(&filename);
|
||||||
|
init_logging(&config);
|
||||||
|
let config = config?;
|
||||||
|
info!("*** Starting up ***");
|
||||||
|
|
||||||
let transformers : Vec<Box<dyn Transformers>> = vec![
|
let mut rs = RedisCtrl::new(&config.redis_url)?;
|
||||||
Box::new(Translate::new(CENTER.0, CENTER.1)),
|
|
||||||
Box::new(Replicate::Until(48))
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
];
|
let r = running.clone();
|
||||||
|
ctrlc::set_handler(move || {
|
||||||
while running.load(Ordering::SeqCst) {
|
r.store(false, Ordering::SeqCst);
|
||||||
let order = rs.get_order(config.laser_id)?;
|
})?;
|
||||||
if order != Order::Draw {
|
|
||||||
info!("Order: {:?}", order);
|
let mut device = get_helios_device()?;
|
||||||
|
|
||||||
|
let transformers: Vec<Box<dyn Transformers>> = vec![
|
||||||
|
Box::new(Translate::new(CENTER.0, CENTER.1)),
|
||||||
|
Box::new(Replicate::Until(48)),
|
||||||
|
];
|
||||||
|
|
||||||
|
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,
|
||||||
|
&mut rs, order == Order::Black)?;
|
||||||
|
|
||||||
|
while let Ok(DeviceStatus::NotReady) = device.status() {}
|
||||||
|
device.write_frame(frame)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame = get_next_frame(&config, 1000, &transformers,
|
info!("Exiting, stoping device.");
|
||||||
&mut rs, order == Order::Black)?;
|
device.stop()?;
|
||||||
|
Ok(())
|
||||||
while let Ok(DeviceStatus::NotReady) = device.status() {
|
|
||||||
}
|
|
||||||
device.write_frame(frame)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Exiting, stoping device.");
|
|
||||||
device.stop()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_logging(config: &LJResult<Conf>) {
|
fn init_logging(config: &LJResult<Conf>) {
|
||||||
if let Ok(ref config) = config {
|
if let Ok(ref config) = config {
|
||||||
if config.debug {
|
if config.debug {
|
||||||
let mut builder = Builder::from_default_env();
|
let mut builder = Builder::from_default_env();
|
||||||
builder
|
builder
|
||||||
.filter(None, LevelFilter::Info)
|
.filter(None, LevelFilter::Info)
|
||||||
.init();
|
.init();
|
||||||
info!("Debug mode enabled from configuration file");
|
info!("Debug mode enabled from configuration file");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
info!("Logging level inherited from env");
|
||||||
info!("Logging level inherited from env");
|
env_logger::init();
|
||||||
env_logger::init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_helios_device() -> LJResult<NativeHeliosDac> {
|
fn get_helios_device() -> LJResult<NativeHeliosDac> {
|
||||||
let controller = NativeHeliosDacController::new()?;
|
let controller = NativeHeliosDacController::new()?;
|
||||||
let devices = controller.list_devices()?;
|
let devices = controller.list_devices()?;
|
||||||
let Some(device) = devices.into_iter().next() else {
|
let Some(device) = devices.into_iter().next() else {
|
||||||
return Err(Box::new(LJError::HeliosDeviceMissing));
|
return Err(Box::new(LJError::HeliosDeviceMissing));
|
||||||
};
|
};
|
||||||
let device = device.open()?;
|
let device = device.open()?;
|
||||||
Ok(device)
|
Ok(device)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_next_frame(
|
fn get_next_frame(
|
||||||
config: &Conf,
|
config: &Conf,
|
||||||
speed: u32,
|
speed: u32,
|
||||||
transformers: &[Box<dyn Transformers>],
|
transformers: &[Box<dyn Transformers>],
|
||||||
rs: &mut RedisCtrl,
|
rs: &mut RedisCtrl,
|
||||||
_black: bool
|
_black: bool,
|
||||||
) -> LJResult<Frame> {
|
) -> LJResult<Frame> {
|
||||||
|
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 {
|
||||||
|
line = transformer.apply(&line);
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("Line: {:?}", line);
|
||||||
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 {
|
|
||||||
line = transformer.apply(&line);
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Line: {:?}", line);
|
let line2: Vec<helios_dac::Point> = line.into_iter().map(|p| p.into()).collect();
|
||||||
|
Ok(Frame::new(speed, line2))
|
||||||
let line2 : Vec<helios_dac::Point> = line.into_iter().map(| p | p.into()).collect();
|
|
||||||
Ok(Frame::new(speed, line2))
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user