From 46a0db5474e438a6b5d73e1b7bb2df90a35f414b Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Sat, 25 Jul 2020 23:28:00 +0200 Subject: [PATCH] add button checking for next scan --- src/main.rs | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 688bef2..cfc3ccd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,6 +225,9 @@ impl Descriptor { fn size(&self) -> SANE_Int { unsafe { (*self.0).size } } + fn cap(&self) -> SANE_Word { + unsafe { (*self.0).cap } + } } #[derive(Debug, Clone)] @@ -386,6 +389,26 @@ impl Opt { let range = unsafe { *(*self.descriptor.0).constraint.range }; Ok(Range(range)) } + fn get_bool(&self) -> Result { + assert_eq!(self.descriptor.type_(), SANE_Value_Type_SANE_TYPE_BOOL); + assert_eq!( + self.descriptor.size(), + std::mem::size_of::() as _ + ); + let mut val = 0; + unsafe { + checked(|| { + sane_control_option( + *self.handle, + self.index as i32, + SANE_Action_SANE_ACTION_GET_VALUE, + &mut val as *mut _ as _, + std::ptr::null_mut(), + ) + })?; + } + Ok(val == SANE_TRUE) + } } #[derive(Debug, Copy, Clone)] @@ -542,6 +565,8 @@ fn main() { device.open().unwrap() }; + let mut scanbutton = None; + println!("Options:"); for option in handle.options() { let optname = option.name(); @@ -583,7 +608,7 @@ fn main() { active_resolution ); } else { - option.set_int(&mut 300).unwrap(); + // option.set_int(&mut 300).unwrap(); let active_resolution = option.get_int().unwrap(); let resolutions = option.int_constraints().unwrap(); print!("\t\t"); @@ -600,6 +625,9 @@ fn main() { "test-picture" => { option.set_string("Color pattern"); } + "scan" | "bool-soft-detect" => { + scanbutton = Some(option); + } _ => {} } } @@ -607,8 +635,13 @@ fn main() { if let Some(dir) = cliopts.dir.as_ref() { let dir = std::path::Path::new(dir); std::fs::create_dir_all(&dir).unwrap(); - loop { - // Check button + let scanbutton = scanbutton.unwrap(); + 'image_loop: loop { + 'button_loop: loop { + if scanbutton.get_bool().unwrap() { + break 'button_loop; + } + } let acq = handle.start().unwrap(); let image = acq.get_image().unwrap();