add button checking for next scan

This commit is contained in:
Magnus Ulimoen 2020-07-25 23:28:00 +02:00
parent 56aa9635c3
commit 46a0db5474
1 changed files with 36 additions and 3 deletions

View File

@ -225,6 +225,9 @@ impl Descriptor {
fn size(&self) -> SANE_Int { fn size(&self) -> SANE_Int {
unsafe { (*self.0).size } unsafe { (*self.0).size }
} }
fn cap(&self) -> SANE_Word {
unsafe { (*self.0).cap }
}
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -386,6 +389,26 @@ impl Opt {
let range = unsafe { *(*self.descriptor.0).constraint.range }; let range = unsafe { *(*self.descriptor.0).constraint.range };
Ok(Range(range)) Ok(Range(range))
} }
fn get_bool(&self) -> Result<bool, Error> {
assert_eq!(self.descriptor.type_(), SANE_Value_Type_SANE_TYPE_BOOL);
assert_eq!(
self.descriptor.size(),
std::mem::size_of::<SANE_Bool>() 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)] #[derive(Debug, Copy, Clone)]
@ -542,6 +565,8 @@ fn main() {
device.open().unwrap() device.open().unwrap()
}; };
let mut scanbutton = None;
println!("Options:"); println!("Options:");
for option in handle.options() { for option in handle.options() {
let optname = option.name(); let optname = option.name();
@ -583,7 +608,7 @@ fn main() {
active_resolution active_resolution
); );
} else { } else {
option.set_int(&mut 300).unwrap(); // option.set_int(&mut 300).unwrap();
let active_resolution = option.get_int().unwrap(); let active_resolution = option.get_int().unwrap();
let resolutions = option.int_constraints().unwrap(); let resolutions = option.int_constraints().unwrap();
print!("\t\t"); print!("\t\t");
@ -600,6 +625,9 @@ fn main() {
"test-picture" => { "test-picture" => {
option.set_string("Color pattern"); 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() { if let Some(dir) = cliopts.dir.as_ref() {
let dir = std::path::Path::new(dir); let dir = std::path::Path::new(dir);
std::fs::create_dir_all(&dir).unwrap(); std::fs::create_dir_all(&dir).unwrap();
loop { let scanbutton = scanbutton.unwrap();
// Check button 'image_loop: loop {
'button_loop: loop {
if scanbutton.get_bool().unwrap() {
break 'button_loop;
}
}
let acq = handle.start().unwrap(); let acq = handle.start().unwrap();
let image = acq.get_image().unwrap(); let image = acq.get_image().unwrap();