create VmcExtCon

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 10:17:28 -05:00
parent db21964ea1
commit e8bb18c47e

View File

@ -412,3 +412,82 @@ impl MessageBehavior for VmcExtCam {
}); });
} }
} }
struct VmcExtCon {
active: i32,
name: String,
is_left: i32,
is_touch: i32,
axis: Vector3,
}
impl MessageBehavior for VmcExtCon {
fn to_sendable_osc_message(&self) -> OscMessage {
return OscMessage {
addr: String::from("/VMC/Ext/Cam"),
args: vec![
OscType::from(self.active),
OscType::from(self.name.to_owned()),
OscType::from(self.is_left),
OscType::from(self.is_touch),
OscType::from(self.axis.x),
OscType::from(self.axis.y),
OscType::from(self.axis.z),
],
};
}
fn parse_from_osc_message(msg: OscMessage) -> Result<Self, String> {
if msg.args.len() != 7 {
return Err(String::from("arg count invalid"));
}
let active: i32;
let name: String;
let is_left: i32;
let is_touch: i32;
let mut axis = Vector3::new(0.0, 0.0, 0.0);
match msg.args[0] {
OscType::Int(i) => active = i,
_ => return Err(String::from("arg type invalid")),
}
if active > 2 || active < 0 {
return Err(String::from("arg value invalid"));
}
match &msg.args[1] {
OscType::String(s) => name = s.to_owned(),
_ => return Err(String::from("arg value invalid")),
}
match msg.args[2] {
OscType::Int(i) => is_left = i,
_ => return Err(String::from("arg type invalid")),
}
if is_left < 0 || is_left > 1 {
return Err(String::from("arg value invalid"));
}
match msg.args[3] {
OscType::Int(i) => is_touch = i,
_ => return Err(String::from("arg type invalid")),
}
if is_touch < 0 || is_touch > 1 {
return Err(String::from("arg value invalid"));
}
match msg.args[4] {
OscType::Float(f) => axis.x = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[5] {
OscType::Float(f) => axis.y = f,
_ => return Err(String::from("arg type invalid")),
}
match msg.args[6] {
OscType::Float(f) => axis.z = f,
_ => return Err(String::from("arg type invalid")),
}
return Ok(VmcExtCon {
active,
name,
is_left,
is_touch,
axis,
});
}
}