mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add a gyro test command to shellchat
This commit is contained in:
parent
5d4e716e1b
commit
3f12b0a69b
5 changed files with 64 additions and 2 deletions
|
|
@ -55,8 +55,8 @@ pub(crate) enum Opcode {
|
|||
/// Turn Boost Mode Off
|
||||
BoostOff,
|
||||
|
||||
/// Read the current accelerations off the IMU
|
||||
//ImuAccelRead,
|
||||
/// Read the current accelerations off the IMU; this blocks while the read takes place
|
||||
ImuAccelReadBlocking,
|
||||
|
||||
/// Power off the SoC
|
||||
PowerOffSoc,
|
||||
|
|
|
|||
|
|
@ -220,6 +220,22 @@ impl Com {
|
|||
Message::new_scalar(Opcode::RequestCharging.to_usize().unwrap(), 0, 0, 0, 0
|
||||
)).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn gyro_read_blocking(&self) -> Result<(u16, u16, u16, u16), xous::Error> {
|
||||
if let xous::Result::Scalar2(x_y, z_id) =
|
||||
send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::ImuAccelReadBlocking.to_usize().unwrap(), 0, 0, 0, 0)).unwrap() {
|
||||
|
||||
let x = (x_y >> 16) as u16;
|
||||
let y = (x_y & 0xffff) as u16;
|
||||
let z = (z_id >> 16) as u16;
|
||||
let id = (z_id & 0xffff) as u16;
|
||||
Ok((x, y, z, id))
|
||||
} else {
|
||||
Err(xous::Error::InternalError)
|
||||
}
|
||||
}
|
||||
|
||||
// note to future self: add other event listener registrations (such as network events) here
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -384,6 +384,18 @@ fn xmain() -> ! {
|
|||
bl_sec = secondary;
|
||||
com.txrx(ComState::BL_START.verb | (main as u16) & 0x1f | (((secondary as u16) & 0x1f) << 5));
|
||||
}),
|
||||
Some(Opcode::ImuAccelReadBlocking) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
com.txrx(ComState::GYRO_UPDATE.verb);
|
||||
com.txrx(ComState::GYRO_READ.verb);
|
||||
let x = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||
let y = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||
let z = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||
let id = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||
xous::return_scalar2(msg.sender,
|
||||
((x as usize) << 16) | y as usize,
|
||||
((z as usize) << 16) | id as usize
|
||||
).expect("coludn't return acceleromotere read data");
|
||||
}),
|
||||
Some(Opcode::BattStats) => {
|
||||
info!("batt stats request received");
|
||||
let stats = com.get_battstats();
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ mod ssid; use ssid::*;
|
|||
mod ver; use ver::*;
|
||||
mod audio; use audio::*;
|
||||
mod backlight; use backlight::*;
|
||||
mod accel; use accel::*;
|
||||
|
||||
mod fcc; use fcc::*;
|
||||
mod pds; // dependency of the FCC file
|
||||
|
|
@ -142,6 +143,7 @@ impl CmdEnv {
|
|||
let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions)
|
||||
let mut ver_cmd = Ver{};
|
||||
let mut backlight_cmd = Backlight{};
|
||||
let mut accel_cmd = Accel{};
|
||||
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||
&mut echo_cmd,
|
||||
|
|
@ -155,6 +157,7 @@ impl CmdEnv {
|
|||
&mut ver_cmd,
|
||||
&mut self.audio_cmd,
|
||||
&mut backlight_cmd,
|
||||
&mut accel_cmd,
|
||||
|
||||
&mut self.fcc_cmd,
|
||||
];
|
||||
|
|
|
|||
31
services/shellchat/src/cmds/accel.rs
Normal file
31
services/shellchat/src/cmds/accel.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use crate::{ShellCmdApi, CommonEnv};
|
||||
use xous_ipc::String;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Accel {
|
||||
}
|
||||
|
||||
impl<'a> ShellCmdApi<'a> for Accel {
|
||||
cmd_api!(accel); // inserts boilerplate for command API
|
||||
|
||||
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
let mut ret = String::<1024>::new();
|
||||
let helpstring = "accel has no options";
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
_ => {
|
||||
let (x, y, z, id) = env.com.gyro_read_blocking().unwrap();
|
||||
write!(ret, "x: {} y: {} z: {}, id: 0x{:x}", x, y, z, id).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue