add touch debug console commands

This commit is contained in:
bunnie 2026-01-05 08:53:59 +08:00
parent 9a94ea48ad
commit 1bc7cfc7d2
2 changed files with 79 additions and 0 deletions

View file

@ -92,6 +92,8 @@ mod i2cdetect;
use i2cdetect::*;
mod ws2812;
use ws2812::*;
mod touch;
use touch::*;
pub struct CmdEnv {
common_env: CommonEnv,
@ -103,6 +105,7 @@ pub struct CmdEnv {
#[cfg(feature = "aestests")]
aes_cmd: Aes,
ws2812_cmd: Ws2812,
touch_cmd: Touch,
}
impl CmdEnv {
pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
@ -130,6 +133,7 @@ impl CmdEnv {
#[cfg(feature = "aestests")]
aes_cmd,
ws2812_cmd: Ws2812::new(),
touch_cmd: Touch::new(),
}
}
@ -157,6 +161,7 @@ impl CmdEnv {
#[cfg(feature = "aestests")]
&mut self.aes_cmd,
&mut self.ws2812_cmd,
&mut self.touch_cmd,
];
if let Some(cmdline) = maybe_cmdline {

View file

@ -0,0 +1,74 @@
use arbitrary_int::u5;
use crate::cmds::ShellCmdApi;
const DEFAULT_TOUCH_PIN: u8 = 1;
pub struct Touch {
pin: u5,
}
impl Touch {
pub fn new() -> Self { Touch { pin: u5::new(DEFAULT_TOUCH_PIN) } }
}
impl<'a> ShellCmdApi<'a> for Touch {
cmd_api!(touch);
fn process(&mut self, args: String, env: &mut super::CommonEnv) -> Result<Option<String>, xous::Error> {
use core::fmt::Write;
let mut ret = String::new();
let helpstring = "ws2812 [rainbow [<duration>]] [length <pixels>] [hexcolor <#rrggbb>]";
let mut tokens = args.split(' ');
if let Some(sub_cmd) = tokens.next() {
match sub_cmd {
"pin" => {
if let Some(pin_str) = tokens.next() {
let pin = u8::from_str_radix(pin_str, 10).unwrap_or(DEFAULT_TOUCH_PIN);
log::info!("Setting input pin to BIO pin {}", pin);
self.pin = arbitrary_int::u5::new(pin);
}
}
"monitor" => {
let mut captouch = bio_lib::captouch::Captouch::new(self.pin, None).unwrap();
captouch.calibrate(None).unwrap();
loop {
log::info!("{:?}, {}", captouch.is_touched(), captouch.raw_status());
env.ticktimer.sleep_ms(100).ok();
}
}
"wait-touch" => {
let mut captouch = bio_lib::captouch::Captouch::new(self.pin, None).unwrap();
captouch.calibrate(None).unwrap();
log::info!("waiting for touch");
captouch.wait_touch(None).unwrap();
log::info!("touch!");
}
"wait-release" => {
let mut captouch = bio_lib::captouch::Captouch::new(self.pin, None).unwrap();
captouch.calibrate(None).unwrap();
log::info!("Touch and hold...");
captouch.wait_touch(None).unwrap();
env.ticktimer.sleep_ms(100).ok();
log::info!("...now waiting for release");
captouch.wait_release(None).unwrap();
log::info!("release!");
}
"touch-release" => {
let mut captouch = bio_lib::captouch::Captouch::new(self.pin, None).unwrap();
captouch.calibrate(None).unwrap();
log::info!("touch and release...");
captouch.wait_touch_and_release(None).unwrap();
log::info!("touched & released!");
}
_ => {
write!(ret, "{}", helpstring).unwrap();
}
}
} else {
write!(ret, "{}", helpstring).unwrap();
}
Ok(Some(ret))
}
}