Skip to content

Commit fe81068

Browse files
Remove unused libusb dependency on Windows
1 parent f8ca222 commit fe81068

File tree

4 files changed

+97
-91
lines changed

4 files changed

+97
-91
lines changed

usb/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ categories = ["hardware-support", "api-bindings"]
1010

1111
[dependencies]
1212
goxlr-types = { path = "../types" }
13-
rusb = "0.9.4"
1413
thiserror = "1.0.63"
1514
byteorder = "1.5.0"
1615
log = "0.4.22"
@@ -23,6 +22,10 @@ cfg-if = "1.0.0"
2322
# New, some fun async stuff..
2423
tokio = { version = "1.39.1", features = ["sync", "rt", "time"] }
2524

25+
# Mac an Linux need libusb
26+
[target.'cfg(not(windows))'.dependencies]
27+
rusb = "0.9.4"
28+
2629
# Dependencies specifically for building under Windows..
2730
[target.'cfg(windows)'.dependencies]
2831
winreg = "0.52.0"

usb/src/device/tusb/tusbaudio.rs

Lines changed: 89 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use winreg::RegKey;
2929
use goxlr_types::VersionNumber;
3030

3131
use crate::device::base::GoXLRDevice;
32-
use crate::{PID_GOXLR_FULL, PID_GOXLR_MINI, VID_GOXLR};
3332

3433
// Define the Types of the various methods..
3534
type EnumerateDevices = unsafe extern "C" fn() -> u32;
@@ -659,97 +658,97 @@ impl TUSBAudio<'_> {
659658
Ok(())
660659
}
661660

662-
#[allow(dead_code)]
663-
pub fn spawn_pnp_handle_rusb(&self) -> Result<()> {
664-
// Comment for future me: Use CM_Register_Notification instead of rusb
665-
666-
let mut spawned = self.pnp_thread_running.lock().unwrap();
667-
if *spawned {
668-
bail!("Handler Thread already running..");
669-
}
670-
671-
debug!("Spawning RUSB PnP Thread");
672-
673-
// We should not return from this method until at least one run has been done by the
674-
// thread, this is primarily to prevent conflicts on startup when everything changes.
675-
676-
let (ready_tx, mut ready_rx) = tokio::sync::oneshot::channel::<bool>();
677-
678-
thread::spawn(move || -> Result<()> {
679-
let mut devices = vec![];
680-
let mut ready_sender = Some(ready_tx);
681-
682-
debug!("PnP Thread Spawned");
683-
loop {
684-
let mut found_devices = vec![];
685-
686-
if let Ok(devices) = rusb::devices() {
687-
for device in devices.iter() {
688-
if let Ok(descriptor) = device.device_descriptor() {
689-
let bus_number = device.bus_number();
690-
let address = device.address();
691-
692-
if descriptor.vendor_id() == VID_GOXLR
693-
&& (descriptor.product_id() == PID_GOXLR_FULL
694-
|| descriptor.product_id() == PID_GOXLR_MINI)
695-
{
696-
found_devices.push(USBDevice {
697-
bus_number,
698-
address,
699-
});
700-
}
701-
}
702-
}
703-
} else {
704-
debug!("Unable to Poll Devices");
705-
}
706-
707-
// Make sure our two vecs are the same..
708-
if !iters_equal_anyorder(
709-
devices.clone().into_iter(),
710-
found_devices.clone().into_iter(),
711-
) {
712-
debug!("Device Change Detected");
713-
let _ = TUSB_INTERFACE.detect_devices();
714-
devices.clear();
715-
devices.append(&mut found_devices);
716-
}
717-
718-
// If a driver takes a couple of hundred milliseconds to load, it's theoretically
719-
// possible that we'll have detected the device and run detect_devices() too early
720-
// leaving the detected device list empty and causing a desync in the lists.
721-
//
722-
// The following simply checks what's already been found, and if the list size
723-
// isn't the same as we have detected here, attempts to force a resync of the
724-
// devices from the API.
725-
if devices.len() != TUSB_INTERFACE.get_devices().len() {
726-
debug!("Device Desync Detected, attempting to resync..");
727-
let _ = TUSB_INTERFACE.detect_devices();
728-
}
729-
730-
if let Some(sender) = ready_sender.take() {
731-
let _ = sender.send(true);
732-
}
733-
sleep(Duration::from_secs(1));
734-
}
735-
});
736-
737-
// Block until the 'ready' message has been sent..
738-
while ready_rx.try_recv().is_err() {
739-
sleep(Duration::from_millis(5));
740-
}
741-
debug!("RUSB PnP Handler Started");
742-
743-
*spawned = true;
744-
Ok(())
745-
}
661+
//#[allow(dead_code)]
662+
// pub fn spawn_pnp_handle_rusb(&self) -> Result<()> {
663+
// // Comment for future me: Use CM_Register_Notification instead of rusb
664+
//
665+
// let mut spawned = self.pnp_thread_running.lock().unwrap();
666+
// if *spawned {
667+
// bail!("Handler Thread already running..");
668+
// }
669+
//
670+
// debug!("Spawning RUSB PnP Thread");
671+
//
672+
// // We should not return from this method until at least one run has been done by the
673+
// // thread, this is primarily to prevent conflicts on startup when everything changes.
674+
//
675+
// let (ready_tx, mut ready_rx) = tokio::sync::oneshot::channel::<bool>();
676+
//
677+
// thread::spawn(move || -> Result<()> {
678+
// let mut devices = vec![];
679+
// let mut ready_sender = Some(ready_tx);
680+
//
681+
// debug!("PnP Thread Spawned");
682+
// loop {
683+
// let mut found_devices = vec![];
684+
//
685+
// if let Ok(devices) = rusb::devices() {
686+
// for device in devices.iter() {
687+
// if let Ok(descriptor) = device.device_descriptor() {
688+
// let bus_number = device.bus_number();
689+
// let address = device.address();
690+
//
691+
// if descriptor.vendor_id() == VID_GOXLR
692+
// && (descriptor.product_id() == PID_GOXLR_FULL
693+
// || descriptor.product_id() == PID_GOXLR_MINI)
694+
// {
695+
// found_devices.push(USBDevice {
696+
// bus_number,
697+
// address,
698+
// });
699+
// }
700+
// }
701+
// }
702+
// } else {
703+
// debug!("Unable to Poll Devices");
704+
// }
705+
//
706+
// // Make sure our two vecs are the same..
707+
// if !iters_equal_anyorder(
708+
// devices.clone().into_iter(),
709+
// found_devices.clone().into_iter(),
710+
// ) {
711+
// debug!("Device Change Detected");
712+
// let _ = TUSB_INTERFACE.detect_devices();
713+
// devices.clear();
714+
// devices.append(&mut found_devices);
715+
// }
716+
//
717+
// // If a driver takes a couple of hundred milliseconds to load, it's theoretically
718+
// // possible that we'll have detected the device and run detect_devices() too early
719+
// // leaving the detected device list empty and causing a desync in the lists.
720+
// //
721+
// // The following simply checks what's already been found, and if the list size
722+
// // isn't the same as we have detected here, attempts to force a resync of the
723+
// // devices from the API.
724+
// if devices.len() != TUSB_INTERFACE.get_devices().len() {
725+
// debug!("Device Desync Detected, attempting to resync..");
726+
// let _ = TUSB_INTERFACE.detect_devices();
727+
// }
728+
//
729+
// if let Some(sender) = ready_sender.take() {
730+
// let _ = sender.send(true);
731+
// }
732+
// sleep(Duration::from_secs(1));
733+
// }
734+
// });
735+
//
736+
// // Block until the 'ready' message has been sent..
737+
// while ready_rx.try_recv().is_err() {
738+
// sleep(Duration::from_millis(5));
739+
// }
740+
// debug!("RUSB PnP Handler Started");
741+
//
742+
// *spawned = true;
743+
// Ok(())
744+
// }
746745
}
747746

748-
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
749-
struct USBDevice {
750-
pub(crate) bus_number: u8,
751-
pub(crate) address: u8,
752-
}
747+
// #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
748+
// struct USBDevice {
749+
// pub(crate) bus_number: u8,
750+
// pub(crate) address: u8,
751+
// }
753752

754753
pub struct DeviceHandle {
755754
handle: u32,

usb/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub enum ConnectError {
33
#[error("No GoXLR device was found")]
44
DeviceNotFound,
55

6+
#[cfg(not(target_os = "windows"))]
67
#[error("USB error: {0}")]
78
UsbError(#[from] rusb::Error),
89

@@ -15,6 +16,7 @@ pub enum ConnectError {
1516

1617
#[derive(thiserror::Error, Debug)]
1718
pub enum CommandError {
19+
#[cfg(not(target_os = "windows"))]
1820
#[error("USB error: {0}")]
1921
UsbError(#[from] rusb::Error),
2022

usb/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#[cfg(not(target_os = "windows"))]
12
pub use rusb;
3+
24
pub mod buttonstate;
35
pub mod channelstate;
46
pub mod colouring;

0 commit comments

Comments
 (0)