Compare commits

...

3 Commits

4 changed files with 22 additions and 22 deletions

View File

@ -70,9 +70,11 @@ fn main() {
}
}).expect("Failed to find the FIRE");
let mut handle = dev.open().expect("Failed to access the FIRE");
handle.claim_interface(1).unwrap();
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
let fires = flfire::get_fires(&cont);
let mut handles = flfire::claim_fires(&fires[0..1]);
let handle = &mut handles[0];
// Clear all LEDS
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();

View File

@ -12,25 +12,12 @@ const TO: Duration = Duration::from_millis(50);
fn main() {
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
let devs = cont.devices().expect("Failed to get connected devices");
let dev = devs.iter().find(|d| {
if let Ok(desc) = d.device_descriptor() {
if desc.vendor_id() == FIRE_VENDOR && desc.product_id() == FIRE_PRODUCT {
true
} else {
false
}
} else {
false
}
}).expect("Failed to find the FIRE");
let fires = flfire::get_fires(&cont);
let mut handles = flfire::claim_fires(&fires[0..1]);
let handle = &mut handles[0];
let (x_dim, y_dim, image) = flfire::read_pbm("/tmp/test.pbm");
let mut handle = dev.open().expect("Failed to access the FIRE");
handle.claim_interface(1).unwrap();
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();
let clear_buf = [

View File

@ -11,7 +11,7 @@ fn main() {
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
let fires = flfire::get_fires(&cont);
let mut handles = flfire::claim_fires(&fires);
let mut handles = flfire::claim_fires(&fires[0..1]);
let handle = &mut handles[0];
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();

View File

@ -21,7 +21,10 @@ pub fn get_fires<'a>(context: &libusb::Context) -> Vec<libusb::Device> {
pub fn claim_fires<'a>(fires: &'a [libusb::Device]) -> Vec<libusb::DeviceHandle<'a>> {
let mut handles = fires.iter().map(|dev| dev.open().expect("Failed to access a FIRE")).collect::<Vec<_>>();
handles.iter_mut().for_each(|h| h.claim_interface(1).expect("Failed to claim a FIRE"));
handles.iter_mut().for_each(|h| {
let _ = h.detach_kernel_driver(1); // Allowed to fail due to for example no attached kernel driver
h.claim_interface(1).expect("Failed to claim a FIRE");
});
handles
}
@ -32,7 +35,15 @@ pub fn get_input(fires: &[libusb::DeviceHandle], timeout: std::time::Duration) -
let mut res = Vec::with_capacity(fires.len());
for h in fires.iter() {
let mut buf = [0u8; INPUT_BLOCKS*4];
let _ = h.read_bulk(0x81, &mut buf, timeout).expect("Failed to read a FIRE");
match h.read_bulk(0x81, &mut buf, timeout) {
Ok(_) => {},
Err(e) => {
match e {
libusb::Error::Timeout => {},
_ => panic!("Failed to read FIRE {}", e),
}
},
}
res.push(buf);
}