From 3c63415e631cf7294d6472136343de9c38fd8134 Mon Sep 17 00:00:00 2001 From: James Wenzel Date: Sun, 23 Aug 2026 11:52:37 -0700 Subject: [PATCH] fix: detect TP-7 audio mode on OS 2.5.7 --- src/device.rs | 14 +++++++++++++- src/usb_owner.rs | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/device.rs b/src/device.rs index 3c19e2a..64bd7b1 100644 --- a/src/device.rs +++ b/src/device.rs @@ -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")] @@ -72,7 +77,7 @@ pub fn list_tp7_devices() -> Result, 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()) @@ -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)]; diff --git a/src/usb_owner.rs b/src/usb_owner.rs index ab28562..b121199 100644 --- a/src/usb_owner.rs +++ b/src/usb_owner.rs @@ -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 {