prep to migrate API in git

This commit is contained in:
bunnie 2021-03-04 18:13:50 +08:00
parent aa8c0e5792
commit fff7c024ad

View file

@ -1,44 +0,0 @@
use xous::{Message, ScalarMessage};
use graphics_server::Gid;
#[allow(dead_code)]
#[derive(Debug, rkyv::Archive, rkyv::Unarchive)]
pub enum Opcode {
/// informs me where my input canvas is
SetInputCanvas(Gid),
/// informs me where my prediction canvas is
SetPredictionCanvas(Gid),
/// set prediction server. Must be a String of the name of a server that is loaded in the system.
SetPredictionServer(xous::String<256>),
}
impl core::convert::TryFrom<& Message> for Opcode {
type Error = &'static str;
fn try_from(message: & Message) -> Result<Self, Self::Error> {
match message {
Message::Scalar(m) => match m.id {
0 => Ok(Opcode::SetInputCanvas(Gid::new([m.arg1 as _, m.arg2 as _, m.arg3 as _, m.arg4 as _]))),
1 => Ok(Opcode::SetPredictionCanvas(Gid::new([m.arg1 as _, m.arg2 as _, m.arg3 as _, m.arg4 as _]))),
_ => Err("IMEF api: unknown Scalar ID"),
},
_ => Err("IMEF api: unhandled message type"),
}
}
}
impl Into<Message> for Opcode {
fn into(self) -> Message {
match self {
Opcode::SetInputCanvas(gid) => Message::Scalar(ScalarMessage {
id: 0, arg1: gid.gid()[0] as _, arg2: gid.gid()[1] as _, arg3: gid.gid()[2] as _, arg4: gid.gid()[3] as _
}),
Opcode::SetPredictionCanvas(gid) => Message::Scalar(ScalarMessage {
id: 0, arg1: gid.gid()[0] as _, arg2: gid.gid()[1] as _, arg3: gid.gid()[2] as _, arg4: gid.gid()[3] as _
}),
_ => panic!("IMEF api: Opcode type not handled by into()"),
}
}
}