xous-core/services/shellchat/src/cmds/vibe.rs

51 lines
1.5 KiB
Rust
Raw Normal View History

2021-04-16 11:27:48 +00:00
use crate::{ShellCmdApi, CommonEnv};
use xous_ipc::String;
use core::fmt::Write;
#[derive(Debug)]
pub struct Vibe {
}
impl Vibe {
pub fn new() -> Self {
2021-04-16 11:27:48 +00:00
Vibe {
}
}
}
impl<'a> ShellCmdApi<'a> for Vibe {
cmd_api!(vibe); // inserts boilerplate for command API
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
let mut ret = String::<1024>::new();
let helpstring = "vibe [on] [off] [long] [double]";
let mut tokens = args.as_str().unwrap().split(' ');
if let Some(sub_cmd) = tokens.next() {
match sub_cmd {
"on" => {
env.gam.set_vibe(true).unwrap();
2021-04-16 11:27:48 +00:00
write!(ret, "Keyboard vibrate on").unwrap();
}
"off" => {
env.gam.set_vibe(false).unwrap();
2021-04-16 11:27:48 +00:00
write!(ret, "Keyboard vibrate off").unwrap();
}
"long" => {
env.llio.vibe(llio::VibePattern::Long).unwrap();
write!(ret, "Long vibe").unwrap();
}
"double" => {
env.llio.vibe(llio::VibePattern::Double).unwrap();
write!(ret, "Double vibe").unwrap();
}
_ => write!(ret, "{}", helpstring).unwrap(),
}
} else {
write!(ret, "{}", helpstring).unwrap();
}
Ok(Some(ret))
}
}