xous-core/services/shellchat/src/cmds/sensors.rs
2021-03-11 02:57:58 +08:00

44 lines
No EOL
1.2 KiB
Rust

use crate::{ShellCmdApi,CommonEnv};
use xous::String;
#[derive(Debug)]
pub struct Sensors {
}
impl Sensors {
pub fn new() -> Self {
Sensors {}
}
}
const VERB: &str = "sensors";
impl<'a> ShellCmdApi<'a> for Sensors {
fn process(&mut self, _rest: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
use core::fmt::Write;
let mut ret = String::<1024>::new();
write!(ret, "Vbus {:.2}V\nVint {:.2}V\nVaux {:.2}V\nVbram {:.2}V\nUSB {:.2}|{:.2}V\nTemp {:.1}°C",
(llio::adc_vbus(env.llio).unwrap() as f64) * 0.005033,
(llio::adc_vccint(env.llio).unwrap() as f64) / 1365.0,
(llio::adc_vccaux(env.llio).unwrap() as f64) / 1365.0,
(llio::adc_vccbram(env.llio).unwrap() as f64) / 1365.0,
(llio::adc_usb_p(env.llio).unwrap() as f64) / 1365.0,
(llio::adc_usb_n(env.llio).unwrap() as f64) / 1365.0,
((llio::adc_temperature(env.llio).unwrap() as f64) * 0.12304) - 273.15,
).unwrap();
Ok(Some(ret))
}
fn verb(&self) -> &'static str {
VERB
}
fn matches(&self, verb: &str) -> bool {
if verb == VERB {
true
} else {
false
}
}
}