refacto transformer with module hierarchy
This commit is contained in:
parent
3588e3f4a2
commit
7d7eec6695
@ -1,14 +1,14 @@
|
|||||||
mod common;
|
mod common;
|
||||||
mod helios;
|
mod helios;
|
||||||
|
|
||||||
use crate::conf::{Conf, DacFamily, EtherDreamConf, HeliosConf};
|
use crate::conf::{Conf, DacFamily}; //, EtherDreamConf, HeliosConf};
|
||||||
use crate::device::common::Device;
|
use crate::device::common::Device;
|
||||||
use crate::device::helios::HeliosDevice;
|
use crate::device::helios::HeliosDevice;
|
||||||
|
|
||||||
pub fn device_factory(config: Conf) -> Box<dyn Device> {
|
pub fn device_factory(config: Conf) -> Box<dyn Device> {
|
||||||
let device = match config.dac {
|
let device = match config.dac {
|
||||||
DacFamily::Helios(conf) => Box::new(HeliosDevice { conf }),
|
DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)),
|
||||||
DacFamily::Etherdream( conf) => todo!(),
|
DacFamily::Etherdream(_conf) => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
device
|
device
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/// 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::NativeHeliosDacController;
|
use helios_dac::NativeHeliosDacController;
|
||||||
use helios_dac::{
|
use helios_dac::{
|
||||||
// Coordinate,
|
// Coordinate,
|
||||||
@ -10,6 +11,7 @@ use helios_dac::{
|
|||||||
Frame,
|
Frame,
|
||||||
Point,
|
Point,
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
use crate::conf::HeliosConf;
|
use crate::conf::HeliosConf;
|
||||||
use crate::device::common::{Device, Status};
|
use crate::device::common::{Device, Status};
|
||||||
|
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -9,8 +9,6 @@ mod point;
|
|||||||
mod transformer;
|
mod transformer;
|
||||||
mod device;
|
mod device;
|
||||||
|
|
||||||
use device::device_factory;
|
|
||||||
|
|
||||||
use helios_dac::{
|
use helios_dac::{
|
||||||
self,
|
self,
|
||||||
NativeHeliosDacController,
|
NativeHeliosDacController,
|
||||||
@ -18,15 +16,19 @@ use helios_dac::{
|
|||||||
DeviceStatus,
|
DeviceStatus,
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::{
|
||||||
use std::sync::Arc;
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc
|
||||||
|
};
|
||||||
use redis_ctrl::{RedisCtrl, Order};
|
use redis_ctrl::{RedisCtrl, Order};
|
||||||
|
use log::{LevelFilter, info, /* warn, */ error};
|
||||||
|
use env_logger::Builder;
|
||||||
|
|
||||||
use conf::Conf;
|
use conf::Conf;
|
||||||
use errors::{LJError, LJResult};
|
use errors::{LJError, LJResult};
|
||||||
use point::Point;
|
use point::Point;
|
||||||
|
use device::device_factory;
|
||||||
use transformer::{Transformers,Translate,Replicate};
|
use transformer::{Transformers,Translate,Replicate};
|
||||||
use log::{LevelFilter, info, /* warn, */ error};
|
|
||||||
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);
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
use crate::point::Point;
|
|
||||||
|
|
||||||
pub trait Transformers {
|
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Translate
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy)]
|
|
||||||
pub struct Translate {
|
|
||||||
x: f32,
|
|
||||||
y: f32
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Translate {
|
|
||||||
pub fn new(x: f32, y: f32) -> Self {
|
|
||||||
Self { x, y }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for Translate {
|
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
|
||||||
point_list.iter()
|
|
||||||
.map(| pt | {
|
|
||||||
Point { x: pt.x + self.x,
|
|
||||||
y: pt.y + self.y,
|
|
||||||
..*pt
|
|
||||||
}
|
|
||||||
}).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Replicate
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Debug,Clone,Copy)]
|
|
||||||
pub enum Replicate {
|
|
||||||
Until(usize),
|
|
||||||
Times(usize)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for Replicate {
|
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point> {
|
|
||||||
let mut point_list2 = vec![];
|
|
||||||
match self {
|
|
||||||
Replicate::Until(n) => {
|
|
||||||
while point_list2.len() < *n {
|
|
||||||
point_list2.append(&mut point_list.to_vec());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Replicate::Times(n) => {
|
|
||||||
for _ in 0..*n {
|
|
||||||
point_list2.append(&mut point_list.to_vec());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
point_list2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user