2023-06-01 21:11:40 +00:00
|
|
|
///
|
|
|
|
/// Configure udev:
|
|
|
|
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
|
|
|
///
|
2023-06-03 13:21:36 +00:00
|
|
|
mod redis_ctrl;
|
2023-06-03 15:52:29 +00:00
|
|
|
mod conf;
|
2023-06-04 09:28:43 +00:00
|
|
|
mod errors;
|
2023-06-04 19:31:32 +00:00
|
|
|
mod point;
|
2023-06-04 19:42:55 +00:00
|
|
|
mod modifier;
|
2023-06-03 13:21:36 +00:00
|
|
|
|
2023-06-03 16:54:41 +00:00
|
|
|
use helios_dac::{
|
2023-06-04 19:31:32 +00:00
|
|
|
self,
|
2023-06-04 10:02:41 +00:00
|
|
|
NativeHeliosDacController,
|
|
|
|
NativeHeliosDac,
|
2023-06-03 16:54:41 +00:00
|
|
|
DeviceStatus,
|
|
|
|
Frame,
|
|
|
|
};
|
2023-06-03 13:21:36 +00:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
use std::sync::Arc;
|
2023-06-03 14:20:35 +00:00
|
|
|
use redis_ctrl::{RedisCtrl,Order};
|
2023-06-04 10:08:44 +00:00
|
|
|
use conf::Conf;
|
2023-06-04 13:09:15 +00:00
|
|
|
use errors::{LJError,LJResult};
|
2023-06-04 19:31:32 +00:00
|
|
|
use point::Point;
|
2023-06-04 19:42:55 +00:00
|
|
|
use modifier::{Transformers,Translate};
|
2023-06-01 21:11:40 +00:00
|
|
|
|
2023-06-04 19:42:55 +00:00
|
|
|
const CENTER : (f32,f32) = (2000.0, 2000.0);
|
2023-06-01 21:11:40 +00:00
|
|
|
|
2023-06-03 16:11:55 +00:00
|
|
|
pub fn main() {
|
2023-06-04 09:28:43 +00:00
|
|
|
match run_all() {
|
2023-06-03 16:11:55 +00:00
|
|
|
Ok(()) => {},
|
|
|
|
Err(err) => {
|
2023-06-04 09:28:43 +00:00
|
|
|
println!("Error: {}", err);
|
2023-06-03 16:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 13:09:15 +00:00
|
|
|
fn run_all() -> LJResult<()> {
|
2023-06-04 09:28:43 +00:00
|
|
|
let Some(filename) = std::env::args().nth(1) else {
|
|
|
|
return Err(Box::new(LJError::ConfigFileMissing));
|
2023-06-04 09:50:05 +00:00
|
|
|
};
|
2023-06-04 10:08:44 +00:00
|
|
|
let config = Conf::new(&filename)?;
|
2023-06-04 13:03:09 +00:00
|
|
|
let mut rs = RedisCtrl::new(&config.redis_url)?;
|
2023-06-04 09:28:43 +00:00
|
|
|
|
2023-06-03 13:21:36 +00:00
|
|
|
let running = Arc::new(AtomicBool::new(true));
|
|
|
|
let r = running.clone();
|
|
|
|
ctrlc::set_handler(move || {
|
|
|
|
r.store(false, Ordering::SeqCst);
|
2023-06-04 09:28:43 +00:00
|
|
|
})?;
|
2023-06-03 14:36:06 +00:00
|
|
|
|
2023-06-04 10:02:41 +00:00
|
|
|
let mut device = get_helios_device()?;
|
2023-06-01 21:11:40 +00:00
|
|
|
|
2023-06-03 14:20:35 +00:00
|
|
|
while running.load(Ordering::SeqCst) {
|
2023-06-04 09:50:05 +00:00
|
|
|
let order = rs.get_order(config.laser_id)?;
|
2023-06-03 14:20:35 +00:00
|
|
|
if order != Order::Draw {
|
|
|
|
println!("{:?}", order);
|
|
|
|
}
|
|
|
|
|
2023-06-04 09:50:05 +00:00
|
|
|
let frame = get_next_frame(&config, 1000,
|
|
|
|
&mut rs, order == Order::Black)?;
|
2023-06-03 13:21:36 +00:00
|
|
|
|
2023-06-01 21:11:40 +00:00
|
|
|
while let Ok(DeviceStatus::NotReady) = device.status() {
|
|
|
|
}
|
|
|
|
device.write_frame(frame)?;
|
|
|
|
}
|
2023-06-03 13:21:36 +00:00
|
|
|
|
|
|
|
println!("Exiting, stoping device.");
|
2023-06-01 21:11:40 +00:00
|
|
|
device.stop()?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-06-04 13:09:15 +00:00
|
|
|
fn get_helios_device() -> LJResult<NativeHeliosDac> {
|
2023-06-04 10:02:41 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-06-01 21:11:40 +00:00
|
|
|
fn get_next_frame(
|
2023-06-04 09:50:05 +00:00
|
|
|
config: &Conf,
|
2023-06-01 21:11:40 +00:00
|
|
|
speed: u32,
|
2023-06-04 09:28:43 +00:00
|
|
|
rs: &mut RedisCtrl,
|
2023-06-04 09:50:05 +00:00
|
|
|
_black: bool
|
2023-06-04 13:09:15 +00:00
|
|
|
) -> LJResult<Frame> {
|
2023-06-04 09:28:43 +00:00
|
|
|
|
2023-06-04 09:50:05 +00:00
|
|
|
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
2023-06-04 19:42:55 +00:00
|
|
|
let line: Vec<Point> = line.into_iter().map(| tpl | tpl.into()).collect();
|
|
|
|
let line = Translate::new(CENTER.0, CENTER.1).apply(&line);
|
|
|
|
|
2023-06-01 21:11:40 +00:00
|
|
|
let mut line2 = vec![];
|
|
|
|
while line2.len() < 48 {
|
2023-06-03 16:54:41 +00:00
|
|
|
for p in &line {
|
|
|
|
line2.push(*p);
|
|
|
|
}
|
2023-06-01 21:11:40 +00:00
|
|
|
}
|
2023-06-03 16:54:41 +00:00
|
|
|
|
2023-06-04 09:28:43 +00:00
|
|
|
println!("{:?}", line2);
|
2023-06-01 21:11:40 +00:00
|
|
|
|
2023-06-04 19:42:55 +00:00
|
|
|
let line2 : Vec<helios_dac::Point> = line2.into_iter().map(| p | p.into()).collect();
|
|
|
|
Ok(Frame::new(speed, line2))
|
2023-06-01 21:11:40 +00:00
|
|
|
}
|