Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use crate::output::AppError;

pub const TP7_VENDOR_ID: u16 = 0x2367;
pub const TP7_PRODUCT_ID: u16 = 0x0019;
pub const TP7_AUDIO_MIDI_PRODUCT_ID: u16 = 0x8019;

pub fn is_tp7_product_id(product_id: u16) -> bool {
matches!(product_id, TP7_PRODUCT_ID | TP7_AUDIO_MIDI_PRODUCT_ID)
}

#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -72,7 +77,7 @@ pub fn list_tp7_devices() -> Result<Vec<Tp7Device>, AppError> {

Ok(devices
.filter(|device| {
device.vendor_id() == TP7_VENDOR_ID && device.product_id() == TP7_PRODUCT_ID
device.vendor_id() == TP7_VENDOR_ID && is_tp7_product_id(device.product_id())
})
.map(Tp7Device::from)
.collect())
Expand Down Expand Up @@ -352,6 +357,13 @@ mod tests {
}
}

#[test]
fn recognizes_known_product_ids() {
assert!(is_tp7_product_id(TP7_PRODUCT_ID));
assert!(is_tp7_product_id(TP7_AUDIO_MIDI_PRODUCT_ID));
assert!(!is_tp7_product_id(0x1234));
}

#[test]
fn infers_audio_midi_mode() {
let interfaces = vec![interface(0x01, 0x01, 0), interface(0x01, 0x03, 0)];
Expand Down
4 changes: 3 additions & 1 deletion src/usb_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ fn owner_belongs_to_tp7_device(entries: &[IoregEntry], index: usize) -> bool {
fn is_tp7_device_entry(entry: &IoregEntry) -> bool {
entry.node_class == "IOUSBHostDevice"
&& entry.id_vendor == Some(crate::device::TP7_VENDOR_ID)
&& entry.id_product == Some(crate::device::TP7_PRODUCT_ID)
&& entry
.id_product
.is_some_and(crate::device::is_tp7_product_id)
}

fn nearest_scope_entry(entries: &[IoregEntry], index: usize) -> usize {
Expand Down