Compare commits
No commits in common. "ad3b3803cee3df42e531dfa56aa4cd589babac3f" and "40abb3ac57617775a70c51b0d2bd96f8a31f4ebd" have entirely different histories.
ad3b3803ce
...
40abb3ac57
@ -14,4 +14,3 @@ log = "0.4.18"
|
|||||||
redis = "0.23.0"
|
redis = "0.23.0"
|
||||||
ron = "0.8.0"
|
ron = "0.8.0"
|
||||||
serde = { version = "1.0.163", features = ["derive"] }
|
serde = { version = "1.0.163", features = ["derive"] }
|
||||||
toml = "0.7.4"
|
|
||||||
|
@ -18,11 +18,3 @@ id = 0
|
|||||||
# For Etherdream. IP of the DAC
|
# For Etherdream. IP of the DAC
|
||||||
# [dac.etherdream]
|
# [dac.etherdream]
|
||||||
# url = "192.168.1.68"
|
# url = "192.168.1.68"
|
||||||
|
|
||||||
[[transformers]]
|
|
||||||
[transformers.translate]
|
|
||||||
x = 2000
|
|
||||||
y = 2000
|
|
||||||
[[transformers]]
|
|
||||||
[transformers.replicate]
|
|
||||||
Until = 48
|
|
||||||
|
48
src/conf.rs
48
src/conf.rs
@ -1,19 +1,16 @@
|
|||||||
use config::Config;
|
use config::Config;
|
||||||
use serde::{Serialize,Deserialize};
|
use serde::{Serialize,Deserialize};
|
||||||
use crate::errors::LJResult;
|
use crate::errors::LJResult;
|
||||||
use crate::transformer;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Conf {
|
pub struct Conf {
|
||||||
pub laser_id: u8,
|
pub laser_id: u8,
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub redis_url: String,
|
pub redis_url: String,
|
||||||
pub dac: DacFamily,
|
pub dac: DacFamily
|
||||||
#[serde(default)]
|
|
||||||
pub transformers: Vec<TransformConf>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum DacFamily {
|
pub enum DacFamily {
|
||||||
#[serde(rename = "helios")]
|
#[serde(rename = "helios")]
|
||||||
Helios(HeliosConf),
|
Helios(HeliosConf),
|
||||||
@ -21,25 +18,16 @@ pub enum DacFamily {
|
|||||||
Etherdream(EtherDreamConf),
|
Etherdream(EtherDreamConf),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct HeliosConf {
|
pub struct HeliosConf {
|
||||||
pub id: u8
|
pub id: u8
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct EtherDreamConf {
|
pub struct EtherDreamConf {
|
||||||
pub url: String
|
pub url: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub enum TransformConf {
|
|
||||||
#[serde(rename = "translate")]
|
|
||||||
Translate(transformer::Translate),
|
|
||||||
#[serde(rename = "replicate")]
|
|
||||||
Replicate(transformer::Replicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Conf {
|
impl Conf {
|
||||||
pub fn new(path: &str) -> LJResult<Conf> {
|
pub fn new(path: &str) -> LJResult<Conf> {
|
||||||
let settings = Config::builder()
|
let settings = Config::builder()
|
||||||
@ -49,30 +37,4 @@ impl Conf {
|
|||||||
let conf : Conf = settings.try_deserialize()?;
|
let conf : Conf = settings.try_deserialize()?;
|
||||||
Ok(conf)
|
Ok(conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_transformers(&self) -> Vec<Box<dyn transformer::Transformers>> {
|
|
||||||
let mut v = vec![];
|
|
||||||
for t in &self.transformers {
|
|
||||||
let t : Box<dyn transformer::Transformers> = match t {
|
|
||||||
TransformConf::Translate(t) => Box::new(t.clone()),
|
|
||||||
TransformConf::Replicate(r) => Box::new(r.clone())
|
|
||||||
};
|
|
||||||
v.push(t);
|
|
||||||
}
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn dump() {
|
|
||||||
let conf = Conf { laser_id: 0,
|
|
||||||
debug: true,
|
|
||||||
redis_url: "redis://127.0.0.1:6379/".to_string(),
|
|
||||||
dac: DacFamily::Helios(HeliosConf { id: 0 }),
|
|
||||||
transformers: vec![
|
|
||||||
TransformConf::Translate(transformer::Translate::new(2000.0,2000.0)),
|
|
||||||
TransformConf::Replicate(transformer::Replicate::Until(48))
|
|
||||||
]
|
|
||||||
};
|
|
||||||
let s = toml::to_string(&conf).unwrap();
|
|
||||||
println!("{}", s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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::new(conf)),
|
||||||
|
DacFamily::Etherdream(_conf) => todo!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
device
|
||||||
|
}
|
@ -2,35 +2,29 @@
|
|||||||
/// Configure udev:
|
/// Configure udev:
|
||||||
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
||||||
///
|
///
|
||||||
use helios_dac::{NativeHeliosDac, NativeHeliosDacController};
|
/*
|
||||||
|
use helios_dac::NativeHeliosDacController;
|
||||||
use helios_dac::{
|
use helios_dac::{
|
||||||
// Coordinate,
|
// Coordinate,
|
||||||
Color,
|
Color,
|
||||||
DeviceStatus,
|
DeviceStatus,
|
||||||
Frame,
|
Frame,
|
||||||
Point as HeliosPoint,
|
Point,
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
use crate::conf::HeliosConf;
|
use crate::conf::HeliosConf;
|
||||||
use crate::device::{Device, Status};
|
use crate::device::common::{Device, Status};
|
||||||
use crate::errors::{LJError, LJResult};
|
|
||||||
use crate::point::Point;
|
|
||||||
|
|
||||||
pub struct HeliosDevice {
|
pub struct HeliosDevice {
|
||||||
pub conf: HeliosConf,
|
pub conf: HeliosConf,
|
||||||
dac: NativeHeliosDac,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeliosDevice {
|
impl HeliosDevice {
|
||||||
pub fn new(conf: &HeliosConf) -> LJResult<Self> {
|
|
||||||
let id = conf.id;
|
pub fn new ( conf: HeliosConf) -> Self{
|
||||||
let controller = NativeHeliosDacController::new()?;
|
Self{ conf }
|
||||||
let devices = controller.list_devices()?;
|
|
||||||
let Some(device) = devices.into_iter().nth(id as usize) else {
|
|
||||||
return Err(Box::new(LJError::HeliosDeviceMissing));
|
|
||||||
};
|
|
||||||
let dac = device.open()?;
|
|
||||||
Ok(Self { conf: (*conf).clone(), dac })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Device for HeliosDevice {
|
impl Device for HeliosDevice {
|
||||||
@ -41,20 +35,4 @@ impl Device for HeliosDevice {
|
|||||||
properties: vec!["foo".to_string()],
|
properties: vec!["foo".to_string()],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self,
|
|
||||||
line: Vec<Point>,
|
|
||||||
speed: u32,
|
|
||||||
) -> 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(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop(&mut self) -> LJResult<()> {
|
|
||||||
self.dac.stop()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
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<()> ;
|
|
||||||
fn stop(&mut self) -> LJResult<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
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!(),
|
|
||||||
};
|
|
||||||
Ok(device)
|
|
||||||
}
|
|
@ -1,7 +1,4 @@
|
|||||||
/*
|
|
||||||
pub mod redis_ctrl;
|
|
||||||
pub mod conf;
|
pub mod conf;
|
||||||
|
pub mod redis_ctrl;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod device;
|
pub mod device;
|
||||||
pub mod point;
|
|
||||||
*/
|
|
||||||
|
69
src/main.rs
69
src/main.rs
@ -9,18 +9,29 @@ mod point;
|
|||||||
mod transformer;
|
mod transformer;
|
||||||
mod device;
|
mod device;
|
||||||
|
|
||||||
use device::device_factory;
|
use helios_dac::{
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
self,
|
||||||
use std::sync::Arc;
|
NativeHeliosDacController,
|
||||||
|
NativeHeliosDac,
|
||||||
|
DeviceStatus,
|
||||||
|
Frame,
|
||||||
|
};
|
||||||
|
use std::sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc
|
||||||
|
};
|
||||||
use redis_ctrl::{RedisCtrl, Order};
|
use redis_ctrl::{RedisCtrl, Order};
|
||||||
use conf::Conf;
|
|
||||||
use errors::LJResult;
|
|
||||||
use point::Point;
|
|
||||||
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;
|
||||||
|
|
||||||
|
use conf::Conf;
|
||||||
|
use errors::{LJError, LJResult};
|
||||||
|
use point::Point;
|
||||||
|
use device::device_factory;
|
||||||
|
use transformer::{Transformers,Translate,Replicate};
|
||||||
|
|
||||||
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
||||||
|
const CENTER: (f32, f32) = (2000.0, 2000.0);
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
match run_all() {
|
match run_all() {
|
||||||
@ -32,7 +43,6 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_all() -> LJResult<()> {
|
fn run_all() -> LJResult<()> {
|
||||||
// Setup configuration file and set up logs
|
|
||||||
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()
|
||||||
});
|
});
|
||||||
@ -42,43 +52,37 @@ fn run_all() -> LJResult<()> {
|
|||||||
let config = config?;
|
let config = config?;
|
||||||
info!("*** Starting up ***");
|
info!("*** Starting up ***");
|
||||||
|
|
||||||
info!("{:?}", config);
|
|
||||||
|
|
||||||
// Setup Redis Service
|
|
||||||
let mut rs = RedisCtrl::new(&config.redis_url)?;
|
let mut rs = RedisCtrl::new(&config.redis_url)?;
|
||||||
|
|
||||||
// Setup handler for interrupt Signals
|
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
let r = running.clone();
|
let r = running.clone();
|
||||||
ctrlc::set_handler(move || {
|
ctrlc::set_handler(move || {
|
||||||
r.store(false, Ordering::SeqCst);
|
r.store(false, Ordering::SeqCst);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Setup Laser Device based on conf
|
let mut device = get_helios_device()?;
|
||||||
let mut tracer = device_factory(&config)?;
|
|
||||||
|
|
||||||
// can't work, but we can add + Debug to Device to make it work...
|
let transformers: Vec<Box<dyn Transformers>> = vec![
|
||||||
//dbg!(tracer);
|
Box::new(Translate::new(CENTER.0, CENTER.1)),
|
||||||
|
Box::new(Replicate::Until(48)),
|
||||||
|
];
|
||||||
|
|
||||||
// Setup geometry transformers on points lists
|
|
||||||
let transformers = config.get_transformers();
|
|
||||||
|
|
||||||
// Dispatch based on redis requests
|
|
||||||
while running.load(Ordering::SeqCst) {
|
while running.load(Ordering::SeqCst) {
|
||||||
|
|
||||||
let order = rs.get_order(config.laser_id)?;
|
let order = rs.get_order(config.laser_id)?;
|
||||||
if order != Order::Draw {
|
if order != Order::Draw {
|
||||||
info!("Order: {:?}", order);
|
info!("Order: {:?}", order);
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame = get_next_frame(&config, &transformers,
|
let frame = get_next_frame(&config, 1000, &transformers,
|
||||||
&mut rs, order == Order::Black)?;
|
&mut rs, order == Order::Black)?;
|
||||||
|
|
||||||
// For now, draw all the time
|
while let Ok(DeviceStatus::NotReady) = device.status() {}
|
||||||
tracer.draw(frame, 1000)?;
|
device.write_frame(frame)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Exiting, stoping device.");
|
info!("Exiting, stoping device.");
|
||||||
tracer.stop()?;
|
device.stop()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,12 +101,23 @@ fn init_logging(config: &LJResult<Conf>) {
|
|||||||
env_logger::init();
|
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(
|
fn get_next_frame(
|
||||||
config: &Conf,
|
config: &Conf,
|
||||||
|
speed: u32,
|
||||||
transformers: &[Box<dyn Transformers>],
|
transformers: &[Box<dyn Transformers>],
|
||||||
rs: &mut RedisCtrl,
|
rs: &mut RedisCtrl,
|
||||||
_black: bool,
|
_black: bool,
|
||||||
) -> LJResult<Vec<Point>> {
|
) -> LJResult<Frame> {
|
||||||
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
||||||
let mut line: Vec<Point> = line.into_iter().map(|tpl| tpl.into()).collect();
|
let mut line: Vec<Point> = line.into_iter().map(|tpl| tpl.into()).collect();
|
||||||
for transformer in transformers {
|
for transformer in transformers {
|
||||||
@ -110,5 +125,7 @@ fn get_next_frame(
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Line: {:?}", line);
|
info!("Line: {:?}", line);
|
||||||
Ok(line)
|
|
||||||
|
let line2: Vec<helios_dac::Point> = line.into_iter().map(|p| p.into()).collect();
|
||||||
|
Ok(Frame::new(speed, line2))
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
use crate::Transformers;
|
use crate::Transformers;
|
||||||
use crate::point::Point;
|
use crate::point::Point;
|
||||||
use serde::{Serialize,Deserialize};
|
|
||||||
|
|
||||||
/// Replicate
|
/// Replicate
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
#[derive(Debug,Clone,Copy)]
|
||||||
pub enum Replicate {
|
pub enum Replicate {
|
||||||
Until(usize),
|
Until(usize),
|
||||||
Times(usize)
|
Times(usize)
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
use crate::Transformers;
|
use crate::Transformers;
|
||||||
use crate::point::Point;
|
use crate::point::Point;
|
||||||
use serde::{Serialize,Deserialize};
|
|
||||||
|
|
||||||
/// Translate
|
/// Translate
|
||||||
|
|
||||||
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
|
#[derive(Debug,Clone,Copy)]
|
||||||
pub struct Translate {
|
pub struct Translate {
|
||||||
x: f32,
|
x: f32,
|
||||||
y: f32
|
y: f32
|
||||||
|
Loading…
Reference in New Issue
Block a user