more errors refactoring
This commit is contained in:
parent
c18de96e10
commit
49830795e6
@ -5,7 +5,8 @@ use redis::RedisError;
|
||||
#[derive(Debug)]
|
||||
pub enum LJError {
|
||||
ConfigFileMissing,
|
||||
RedisConnect(RedisError)
|
||||
RedisConnect(RedisError),
|
||||
HeliosDeviceMissing
|
||||
}
|
||||
|
||||
impl fmt::Display for LJError {
|
||||
@ -19,6 +20,9 @@ impl fmt::Display for LJError {
|
||||
},
|
||||
RedisConnect(err) => {
|
||||
write!(f, "unable to connect to redis server: {err}")
|
||||
},
|
||||
HeliosDeviceMissing => {
|
||||
write!(f, "helios device not found")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,8 +33,8 @@ impl Error for LJError {
|
||||
use LJError::*;
|
||||
|
||||
match self {
|
||||
ConfigFileMissing => None,
|
||||
RedisConnect(err) => Some(err)
|
||||
RedisConnect(err) => Some(err),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
33
src/main.rs
33
src/main.rs
@ -6,8 +6,9 @@ mod redis_ctrl;
|
||||
mod conf;
|
||||
mod errors;
|
||||
|
||||
use helios_dac::NativeHeliosDacController;
|
||||
use helios_dac::{
|
||||
NativeHeliosDacController,
|
||||
NativeHeliosDac,
|
||||
// Coordinate,
|
||||
Color,
|
||||
DeviceStatus,
|
||||
@ -36,31 +37,15 @@ fn run_all() -> Result<(), Box<dyn std::error::Error>> {
|
||||
return Err(Box::new(LJError::ConfigFileMissing));
|
||||
};
|
||||
let config = load_config(&filename)?;
|
||||
let rs = RedisCtrl::new()?;
|
||||
let mut rs = RedisCtrl::new()?;
|
||||
|
||||
run_dac(config, rs)
|
||||
}
|
||||
|
||||
fn run_dac(
|
||||
config: Conf,
|
||||
mut rs: RedisCtrl
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let r = running.clone();
|
||||
|
||||
ctrlc::set_handler(move || {
|
||||
r.store(false, Ordering::SeqCst);
|
||||
})?;
|
||||
|
||||
let controller = NativeHeliosDacController::new()?;
|
||||
let devices = controller.list_devices()?;
|
||||
|
||||
let Some(device) = devices.into_iter().next() else {
|
||||
println!("Unable to find an helios device");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let mut device = device.open()?;
|
||||
let mut device = get_helios_device()?;
|
||||
|
||||
while running.load(Ordering::SeqCst) {
|
||||
let order = rs.get_order(config.laser_id)?;
|
||||
@ -81,6 +66,16 @@ fn run_dac(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_helios_device() -> Result<NativeHeliosDac, Box<dyn std::error::Error>> {
|
||||
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)
|
||||
}
|
||||
|
||||
fn get_next_frame(
|
||||
config: &Conf,
|
||||
speed: u32,
|
||||
|
Loading…
Reference in New Issue
Block a user