xous-core/services/ticktimer-server/src/api.rs

48 lines
1.2 KiB
Rust
Raw Normal View History

2020-10-12 11:08:16 +00:00
use xous::{Message, ScalarMessage};
#[derive(Debug)]
pub enum Opcode {
/// Reset the timer
Reset,
/// Get the elapsed time in milliseconds
ElapsedMs,
}
impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
type Error = &'static str;
fn try_from(message: &'a Message) -> Result<Self, Self::Error> {
match message {
Message::Scalar(m) => match m.id {
1 => Ok(Opcode::Reset),
_ => Err("unrecognized opcode"),
},
Message::BlockingScalar(m) => match m.id {
4919 => Ok(Opcode::ElapsedMs),
_ => Err("unrecognized opcode"),
}
2020-10-12 11:08:16 +00:00
_ => Err("unhandled message type"),
}
}
}
impl Into<Message> for Opcode {
fn into(self) -> Message {
match self {
Opcode::Reset => Message::Scalar(ScalarMessage {
id: 1,
arg1: 0,
arg2: 0,
arg3: 0,
arg4: 0,
}),
2020-10-13 14:49:12 +00:00
Opcode::ElapsedMs => Message::BlockingScalar(ScalarMessage {
id: 4919,
2020-10-12 11:08:16 +00:00
arg1: 0,
arg2: 0,
arg3: 0,
arg4: 0,
}),
}
}
}