diff --git a/copyme.Settings.toml b/copyme.Settings.toml index c9c3513..5296d56 100644 --- a/copyme.Settings.toml +++ b/copyme.Settings.toml @@ -1,4 +1,4 @@ -laser_id = 1 +laser_id = 0 debug = "true" redis_url = "127.0.0.1" dac_family = "Helios" diff --git a/src/conf.rs b/src/conf.rs index 871d044..7cbf585 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -10,7 +10,7 @@ pub enum DacFamily { } #[derive(Deserialize,Debug)] -pub struct Conf{ +pub struct Conf { laser_id : u8, debug : bool, redis_url : String, @@ -21,27 +21,12 @@ pub struct Conf{ pub fn load_config( path : &str )-> Result> { - - let conf_builder = Config::builder() - .add_source(config::File::with_name(path)); - - - let settings = match conf_builder.build() { - Ok(conf) => conf, - Err(err) => { - println!("Invalid configuration file / missing file: {:?}", err); - return Err(Box::new(err)) - } - }; + let settings = Config::builder() + .add_source(config::File::with_name(path)) + .build()?; let conf = settings .try_deserialize::()?; - // .try_deserialize::>()?; - - println!( - "{:?}", - conf - ); - + Ok(conf) -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index b5ae005..e1a22a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,31 +16,46 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use redis_ctrl::{RedisCtrl,Order}; -use conf::{load_config}; +use conf::{load_config,Conf}; const CENTER : (u16,u16) = (2000, 2000); -pub fn main() -> Result<(), Box> { +pub fn main() { - let config = load_config("Settings")?; + let config = match load_config("Settings") { + Ok(c) => c, + Err(err) => { + panic!("Unable to load config file: {:?}", err) + } + }; + let rs = match RedisCtrl::new() { + Ok(rs) => rs, + Err(err) => { + panic!("Unable to connect to redis: {:?}", err); + } + }; + + match run_dac(config, rs) { + Ok(()) => {}, + Err(err) => { + panic!("Error: {:?}", err) + } + } +} + +fn run_dac( + config: Conf, + mut rs: RedisCtrl +) -> Result<(), Box> { let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); ctrlc::set_handler(move || { r.store(false, Ordering::SeqCst); }).expect("Error setting Ctrl-C handler"); - - let mut rs = match RedisCtrl::new() { - Ok(rs) => rs, - Err(err) => { - println!("Unable to connect to redis: {:?}", err); - return Ok(()) - } - }; - let controller = NativeHeliosDacController::new()?; let devices = controller.list_devices()?;