124 lines
3.3 KiB
Rust
124 lines
3.3 KiB
Rust
|
///
|
||
|
/// 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 utils;
|
||
|
mod qualibration;
|
||
|
|
||
|
use qualibration::{Qualibration, annalyse::adding_trackbar};
|
||
|
|
||
|
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::{Arc, atomic::{AtomicBool, Ordering}};
|
||
|
|
||
|
|
||
|
use opencv::Result;
|
||
|
use opencv::highgui;
|
||
|
|
||
|
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()?;
|
||
|
/////////////////
|
||
|
qualibration.run_step()?;
|
||
|
let key = highgui::wait_key(1)?;
|
||
|
if key != -1 {
|
||
|
qualibration.key = key;
|
||
|
}
|
||
|
if key == 27 { // esc in my case
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
let points_list: Vec<Point> = qualibration.draw_sequence()?; //draw::draw(_t)?;
|
||
|
//qualibration.id = next_id;
|
||
|
let v: Vec<(f32, f32, u32)> = points_list
|
||
|
.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),
|
||
|
)?;
|
||
|
|
||
|
if qualibration.capture_mode {
|
||
|
let millis = std::time::Duration::from_millis(300); // 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(())
|
||
|
}
|