feat: small refactor of physical xr device detection and subsequent profile selection

This commit is contained in:
Gabriele Musco 2024-08-05 13:32:15 +02:00
commit 2bd0b12e91
2 changed files with 44 additions and 44 deletions

View file

@ -2,7 +2,7 @@ use serde::{de::Error, Deserialize, Serialize};
use crate::{ use crate::{
constants::CMD_NAME, constants::CMD_NAME,
device_prober::get_xr_usb_devices, device_prober::PhysicalXRDevice,
file_utils::get_writer, file_utils::get_writer,
paths::get_config_dir, paths::get_config_dir,
profile::Profile, profile::Profile,
@ -46,18 +46,16 @@ impl Config {
pub fn get_selected_profile(&self, profiles: &[Profile]) -> Profile { pub fn get_selected_profile(&self, profiles: &[Profile]) -> Profile {
let def = || profiles.first().expect("No profiles found").clone(); let def = || profiles.first().expect("No profiles found").clone();
match profiles if let Some(p) = profiles
.iter() .iter()
.find(|p| p.uuid == self.selected_profile_uuid) .find(|p| p.uuid == self.selected_profile_uuid)
{ {
Some(p) => p.clone(), p.clone()
None => match get_xr_usb_devices().first() { } else {
Some(dev) => match dev.get_default_profile() { PhysicalXRDevice::from_usb()
Some(p) => p, .first()
None => def(), .and_then(|xrd| xrd.get_default_profile())
}, .unwrap_or_else(def)
None => def(),
},
} }
} }

View file

@ -151,38 +151,40 @@ fn list_usb_devs() -> Vec<(u16, u16)> {
.collect() .collect()
} }
pub fn get_xr_usb_devices() -> Vec<PhysicalXRDevice> { impl PhysicalXRDevice {
list_usb_devs() pub fn from_usb() -> Vec<Self> {
.into_iter() list_usb_devs()
.filter_map(|t| match t { .into_iter()
// PCVR .filter_map(|t| match t {
(0x28de, 0x2102) => Some(PhysicalXRDevice::ValveIndex), // PCVR
// this is the index controller, shouldn't dictate the driver (0x28de, 0x2102) => Some(PhysicalXRDevice::ValveIndex),
// so it's commented out // this is the index controller, shouldn't dictate the driver
// (0x28de, 0x2300) => Some(PhysicalXRDevice::ValveIndex), // so it's commented out
(0x0bb4, 0x2c87) => Some(PhysicalXRDevice::HTCVive), // (0x28de, 0x2300) => Some(PhysicalXRDevice::ValveIndex),
(0x0bb4, 0x0309) => Some(PhysicalXRDevice::HTCVivePro), (0x0bb4, 0x2c87) => Some(PhysicalXRDevice::HTCVive),
(0x0bb4, 0x0313) => Some(PhysicalXRDevice::HTCViveCosmos), (0x0bb4, 0x0309) => Some(PhysicalXRDevice::HTCVivePro),
(0x0bb4, 0x0342) => Some(PhysicalXRDevice::HTCVivePro2), (0x0bb4, 0x0313) => Some(PhysicalXRDevice::HTCViveCosmos),
(0x2833, 0x0031) => Some(PhysicalXRDevice::OculusRift), (0x0bb4, 0x0342) => Some(PhysicalXRDevice::HTCVivePro2),
(0x2833, 0x0051) => Some(PhysicalXRDevice::OculusRiftS), (0x2833, 0x0031) => Some(PhysicalXRDevice::OculusRift),
(0x1532, 0x0300) => Some(PhysicalXRDevice::RazerHydra), (0x2833, 0x0051) => Some(PhysicalXRDevice::OculusRiftS),
(0x0483, 0x0021) => Some(PhysicalXRDevice::Pimax4K), (0x1532, 0x0300) => Some(PhysicalXRDevice::RazerHydra),
(0x054c, 0x09af) => Some(PhysicalXRDevice::PlayStationVR), (0x0483, 0x0021) => Some(PhysicalXRDevice::Pimax4K),
(0x054c, 0x0cde) => Some(PhysicalXRDevice::PlayStationVR2), (0x054c, 0x09af) => Some(PhysicalXRDevice::PlayStationVR),
(0x03f0, 0x0c6a) => Some(PhysicalXRDevice::HPReverbG1), (0x054c, 0x0cde) => Some(PhysicalXRDevice::PlayStationVR2),
(0x03f0, 0x0580) => Some(PhysicalXRDevice::HPReverbG2), (0x03f0, 0x0c6a) => Some(PhysicalXRDevice::HPReverbG1),
(0x04b4, 0x6504) => Some(PhysicalXRDevice::LenovoExplorer), (0x03f0, 0x0580) => Some(PhysicalXRDevice::HPReverbG2),
(0x35bd, 0x0101) => Some(PhysicalXRDevice::BigscreenBeyond), (0x04b4, 0x6504) => Some(PhysicalXRDevice::LenovoExplorer),
(0x04e8, 0x7312) => Some(PhysicalXRDevice::SamsungOdysseyPlus), (0x35bd, 0x0101) => Some(PhysicalXRDevice::BigscreenBeyond),
(0x04e8, 0x7084) => Some(PhysicalXRDevice::SamsungOdysseyPlus), (0x04e8, 0x7312) => Some(PhysicalXRDevice::SamsungOdysseyPlus),
(0x413c, 0xb0d5) => Some(PhysicalXRDevice::DellVisor), (0x04e8, 0x7084) => Some(PhysicalXRDevice::SamsungOdysseyPlus),
// Standalone (0x413c, 0xb0d5) => Some(PhysicalXRDevice::DellVisor),
(0x2833, 0x0137) => Some(PhysicalXRDevice::OculusQuest), // Standalone
(0x2833, 0x0186) => Some(PhysicalXRDevice::OculusQuest2), (0x2833, 0x0137) => Some(PhysicalXRDevice::OculusQuest),
(0x2d40, 0x00b7) => Some(PhysicalXRDevice::Pico4), (0x2833, 0x0186) => Some(PhysicalXRDevice::OculusQuest2),
(0x0bb4, 0x0344) => Some(PhysicalXRDevice::ViveFocus3), (0x2d40, 0x00b7) => Some(PhysicalXRDevice::Pico4),
_ => None, (0x0bb4, 0x0344) => Some(PhysicalXRDevice::ViveFocus3),
}) _ => None,
.collect() })
.collect()
}
} }