From 8667bd2c92cdf0ab5dbd458734a1f92f4ed9e249 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 29 Nov 2022 15:10:16 +0000 Subject: [PATCH] Cleaned up and replaced the DfuLibusb::open() call with a call to DfuLibusb::from_usb_device() --- src/bmp.rs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/bmp.rs b/src/bmp.rs index 57cc5fe..b53f9a8 100644 --- a/src/bmp.rs +++ b/src/bmp.rs @@ -479,26 +479,11 @@ impl BmpDevice .map_err(|e| e.with_ctx("detaching device for download"))?; } - let device_desc = self.device().device_descriptor() - .expect(libusb_cannot_fail!("libusb_get_device_descriptor")); - let (vid, pid) = (device_desc.vendor_id(), device_desc.product_id()); let load_address = self.platform.load_address(firmware_type); - // HACK: You can't have multiple open handles to the same WinUSB device in the same process, - // and DfuLibusb::open() opens a handle, so we have to drop ours. - if cfg!(windows) { - if let Some(handle) = self.handle.take() { - drop(handle); - } - thread::sleep(Duration::from_millis(250)); - } - - - // FIXME: change to DfuLibusb::from_usb_device() when https://github.com/dfu-rs/dfu-libusb/pull/9 is merged. - let mut dfu_dev = DfuLibusb::open( - self.device().context(), - vid, - pid, + let mut dfu_dev = DfuLibusb::from_usb_device( + self.device().clone(), + self.handle.take().expect("Must have a valid device handle"), 0, 0, )?;