diff --git a/Cargo.toml b/Cargo.toml index 59a399b..2814a1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" sane-sys = { path = "sane-sys" } image = "0.23.7" gumdrop = "0.8.0" +ctrlc = "3.1.5" [workspace] members = [ diff --git a/src/main.rs b/src/main.rs index cfc3ccd..1d149a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -456,7 +456,6 @@ impl<'a> Acquisition<'a> { return Err(err); } } - // std::thread::sleep(std::time::Duration::from_millis(100)); } } assert_eq!(buffer.len(), 0); @@ -476,7 +475,6 @@ impl<'a> Acquisition<'a> { }; let mut image = vec![0_u8; bytesize as _]; - // unsafe { checked(|| sane_set_io_mode(self.handle.0, SANE_FALSE as _))? }; #[allow(non_upper_case_globals)] match parameters.format() { SANE_Frame_SANE_FRAME_GRAY => self.read_image(&mut image[..])?, @@ -636,8 +634,19 @@ fn main() { let dir = std::path::Path::new(dir); std::fs::create_dir_all(&dir).unwrap(); let scanbutton = scanbutton.unwrap(); + let shouldstop = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); + let stop = shouldstop.clone(); + ctrlc::set_handler(move || { + shouldstop.store(true, std::sync::atomic::Ordering::SeqCst); + }) + .unwrap(); + 'image_loop: loop { + println!("Scan by pushing scan, or interrupt with ctrl-c"); 'button_loop: loop { + if stop.load(std::sync::atomic::Ordering::SeqCst) { + break 'image_loop; + } if scanbutton.get_bool().unwrap() { break 'button_loop; }