2023-09-12 21:35:29 +00:00
|
|
|
///
|
|
|
|
/// Configure udev:
|
|
|
|
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
|
|
|
///
|
|
|
|
mod conf;
|
|
|
|
mod draw;
|
|
|
|
mod framerate;
|
|
|
|
mod logs;
|
|
|
|
mod point;
|
|
|
|
|
|
|
|
mod qualibration;
|
2023-09-14 18:29:34 +00:00
|
|
|
mod utils;
|
2023-09-12 21:35:29 +00:00
|
|
|
|
2023-09-14 18:29:34 +00:00
|
|
|
use qualibration::{annalyse::adding_trackbar, Qualibration};
|
2023-09-12 21:35:29 +00:00
|
|
|
|
|
|
|
use conf::Conf;
|
|
|
|
use log::{/*debug, warn, */ error, info};
|
|
|
|
use logs::init_logging;
|
|
|
|
use point::{Color, Point};
|
|
|
|
use redis::{Client, Commands, Connection};
|
2023-09-14 18:29:34 +00:00
|
|
|
use std::sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc,
|
|
|
|
};
|
2023-09-12 21:35:29 +00:00
|
|
|
|
|
|
|
use opencv::highgui;
|
2023-09-14 18:29:34 +00:00
|
|
|
use opencv::Result;
|
2023-09-12 21:35:29 +00:00
|
|
|
|
|
|
|
opencv::opencv_branch_4! {
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use opencv::imgproc::LINE_AA;
|
|
|
|
}
|
|
|
|
opencv::not_opencv_branch_4! {
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
use opencv::core::LINE_AA;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
match run_all() {
|
|
|
|
Ok(()) => {}
|
|
|
|
Err(err) => {
|
|
|
|
error!("Error: {}", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_all() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
// Setup configuration file and set up logs
|
|
|
|
let filename = DEFAULT_CONF_FILE.to_string();
|
|
|
|
let config = Conf::new(&filename);
|
|
|
|
init_logging(&config);
|
|
|
|
let config = config?;
|
|
|
|
let conf2 = config.clone();
|
|
|
|
|
|
|
|
let client = Client::open(config.redis_url.clone())?;
|
|
|
|
let mut con: Connection = client.get_connection()?;
|
|
|
|
|
|
|
|
let mut framerate_handler = framerate::Framerate::new(config.framerate)?;
|
|
|
|
|
|
|
|
// Setup handler for interrupt Signals
|
|
|
|
let running = Arc::new(AtomicBool::new(true));
|
|
|
|
let r = running.clone();
|
|
|
|
ctrlc::set_handler(move || {
|
|
|
|
let client = Client::open(conf2.redis_url.clone()).unwrap();
|
|
|
|
let mut con: Connection = client.get_connection().unwrap();
|
|
|
|
let _a: () = con
|
|
|
|
.set(
|
|
|
|
format!("/pl/{}/{}", conf2.client_id, conf2.laser_id),
|
|
|
|
format!("[]"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
r.store(false, Ordering::SeqCst);
|
|
|
|
})?;
|
|
|
|
|
|
|
|
info!("*** Starting up ***");
|
|
|
|
info!("{:?}", config);
|
|
|
|
|
|
|
|
let mut qualibration = Qualibration::new()?;
|
|
|
|
adding_trackbar(&mut qualibration, "histogram: 0")?;
|
|
|
|
|
|
|
|
let _a: () = con.set(format!("/kpps/{}", conf2.laser_id), 65535)?;
|
|
|
|
let _a: () = con.set(
|
|
|
|
format!("/order/{}", conf2.laser_id),
|
|
|
|
7, // order to change kpps
|
|
|
|
)?;
|
|
|
|
|
|
|
|
while running.load(Ordering::SeqCst) {
|
2023-09-14 18:29:34 +00:00
|
|
|
//let _t = framerate_handler.handle_time()?;
|
2023-09-12 21:35:29 +00:00
|
|
|
/////////////////
|
|
|
|
let key = highgui::wait_key(1)?;
|
2023-09-14 19:11:01 +00:00
|
|
|
//if key != -1 {
|
2023-09-12 21:35:29 +00:00
|
|
|
qualibration.key = key;
|
2023-09-14 19:11:01 +00:00
|
|
|
//}
|
2023-09-14 18:29:34 +00:00
|
|
|
if key == 27 {
|
|
|
|
// esc in my case
|
2023-09-12 21:35:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-09-14 18:29:34 +00:00
|
|
|
//qualibration.id = next_id;
|
|
|
|
let v: Vec<(f32, f32, u32)> = qualibration
|
|
|
|
.draw_sequence()?
|
2023-09-12 21:35:29 +00:00
|
|
|
.iter()
|
|
|
|
.map(|pt| (pt.x, pt.y, u32::from(pt.color)))
|
|
|
|
.collect();
|
|
|
|
// println!("{:?}", v);
|
|
|
|
let _ = con.set(
|
|
|
|
format!("/pl/{}/{}", config.client_id, config.laser_id),
|
|
|
|
format!("{:?}", v),
|
|
|
|
)?;
|
|
|
|
|
2023-09-14 18:29:34 +00:00
|
|
|
qualibration.run_step()?;
|
|
|
|
|
2023-09-12 21:35:29 +00:00
|
|
|
if qualibration.capture_mode {
|
2023-09-14 18:29:34 +00:00
|
|
|
let millis = std::time::Duration::from_millis(1000); // TODO: find solution to know when change has been done
|
2023-09-12 21:35:29 +00:00
|
|
|
std::thread::sleep(millis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let _ = con.set(
|
|
|
|
format!("/pl/{}/{}", config.client_id, config.laser_id),
|
|
|
|
format!("[]"),
|
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|