add test device

This commit is contained in:
Magnus Ulimoen 2020-07-24 20:50:59 +02:00
parent 7bf18a4946
commit e0c5acefb7
1 changed files with 33 additions and 16 deletions

View File

@ -138,6 +138,12 @@ impl Drop for Handle {
} }
impl Handle { impl Handle {
fn from_name(name: &str) -> Result<Self, Error> {
let name = std::ffi::CString::new(name).unwrap();
let mut handle = std::ptr::null_mut();
unsafe { checked(|| sane_open(name.as_ptr(), &mut handle))? };
Ok(Self(handle))
}
fn descriptors(&self) -> impl ExactSizeIterator<Item = Descriptor> + '_ { fn descriptors(&self) -> impl ExactSizeIterator<Item = Descriptor> + '_ {
// Guaranteed to exist // Guaranteed to exist
let first_desc = self.get_descriptor(0).unwrap(); let first_desc = self.get_descriptor(0).unwrap();
@ -346,7 +352,7 @@ impl<'a> Acquisition<'a> {
let mut image = Vec::<u8>::with_capacity(bytesize as _); let mut image = Vec::<u8>::with_capacity(bytesize as _);
let mut len = 0; let mut len = 0;
unsafe { checked(|| sane_set_io_mode(self.handle.0, SANE_FALSE as _))? }; // unsafe { checked(|| sane_set_io_mode(self.handle.0, SANE_FALSE as _))? };
unsafe { unsafe {
'read_loop: loop { 'read_loop: loop {
@ -383,6 +389,8 @@ impl Drop for Acquisition<'_> {
} }
} }
const TESTDEVICE: bool = true;
fn main() { fn main() {
let (context, version) = Context::init().unwrap(); let (context, version) = Context::init().unwrap();
println!( println!(
@ -391,19 +399,23 @@ fn main() {
version.minor(), version.minor(),
version.build() version.build()
); );
let mut chosen_device = None; let handle = if TESTDEVICE {
for device in context.devices(true).unwrap() { Handle::from_name("test").unwrap()
println!("Device:"); } else {
let name = device.name(); let mut chosen_device = None;
println!("\tname: {}", name); for device in context.devices(true).unwrap() {
println!("\tvendor: {}", device.vendor()); println!("Device:");
println!("\tmodel: {}", device.model()); let name = device.name();
println!("\ttype: {}", device.type_()); println!("\tname: {}", name);
chosen_device = Some(device); println!("\tvendor: {}", device.vendor());
} println!("\tmodel: {}", device.model());
println!("\ttype: {}", device.type_());
chosen_device = Some(device);
}
let device = chosen_device.unwrap(); let device = chosen_device.unwrap();
let handle = device.open().unwrap(); device.open().unwrap()
};
println!("Options:"); println!("Options:");
for option in handle.options() { for option in handle.options() {
@ -412,7 +424,9 @@ fn main() {
continue; continue;
} }
println!("\t{}", optname); println!("\t{}", optname);
println!("\t\t{}", option.desc()); for line in option.desc().lines() {
println!("\t\t{}", line);
}
match optname { match optname {
"mode" => { "mode" => {
print!("\t\t"); print!("\t\t");
@ -426,6 +440,9 @@ fn main() {
"depth" => { "depth" => {
println!("\t\tCurrent depth: {}", option.get_int().unwrap()); println!("\t\tCurrent depth: {}", option.get_int().unwrap());
} }
"test-picture" => {
option.set_string("Color pattern");
}
_ => {} _ => {}
} }
} }
@ -433,6 +450,6 @@ fn main() {
let parameters = handle.parameters().unwrap(); let parameters = handle.parameters().unwrap();
println!("{:?}", parameters); println!("{:?}", parameters);
// let acq = handle.start().unwrap(); let acq = handle.start().unwrap();
// let image = acq.get_image().unwrap(); let image = acq.get_image().unwrap();
} }