lj_qualibration/src/main.rs

127 lines
3.3 KiB
Rust
Raw Normal View History

///
/// 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;
mod utils;
use qualibration::{annalyse::adding_trackbar, Qualibration};
use conf::Conf;
use log::{/*debug, warn, */ error, info};
use logs::init_logging;
use point::{Color, Point};
use redis::{Client, Commands, Connection};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use opencv::highgui;
use opencv::Result;
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) {
//let _t = framerate_handler.handle_time()?;
/////////////////
let key = highgui::wait_key(1)?;
2023-09-14 19:11:01 +00:00
//if key != -1 {
qualibration.key = key;
2023-09-14 19:11:01 +00:00
//}
if key == 27 {
// esc in my case
break;
}
//qualibration.id = next_id;
let v: Vec<(f32, f32, u32)> = qualibration
.draw_sequence()?
.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),
)?;
qualibration.run_step()?;
if qualibration.capture_mode {
let millis = std::time::Duration::from_millis(1000); // TODO: find solution to know when change has been done
std::thread::sleep(millis);
}
}
let _ = con.set(
format!("/pl/{}/{}", config.client_id, config.laser_id),
format!("[]"),
)?;
Ok(())
}