Compare commits
3 Commits
8932f1f341
...
f092f93afa
Author | SHA1 | Date |
---|---|---|
Valentin Anger | f092f93afa | |
Valentin Anger | 01f35567f3 | |
Valentin Anger | 2272d6bcdf |
|
@ -70,9 +70,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
}).expect("Failed to find the FIRE");
|
}).expect("Failed to find the FIRE");
|
||||||
|
|
||||||
let mut handle = dev.open().expect("Failed to access the FIRE");
|
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
|
||||||
handle.claim_interface(1).unwrap();
|
let fires = flfire::get_fires(&cont);
|
||||||
|
let mut handles = flfire::claim_fires(&fires[0..1]);
|
||||||
|
let handle = &mut handles[0];
|
||||||
|
|
||||||
// Clear all LEDS
|
// Clear all LEDS
|
||||||
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();
|
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -12,25 +12,12 @@ const TO: Duration = Duration::from_millis(50);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
|
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
|
||||||
let devs = cont.devices().expect("Failed to get connected devices");
|
let fires = flfire::get_fires(&cont);
|
||||||
|
let mut handles = flfire::claim_fires(&fires[0..1]);
|
||||||
let dev = devs.iter().find(|d| {
|
let handle = &mut handles[0];
|
||||||
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 (x_dim, y_dim, image) = flfire::read_pbm("/tmp/test.pbm");
|
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();
|
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();
|
||||||
|
|
||||||
let clear_buf = [
|
let clear_buf = [
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
||||||
|
|
||||||
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
|
let cont = libusb::Context::new().expect("Failed to initialize a libusb context");
|
||||||
let fires = flfire::get_fires(&cont);
|
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];
|
let handle = &mut handles[0];
|
||||||
|
|
||||||
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();
|
handle.write_bulk(1, &[0x0b,0xb0,0x7f,0], TO).unwrap();
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -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>> {
|
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<_>>();
|
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
|
handles
|
||||||
}
|
}
|
||||||
|
@ -32,7 +35,15 @@ pub fn get_input(fires: &[libusb::DeviceHandle], timeout: std::time::Duration) -
|
||||||
let mut res = Vec::with_capacity(fires.len());
|
let mut res = Vec::with_capacity(fires.len());
|
||||||
for h in fires.iter() {
|
for h in fires.iter() {
|
||||||
let mut buf = [0u8; INPUT_BLOCKS*4];
|
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);
|
res.push(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue