feat: xr devices struct representing roles in monado log

This commit is contained in:
Gabriele Musco 2023-07-07 06:31:36 +02:00
commit 94932b0214
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
2 changed files with 66 additions and 0 deletions

View file

@ -26,6 +26,7 @@ pub mod downloader;
pub mod env_var_descriptions;
pub mod log_parser;
pub mod log_level;
pub mod xr_devices;
fn main() -> Result<()> {
// Prepare i18n

65
src/xr_devices.rs Normal file
View file

@ -0,0 +1,65 @@
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum XRDevice {
Head, Left, Right, Gamepad, Eyes, HandTrackingLeft, HandTrackingRight
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct XRDevices {
pub head: Option<String>,
pub left: Option<String>,
pub right: Option<String>,
pub gamepad: Option<String>,
pub eyes: Option<String>,
pub hand_tracking_left: Option<String>,
pub hand_tracking_right: Option<String>,
}
impl Default for XRDevices {
fn default() -> Self {
Self {
head: None,
left: None,
right: None,
gamepad: None,
eyes: None,
hand_tracking_left: None,
hand_tracking_right: None,
}
}
}
impl XRDevices {
pub fn from_log_message(s: String) -> Option<Self> {
let rows = s.split("\n");
let mut in_section = false;
let mut devs = Self::default();
for row in rows {
if !in_section && row.starts_with("\tIn roles:") {
in_section = true;
continue;
}
if in_section {
if row.starts_with("\tResult:") {
break;
}
match row.trim().split(": ").collect::<Vec<&str>>()[..] {
[_, "<none>"] => {},
["head", val] => devs.head = Some(val.to_string()),
["left", val] => devs.left = Some(val.to_string()),
["right", val] => devs.right = Some(val.to_string()),
["gamepad", val] => devs.gamepad = Some(val.to_string()),
["eyes", val] => devs.eyes = Some(val.to_string()),
["hand_tracking.left", val] => devs.hand_tracking_left = Some(val.to_string()),
["hand_tracking.right", val] => {
devs.hand_tracking_right = Some(val.to_string())
}
_ => {}
}
}
}
if in_section {
return Some(devs);
}
None
}
}