mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-25 18:58:38 +00:00
feat: button to auto add detected trackers to config
This commit is contained in:
parent
ac340ae6f2
commit
a21d8f27f4
2 changed files with 69 additions and 2 deletions
|
@ -163,6 +163,19 @@ pub struct MonadoConfigV0 {
|
||||||
pub tracker_roles: Vec<TrackerRole>,
|
pub tracker_roles: Vec<TrackerRole>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MonadoConfigV0 {
|
||||||
|
pub fn has_tracker_serial(&self, serial: &str) -> bool {
|
||||||
|
self.tracker_roles.iter().any(|t| t.device_serial == serial)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_next_free_xrt_tracker_role(&self) -> XrtTrackerRole {
|
||||||
|
XrtTrackerRole::iter()
|
||||||
|
.find(|role| !self.tracker_roles.iter().any(|et| et.role == **role))
|
||||||
|
.unwrap_or(&XrtTrackerRole::ViveTrackerHtcxHandheldObject)
|
||||||
|
.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_monado_config_v0_path() -> String {
|
fn get_monado_config_v0_path() -> String {
|
||||||
format!(
|
format!(
|
||||||
"{config}/monado/config_v0.json",
|
"{config}/monado/config_v0.json",
|
||||||
|
@ -188,6 +201,23 @@ pub fn dump_monado_config_v0(config: &MonadoConfigV0) {
|
||||||
dump_monado_config_v0_to_path(config, &get_monado_config_v0_path());
|
dump_monado_config_v0_to_path(config, &get_monado_config_v0_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dump_generic_trackers(trackers: &[String]) -> usize {
|
||||||
|
let mut conf = get_monado_config_v0();
|
||||||
|
let mut added: usize = 0;
|
||||||
|
trackers.iter().for_each(|serial| {
|
||||||
|
if conf.has_tracker_serial(serial) {
|
||||||
|
conf.tracker_roles.push(TrackerRole {
|
||||||
|
device_serial: serial.to_string(),
|
||||||
|
role: conf.get_next_free_xrt_tracker_role(),
|
||||||
|
..TrackerRole::default()
|
||||||
|
});
|
||||||
|
added += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
added
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::get_monado_config_v0_from_path;
|
use super::get_monado_config_v0_from_path;
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
use crate::xr_devices::{XRDevice, XRDevices};
|
use crate::{
|
||||||
|
file_builders::monado_config_v0::dump_generic_trackers,
|
||||||
|
xr_devices::{XRDevice, XRDevices},
|
||||||
|
};
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use relm4::prelude::*;
|
use relm4::prelude::*;
|
||||||
|
|
||||||
|
use super::alert::alert;
|
||||||
|
|
||||||
#[tracker::track]
|
#[tracker::track]
|
||||||
pub struct DevicesBox {
|
pub struct DevicesBox {
|
||||||
devices: Option<XRDevices>,
|
devices: Option<XRDevices>,
|
||||||
|
@ -10,6 +15,7 @@ pub struct DevicesBox {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DevicesBoxMsg {
|
pub enum DevicesBoxMsg {
|
||||||
UpdateDevices(Option<XRDevices>),
|
UpdateDevices(Option<XRDevices>),
|
||||||
|
DumpGenericTrackers,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DevicesBox {
|
impl DevicesBox {
|
||||||
|
@ -251,6 +257,16 @@ impl SimpleComponent for DevicesBox {
|
||||||
None => "None".to_string(),
|
None => "None".to_string(),
|
||||||
}).as_str(),
|
}).as_str(),
|
||||||
},
|
},
|
||||||
|
gtk::Button {
|
||||||
|
set_halign: gtk::Align::Start,
|
||||||
|
set_hexpand: false,
|
||||||
|
set_icon_name: "document-save-symbolic",
|
||||||
|
set_tooltip_text: Some("Save current trackers"),
|
||||||
|
set_css_classes: &["circular", "flat"],
|
||||||
|
connect_clicked => move |_| {
|
||||||
|
sender.input(Self::Input::DumpGenericTrackers);
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,13 +278,34 @@ impl SimpleComponent for DevicesBox {
|
||||||
Self::Input::UpdateDevices(devs) => {
|
Self::Input::UpdateDevices(devs) => {
|
||||||
self.set_devices(devs);
|
self.set_devices(devs);
|
||||||
}
|
}
|
||||||
|
Self::Input::DumpGenericTrackers => {
|
||||||
|
if let Some(devs) = self.devices.as_ref() {
|
||||||
|
let added = dump_generic_trackers(&devs.generic_trackers);
|
||||||
|
let multi_title = format!("Added {} new trackers", added);
|
||||||
|
let (title, msg) = match added {
|
||||||
|
0 => (
|
||||||
|
"No new trackers found",
|
||||||
|
"All the currently connected trackers are already present in your configuration"
|
||||||
|
),
|
||||||
|
1 => (
|
||||||
|
"Added 1 new tracker",
|
||||||
|
"Edit your configuration to make sure that all the trackers have the appropriate roles assigned"
|
||||||
|
),
|
||||||
|
_ => (
|
||||||
|
multi_title.as_str(),
|
||||||
|
"Edit your configuration to make sure that all the trackers have the appropriate roles assigned"
|
||||||
|
),
|
||||||
|
};
|
||||||
|
alert(title, Some(msg), None);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(
|
fn init(
|
||||||
_init: Self::Init,
|
_init: Self::Init,
|
||||||
root: &Self::Root,
|
root: &Self::Root,
|
||||||
_sender: ComponentSender<Self>,
|
sender: ComponentSender<Self>,
|
||||||
) -> ComponentParts<Self> {
|
) -> ComponentParts<Self> {
|
||||||
let model = Self {
|
let model = Self {
|
||||||
tracker: 0,
|
tracker: 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue