mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
reduce resource usage of the oqc_test
- code is merged into shellchat so there's less alignment overhead and some library reuse - server is not spawned until it's needed, so the RAM load is less
This commit is contained in:
parent
9a86685e8b
commit
f626374b36
12 changed files with 446 additions and 91 deletions
44
Cargo.lock
generated
44
Cargo.lock
generated
|
|
@ -1404,25 +1404,6 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "oqc-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"com",
|
||||
"gam",
|
||||
"keyboard",
|
||||
"llio",
|
||||
"log",
|
||||
"log-server",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"ticktimer-server",
|
||||
"utralib",
|
||||
"xous",
|
||||
"xous-ipc",
|
||||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orbclient"
|
||||
version = "0.3.30"
|
||||
|
|
@ -1801,7 +1782,6 @@ dependencies = [
|
|||
"num-traits",
|
||||
"rand_core 0.5.1",
|
||||
"rkyv",
|
||||
"rtc",
|
||||
"sha2",
|
||||
"spinor",
|
||||
"susres",
|
||||
|
|
@ -1814,28 +1794,6 @@ dependencies = [
|
|||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"chrono",
|
||||
"gam",
|
||||
"llio",
|
||||
"locales",
|
||||
"log",
|
||||
"log-server",
|
||||
"modals",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"rkyv",
|
||||
"ticktimer-server",
|
||||
"utralib",
|
||||
"xous",
|
||||
"xous-ipc",
|
||||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.20"
|
||||
|
|
@ -2023,12 +1981,10 @@ dependencies = [
|
|||
"net",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"oqc-test",
|
||||
"pddb",
|
||||
"rand_core 0.5.1",
|
||||
"rkyv",
|
||||
"root-keys",
|
||||
"rtc",
|
||||
"sha2",
|
||||
"spectrum-analyzer",
|
||||
"spinor",
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ default-members = [
|
|||
"services/spinor",
|
||||
"services/root-keys",
|
||||
"services/jtag",
|
||||
"services/oqc-test",
|
||||
"services/test-stub2",
|
||||
"services/pddb",
|
||||
"services/net",
|
||||
|
|
@ -82,7 +81,6 @@ members = [
|
|||
"services/root-keys",
|
||||
"services/jtag",
|
||||
"tools/wycheproof-import",
|
||||
"services/oqc-test",
|
||||
"services/test-stub2",
|
||||
"services/pddb",
|
||||
"services/net",
|
||||
|
|
|
|||
|
|
@ -121,19 +121,6 @@ fn xmain() -> ! {
|
|||
*hit = true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
match remaining.get(&key) {
|
||||
Some(_hit) => {
|
||||
log::info!("got {}", map_codes(key));
|
||||
remaining.insert(key, true);
|
||||
},
|
||||
None => {
|
||||
if key.r != 254 { // 254 is (ab)used by the tester thread to create a ping event
|
||||
log::warn!("got unexpected r/c: {:?}", key)
|
||||
}
|
||||
},
|
||||
};
|
||||
*/
|
||||
}
|
||||
if elapsed - last_redraw_time > 100 { // rate limit redraws to 10Hz
|
||||
render_string(&mut bot_str, &remaining, timeout - (elapsed - start_time));
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ susres = {path = "../susres"}
|
|||
trng = {path= "../trng"}
|
||||
spinor = {path="../spinor"}
|
||||
llio = {path="../llio"}
|
||||
rtc = {path="../rtc"}
|
||||
com = {path="../com"}
|
||||
|
||||
xous-ipc = {path = "../../xous-ipc"}
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ fn xmain() -> ! {
|
|||
|
||||
// create the servers necessary to coordinate an auto-reboot sequence...
|
||||
let llio = llio::Llio::new(&xns);
|
||||
let rtc = rtc::Rtc::new(&xns);
|
||||
let rtc = llio::Rtc::new(&xns);
|
||||
let ticktimer = ticktimer_server::Ticktimer::new().unwrap();
|
||||
let com = com::Com::new(&xns).unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ graphics-server = {path = "../graphics-server"}
|
|||
ime-plugin-api = {path = "../ime-plugin-api"}
|
||||
ime-plugin-shell = {path = "../ime-plugin-shell"}
|
||||
llio = {path = "../llio"}
|
||||
rtc = {path = "../rtc"}
|
||||
log = "0.4.14"
|
||||
log-server = {path = "../log-server"}
|
||||
ticktimer-server = {path = "../ticktimer-server"}
|
||||
|
|
@ -45,8 +44,6 @@ rkyv = {version = "0.4.3", default-features = false, features = ["const_generics
|
|||
|
||||
# for audio self-test analysis
|
||||
spectrum-analyzer = "0.5.2"
|
||||
# for outgoing quality check
|
||||
oqc-test = {path="../oqc-test"}
|
||||
|
||||
# for the curve25519 tests
|
||||
# hardware acceleration adaptations are inserted into a fork of the main branch.
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ use trng::*;
|
|||
pub struct CommonEnv {
|
||||
llio: llio::Llio,
|
||||
i2c: llio::I2c,
|
||||
rtc: Arc<Mutex<rtc::Rtc>>,
|
||||
rtc: Arc<Mutex<llio::Rtc>>,
|
||||
com: com::Com,
|
||||
ticktimer: ticktimer_server::Ticktimer,
|
||||
gam: gam::Gam,
|
||||
|
|
@ -140,7 +140,7 @@ impl CmdEnv {
|
|||
let mut common = CommonEnv {
|
||||
llio: llio::Llio::new(&xns),
|
||||
i2c: llio::I2c::new(&xns),
|
||||
rtc: Arc::new(Mutex::new(rtc::Rtc::new(&xns))),
|
||||
rtc: Arc::new(Mutex::new(llio::Rtc::new(&xns))),
|
||||
com: com::Com::new(&xns).expect("could't connect to COM"),
|
||||
ticktimer,
|
||||
gam: gam::Gam::new(&xns).expect("couldn't connect to GAM"),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use xous_ipc::String;
|
|||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
static SHELLCONN: AtomicU32 = AtomicU32::new(0);
|
||||
pub fn dt_callback(dt: rtc::DateTime) {
|
||||
pub fn dt_callback(dt: llio::DateTime) {
|
||||
let buf = xous_ipc::Buffer::into_buf(dt).or(Err(xous::Error::InternalError)).unwrap();
|
||||
log::trace!("SHELLCONN: {}", SHELLCONN.load(Ordering::Relaxed));
|
||||
buf.send(SHELLCONN.load(Ordering::Relaxed), 0xdead_beef).unwrap(); // send an "unknown ID" so it's routed to the callback handler
|
||||
|
|
@ -32,10 +32,6 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
|||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
"ux" => {
|
||||
env.rtc.lock().unwrap().set_rtc_ux().expect("couldn't send set UX message");
|
||||
write!(ret, "{}", "UX time set launched").unwrap();
|
||||
}
|
||||
"get" => {
|
||||
write!(ret, "{}", "Requesting DateTime from RTC...").unwrap();
|
||||
env.rtc.lock().unwrap().hook_rtc_callback(dt_callback).unwrap();
|
||||
|
|
@ -49,7 +45,7 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
|||
let mut day: u8 = 0;
|
||||
let mut month: u8 = 0;
|
||||
let mut year: u8 = 0;
|
||||
let mut weekday: rtc::Weekday = rtc::Weekday::Sunday;
|
||||
let mut weekday: llio::Weekday = llio::Weekday::Sunday;
|
||||
|
||||
if let Some(tok_str) = tokens.next() {
|
||||
hour = if let Ok(n) = tok_str.parse::<u8>() { n } else { success = false; 0 }
|
||||
|
|
@ -89,13 +85,13 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
|||
|
||||
if let Some(tok_str) = tokens.next() {
|
||||
match tok_str {
|
||||
"mon" => weekday = rtc::Weekday::Monday,
|
||||
"tue" => weekday = rtc::Weekday::Tuesday,
|
||||
"wed" => weekday = rtc::Weekday::Wednesday,
|
||||
"thu" => weekday = rtc::Weekday::Thursday,
|
||||
"fri" => weekday = rtc::Weekday::Friday,
|
||||
"sat" => weekday = rtc::Weekday::Saturday,
|
||||
"sun" => weekday = rtc::Weekday::Sunday,
|
||||
"mon" => weekday = llio::Weekday::Monday,
|
||||
"tue" => weekday = llio::Weekday::Tuesday,
|
||||
"wed" => weekday = llio::Weekday::Wednesday,
|
||||
"thu" => weekday = llio::Weekday::Thursday,
|
||||
"fri" => weekday = llio::Weekday::Friday,
|
||||
"sat" => weekday = llio::Weekday::Saturday,
|
||||
"sun" => weekday = llio::Weekday::Sunday,
|
||||
_ => success = false,
|
||||
}
|
||||
} else {
|
||||
|
|
@ -104,7 +100,7 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
|||
if !success {
|
||||
write!(ret, "{}", "usage: rtc set hh mm ss MM DD YY day\n'day' is three-day code, eg. mon tue").unwrap();
|
||||
} else {
|
||||
let dt = rtc::DateTime {
|
||||
let dt = llio::DateTime {
|
||||
seconds: sec,
|
||||
minutes: min,
|
||||
hours: hour,
|
||||
|
|
@ -132,7 +128,7 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
|||
use core::fmt::Write;
|
||||
|
||||
let buffer = unsafe { xous_ipc::Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let dt = buffer.to_original::<rtc::DateTime, _>().unwrap();
|
||||
let dt = buffer.to_original::<llio::DateTime, _>().unwrap();
|
||||
|
||||
let mut ret = String::<1024>::new();
|
||||
write!(ret, "{}:{:02}:{:02}, {}/{}/{}, {:?}", dt.hours, dt.minutes, dt.seconds, dt.months, dt.days, dt.years, dt.weekday).unwrap();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::oqc_test::OqcOp;
|
||||
use crate::{ShellCmdApi,CommonEnv};
|
||||
use xous_ipc::String;
|
||||
use xous::{MessageEnvelope, Message};
|
||||
|
|
@ -6,9 +7,11 @@ use llio::I2cStatus;
|
|||
use codec::*;
|
||||
use spectrum_analyzer::{FrequencyLimit, FrequencySpectrum, samples_fft_to_spectrum};
|
||||
use spectrum_analyzer::windows::hann_window;
|
||||
use rtc::{DateTime, Weekday};
|
||||
use llio::{DateTime, Weekday};
|
||||
use core::fmt::Write;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use core::sync::atomic::{AtomicBool, Ordering, AtomicU32};
|
||||
use std::sync::Arc;
|
||||
use num_traits::*;
|
||||
|
||||
static AUDIO_OQC: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
|
|
@ -31,8 +34,6 @@ pub struct Test {
|
|||
end_time: Option<DateTime>,
|
||||
start_elapsed: Option<u64>,
|
||||
end_elapsed: Option<u64>,
|
||||
//kbd: Arc<Mutex<keyboard::Keyboard>>,
|
||||
oqc: oqc_test::Oqc,
|
||||
oqc_start: u64,
|
||||
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||
jtag: jtag::Jtag,
|
||||
|
|
@ -67,8 +68,6 @@ impl Test {
|
|||
end_time: None,
|
||||
start_elapsed: None,
|
||||
end_elapsed: None,
|
||||
//kbd: Arc::new(Mutex::new(keyboard::Keyboard::new(&xns).unwrap())),
|
||||
oqc: oqc_test::Oqc::new(&xns).unwrap(),
|
||||
oqc_start: 0,
|
||||
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||
jtag: jtag::Jtag::new(&xns).unwrap(),
|
||||
|
|
@ -399,6 +398,19 @@ impl<'a> ShellCmdApi<'a> for Test {
|
|||
log::info!("{}|ASTOP|", SENTINEL);
|
||||
}
|
||||
"oqc" => {
|
||||
let oqc_cid = Arc::new(AtomicU32::new(0));
|
||||
// start the OQC thread
|
||||
let _ = std::thread::spawn({
|
||||
let oqc_cid = oqc_cid.clone();
|
||||
move || {
|
||||
crate::oqc_test::oqc_test(oqc_cid);
|
||||
}
|
||||
});
|
||||
// wait until the OQC thread has connected itself
|
||||
while oqc_cid.load(Ordering::SeqCst) == 0 {
|
||||
env.ticktimer.sleep_ms(200).unwrap();
|
||||
}
|
||||
|
||||
if ((env.llio.adc_vbus().unwrap() as f64) * 0.005033) > 1.5 {
|
||||
// if power is plugged in, deny powerdown request
|
||||
write!(ret, "Can't run OQC test while charging. Unplug charging cable and try again.").unwrap();
|
||||
|
|
@ -434,10 +446,13 @@ impl<'a> ShellCmdApi<'a> for Test {
|
|||
susres.initiate_suspend().unwrap();
|
||||
env.ticktimer.sleep_ms(1000).unwrap(); // pause for the suspend/resume cycle
|
||||
|
||||
self.oqc.trigger(60_000);
|
||||
let timeout = 60_0000;
|
||||
xous::send_message(oqc_cid.load(Ordering::SeqCst),
|
||||
xous::Message::new_blocking_scalar(OqcOp::Trigger.to_usize().unwrap(), timeout, 0, 0, 0,)
|
||||
).expect("couldn't trigger self test");
|
||||
|
||||
loop {
|
||||
match self.oqc.status() {
|
||||
match oqc_status(oqc_cid.load(Ordering::SeqCst)) {
|
||||
Some(true) => {
|
||||
let ssid_str = env.com.ssid_fetch_as_string().unwrap();
|
||||
use std::str::FromStr;
|
||||
|
|
@ -846,3 +861,23 @@ fn rtc_get(i2c: &mut llio::I2c) -> Option<DateTime> {
|
|||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
fn oqc_status(conn: xous::CID) -> Option<bool> { // None if still running or not yet run; Some(true) if pass; Some(false) if fail
|
||||
let result = xous::send_message(conn,
|
||||
xous::Message::new_blocking_scalar(OqcOp::Status.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't query test status");
|
||||
match result {
|
||||
xous::Result::Scalar1(val) => {
|
||||
match val {
|
||||
0 => return None,
|
||||
1 => return Some(true),
|
||||
2 => return Some(false),
|
||||
_ => return Some(false),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log::error!("internal error");
|
||||
panic!("improper result code on oqc status query");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ use xous_ipc::{String, Buffer};
|
|||
mod cmds;
|
||||
use cmds::*;
|
||||
|
||||
mod oqc_test;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct History {
|
||||
// the history record
|
||||
|
|
|
|||
387
services/shellchat/src/oqc_test.rs
Normal file
387
services/shellchat/src/oqc_test.rs
Normal file
|
|
@ -0,0 +1,387 @@
|
|||
use num_traits::*;
|
||||
use gam::modal::*;
|
||||
use keyboard::{RowCol, KeyRawStates};
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) const SERVER_NAME_OQC: &str = "_Outgoing Quality Check Test Program_";
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum OqcOp {
|
||||
Trigger,
|
||||
KeyCode,
|
||||
Status,
|
||||
UxGutter,
|
||||
ModalRedraw,
|
||||
ModalKeys,
|
||||
ModalDrop,
|
||||
Quit,
|
||||
}
|
||||
|
||||
pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>) {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
// we allow any connections because this server is not spawned until it is needed
|
||||
let oqc_sid = xns.register_name(SERVER_NAME_OQC, None).expect("can't register server");
|
||||
|
||||
let ticktimer = ticktimer_server::Ticktimer::new().unwrap();
|
||||
let kbd = keyboard::Keyboard::new(&xns).unwrap();
|
||||
kbd.register_raw_listener(
|
||||
SERVER_NAME_OQC,
|
||||
OqcOp::KeyCode.to_usize().unwrap()
|
||||
);
|
||||
let com = com::Com::new(&xns).unwrap();
|
||||
let llio = llio::Llio::new(&xns);
|
||||
|
||||
let test_cid = xous::connect(oqc_sid).unwrap();
|
||||
let mut test_action = Notification::new(
|
||||
test_cid,
|
||||
OqcOp::UxGutter.to_u32().unwrap()
|
||||
);
|
||||
test_action.manual_dismiss = false;
|
||||
let mut test_modal = Modal::new(
|
||||
"test modal",
|
||||
ActionType::Notification(test_action),
|
||||
None,
|
||||
Some("Initializing..."),
|
||||
GlyphStyle::Small,
|
||||
8
|
||||
);
|
||||
let mut test_run = false;
|
||||
let mut remaining = populate_vectors();
|
||||
let mut bot_str = String::new();
|
||||
let mut start_time = 0;
|
||||
let mut timeout = 120_000;
|
||||
let mut passing: Option<bool> = None;
|
||||
let mut test_finished = false;
|
||||
let mut last_redraw_time = 0;
|
||||
|
||||
// this connection unblocks the calling thread
|
||||
oqc_cid.store(xous::connect(oqc_sid).unwrap(), Ordering::SeqCst);
|
||||
loop {
|
||||
let msg = xous::receive_message(oqc_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(OqcOp::Trigger) => xous::msg_blocking_scalar_unpack!(msg, timeout_set, _, _, _, {
|
||||
if !test_run {
|
||||
test_modal.spawn_helper(oqc_sid, test_modal.sid,
|
||||
OqcOp::ModalRedraw.to_u32().unwrap(),
|
||||
OqcOp::ModalKeys.to_u32().unwrap(),
|
||||
OqcOp::ModalDrop.to_u32().unwrap(),
|
||||
);
|
||||
|
||||
// test the screen
|
||||
com.set_backlight(255, 255).unwrap();
|
||||
test_modal.gam.selftest(8_000); // 12_000 by default
|
||||
|
||||
// now start the keyboard test
|
||||
timeout = if timeout_set > 120_000 {
|
||||
120_000
|
||||
} else {
|
||||
timeout_set as u64
|
||||
};
|
||||
start_time = ticktimer.elapsed_ms();
|
||||
last_redraw_time = start_time;
|
||||
log::info!("raising modal");
|
||||
render_string(&mut bot_str, &remaining, timeout - (ticktimer.elapsed_ms() - start_time));
|
||||
test_modal.modify(None, None, false,
|
||||
Some(bot_str.as_str()), false, None);
|
||||
test_modal.activate();
|
||||
test_modal.redraw();
|
||||
test_modal.gam.set_vibe(true).unwrap();
|
||||
|
||||
// start a thread that advances the timer when not hitting keys
|
||||
xous::create_thread_2(ping_thread, xous::connect(oqc_sid).unwrap() as usize, timeout as usize).unwrap();
|
||||
xous::return_scalar(msg.sender, 1).unwrap();
|
||||
} else {
|
||||
xous::return_scalar(msg.sender, 0).unwrap();
|
||||
}
|
||||
test_run = true;
|
||||
}),
|
||||
Some(OqcOp::KeyCode) => {
|
||||
if test_run {
|
||||
if test_finished {
|
||||
// we'll continue to get keycodes, but ignore them once the test is finished
|
||||
continue;
|
||||
}
|
||||
let elapsed = ticktimer.elapsed_ms();
|
||||
if elapsed - start_time < timeout {
|
||||
let buffer = unsafe {
|
||||
xous_ipc::Buffer::from_memory_message(msg.body.memory_message().unwrap())
|
||||
};
|
||||
let krs = buffer.to_original::<[(u8, u8); 32],_>().unwrap();
|
||||
let mut rawstates = KeyRawStates::new();
|
||||
for &(r, c) in krs[..16].iter() {
|
||||
if r != 255 || c != 255 {
|
||||
rawstates.keydowns.push(RowCol{r, c});
|
||||
}
|
||||
}
|
||||
for &(r, c) in krs[16..].iter() {
|
||||
if r!= 255 || c != 255 {
|
||||
rawstates.keyups.push(RowCol{r, c});
|
||||
}
|
||||
}
|
||||
|
||||
if rawstates.keydowns.len() > 0 { // only worry about keydowns
|
||||
for &key in rawstates.keydowns.iter() {
|
||||
for (rc, hit) in remaining.iter_mut() {
|
||||
if *rc == key {
|
||||
*hit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if elapsed - last_redraw_time > 100 { // rate limit redraws to 10Hz
|
||||
render_string(&mut bot_str, &remaining, timeout - (elapsed - start_time));
|
||||
test_modal.modify(None, None, false,
|
||||
Some(bot_str.as_str()), false, None);
|
||||
test_modal.redraw();
|
||||
last_redraw_time = elapsed;
|
||||
llio.vibe(llio::VibePattern::Short).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// iterate and see if all keys have been hit
|
||||
let mut finished = true;
|
||||
for &(_rc, vals) in remaining.iter() {
|
||||
if vals == false {
|
||||
finished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if finished {
|
||||
passing = Some(true);
|
||||
com.set_backlight(0, 0).unwrap();
|
||||
test_modal.gam.relinquish_focus().unwrap();
|
||||
log::info!("all keys hit, exiting");
|
||||
test_finished = true;
|
||||
}
|
||||
} else {
|
||||
// timeout
|
||||
passing = Some(false);
|
||||
com.set_backlight(0, 0).unwrap();
|
||||
test_modal.gam.relinquish_focus().unwrap();
|
||||
log::info!("test done, relinquishing focus");
|
||||
test_finished = true;
|
||||
}
|
||||
} else {
|
||||
// simply ignore the reports in
|
||||
// we have to register our key listener early on, otherwise the rootkeys won't work for normal use
|
||||
// we do want the keyboard listener slots to be fully occupied, otherwise something nefarious could
|
||||
// squat the unused port...
|
||||
}
|
||||
},
|
||||
Some(OqcOp::Status) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
let _ = match passing {
|
||||
None => xous::return_scalar(msg.sender, 0),
|
||||
Some(true) => xous::return_scalar(msg.sender, 1),
|
||||
Some(false) => xous::return_scalar(msg.sender, 2),
|
||||
};
|
||||
}),
|
||||
Some(OqcOp::UxGutter) => {
|
||||
// log::info!("gutter");
|
||||
// an intentional NOP for UX actions that require a destintation but need no action
|
||||
},
|
||||
Some(OqcOp::ModalRedraw) => {
|
||||
// log::info!("modal redraw handler");
|
||||
// test_modal.redraw();
|
||||
},
|
||||
Some(OqcOp::ModalKeys) => xous::msg_scalar_unpack!(msg, _k1, _k2, _k3, _k4, {
|
||||
// log::info!("modal keys message, ignoring");
|
||||
// ignore keys, we have our own key routine
|
||||
}),
|
||||
Some(OqcOp::ModalDrop) => {
|
||||
log::error!("test modal quit unexpectedly");
|
||||
}
|
||||
Some(OqcOp::Quit) => {
|
||||
log::warn!("Quit received on OQC");
|
||||
break;
|
||||
}
|
||||
None => {
|
||||
log::error!("couldn't convert OqcOp: {:?}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up our program
|
||||
log::trace!("main loop exit, destroying servers");
|
||||
xns.unregister_server(oqc_sid).unwrap();
|
||||
xous::destroy_server(oqc_sid).unwrap();
|
||||
log::trace!("quitting");
|
||||
xous::terminate_process(0)
|
||||
}
|
||||
|
||||
fn populate_vectors() -> Vec::<(RowCol, bool)> {
|
||||
let mut vectors = Vec::<(RowCol, bool)>::new();
|
||||
vectors.push((RowCol::new(0, 0), false));
|
||||
vectors.push((RowCol::new(0, 1), false));
|
||||
vectors.push((RowCol::new(0, 2), false));
|
||||
vectors.push((RowCol::new(0, 3), false));
|
||||
vectors.push((RowCol::new(0, 4), false));
|
||||
vectors.push((RowCol::new(4, 5), false));
|
||||
vectors.push((RowCol::new(4, 6), false));
|
||||
vectors.push((RowCol::new(4, 7), false));
|
||||
vectors.push((RowCol::new(4, 8), false));
|
||||
vectors.push((RowCol::new(4, 9), false));
|
||||
vectors.push((RowCol::new(1, 0), false));
|
||||
vectors.push((RowCol::new(1, 1), false));
|
||||
vectors.push((RowCol::new(1, 2), false));
|
||||
vectors.push((RowCol::new(1, 3), false));
|
||||
vectors.push((RowCol::new(1, 4), false));
|
||||
vectors.push((RowCol::new(5, 5), false));
|
||||
vectors.push((RowCol::new(5, 6), false));
|
||||
vectors.push((RowCol::new(5, 7), false));
|
||||
vectors.push((RowCol::new(5, 8), false));
|
||||
vectors.push((RowCol::new(5, 9), false));
|
||||
vectors.push((RowCol::new(2, 0), false));
|
||||
vectors.push((RowCol::new(2, 1), false));
|
||||
vectors.push((RowCol::new(2, 2), false));
|
||||
vectors.push((RowCol::new(2, 3), false));
|
||||
vectors.push((RowCol::new(2, 4), false));
|
||||
vectors.push((RowCol::new(6, 5), false));
|
||||
vectors.push((RowCol::new(6, 6), false));
|
||||
vectors.push((RowCol::new(6, 7), false));
|
||||
vectors.push((RowCol::new(6, 8), false));
|
||||
vectors.push((RowCol::new(6, 9), false));
|
||||
vectors.push((RowCol::new(3, 0), false));
|
||||
vectors.push((RowCol::new(3, 1), false));
|
||||
vectors.push((RowCol::new(3, 2), false));
|
||||
vectors.push((RowCol::new(3, 3), false));
|
||||
vectors.push((RowCol::new(3, 4), false));
|
||||
vectors.push((RowCol::new(7, 5), false));
|
||||
vectors.push((RowCol::new(7, 6), false));
|
||||
vectors.push((RowCol::new(7, 7), false));
|
||||
vectors.push((RowCol::new(7, 8), false));
|
||||
vectors.push((RowCol::new(7, 9), false));
|
||||
vectors.push((RowCol::new(8, 5), false));
|
||||
vectors.push((RowCol::new(8, 6), false));
|
||||
vectors.push((RowCol::new(8, 7), false));
|
||||
vectors.push((RowCol::new(8, 8), false));
|
||||
vectors.push((RowCol::new(8, 9), false));
|
||||
vectors.push((RowCol::new(8, 0), false));
|
||||
vectors.push((RowCol::new(8, 1), false));
|
||||
vectors.push((RowCol::new(3, 8), false));
|
||||
vectors.push((RowCol::new(3, 9), false));
|
||||
vectors.push((RowCol::new(8, 3), false));
|
||||
vectors.push((RowCol::new(3, 6), false));
|
||||
vectors.push((RowCol::new(6, 4), false));
|
||||
vectors.push((RowCol::new(8, 2), false));
|
||||
vectors.push((RowCol::new(5, 2), false));
|
||||
|
||||
vectors
|
||||
}
|
||||
|
||||
fn map_codes(code: RowCol) -> &'static str {
|
||||
let rc = (code.r, code.c);
|
||||
|
||||
match rc {
|
||||
(0, 0) => "1",
|
||||
(0, 1) => "2",
|
||||
(0, 2) => "3",
|
||||
(0, 3) => "4",
|
||||
(0, 4) => "5",
|
||||
(4, 5) => "6",
|
||||
(4, 6) => "7",
|
||||
(4, 7) => "8",
|
||||
(4, 8) => "9",
|
||||
(4, 9) => "0",
|
||||
(1, 0) => "q",
|
||||
(1, 1) => "w",
|
||||
(1, 2) => "e",
|
||||
(1, 3) => "r",
|
||||
(1, 4) => "t",
|
||||
(5, 5) => "y",
|
||||
(5, 6) => "u",
|
||||
(5, 7) => "i",
|
||||
(5, 8) => "o",
|
||||
(5, 9) => "p",
|
||||
(2, 0) => "a",
|
||||
(2, 1) => "s",
|
||||
(2, 2) => "d",
|
||||
(2, 3) => "f",
|
||||
(2, 4) => "g",
|
||||
(6, 5) => "h",
|
||||
(6, 6) => "j",
|
||||
(6, 7) => "k",
|
||||
(6, 8) => "l",
|
||||
(6, 9) => "BS",
|
||||
(3, 0) => "!",
|
||||
(3, 1) => "z",
|
||||
(3, 2) => "x",
|
||||
(3, 3) => "c",
|
||||
(3, 4) => "v",
|
||||
(7, 5) => "b",
|
||||
(7, 6) => "n",
|
||||
(7, 7) => "m",
|
||||
(7, 8) => "?",
|
||||
//(7, 9) => "↩️",
|
||||
(7, 9) => "RET",
|
||||
|
||||
(8, 5) => "LS",
|
||||
(8, 6) => ",",
|
||||
(8, 7) => "SP",
|
||||
(8, 8) => ".",
|
||||
(8, 9) => "RS",
|
||||
(8, 0) => "F1",
|
||||
(8, 1) => "F2",
|
||||
(3, 8) => "F3",
|
||||
(3, 9) => "F4",
|
||||
//(8, 3) => "⬅️",
|
||||
(8, 3) => "LT",
|
||||
//(3, 6) => "➡️",
|
||||
(3, 6) => "RT",
|
||||
//(6, 4) => "⬆️",
|
||||
(6, 4) => "UP",
|
||||
//(8, 2) => "⬇️",
|
||||
(8, 2) => "DN",
|
||||
(5, 2) => "MID",
|
||||
_ => "ERR!",
|
||||
}
|
||||
}
|
||||
|
||||
fn render_string(txt: &mut String, remaining: &Vec::<(RowCol, bool)>, time_remaining: u64) {
|
||||
txt.clear();
|
||||
let mut keyrowstrs: [String; 7] = [
|
||||
String::new(),
|
||||
String::new(),
|
||||
String::new(),
|
||||
String::new(),
|
||||
String::new(),
|
||||
String::new(),
|
||||
String::new(),
|
||||
];
|
||||
for &(code, was_hit) in remaining.iter() {
|
||||
if !was_hit {
|
||||
// lookup table to help organize the key hits remaining
|
||||
let draw_row = match code.r {
|
||||
0 | 4 => 2,
|
||||
1 => 3,
|
||||
5 => if code.c != 2 {3} else {0},
|
||||
2 => 4,
|
||||
6 => if code.c != 4 {4} else {0},
|
||||
3 => if code.c <= 4 {5} else { if code.c == 6 {0} else {1} }
|
||||
7 => 5,
|
||||
8 => if code.c >= 5 {6} else { if code.c <= 1 {1} else {0} },
|
||||
_ => 6,
|
||||
};
|
||||
keyrowstrs[draw_row].push_str(map_codes(code));
|
||||
keyrowstrs[draw_row].push_str(" ");
|
||||
}
|
||||
}
|
||||
for s in keyrowstrs.iter() {
|
||||
txt.push_str(s);
|
||||
txt.push('\n');
|
||||
}
|
||||
txt.push_str("Timeout: ");
|
||||
txt.push_str(&(time_remaining / 1000).to_string());
|
||||
txt.push_str("s");
|
||||
//txt.push_str("\n\n\n\n");
|
||||
}
|
||||
|
||||
fn ping_thread(conn: usize, timeout: usize) {
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
let start = tt.elapsed_ms();
|
||||
let mut krs_ser: [(u8, u8); 32] = [(255, 255); 32];
|
||||
krs_ser[0] = (254, 254);
|
||||
while tt.elapsed_ms() - start < timeout as u64 {
|
||||
tt.sleep_ms(2000).unwrap();
|
||||
let buf = xous_ipc::Buffer::into_buf(krs_ser).or(Err(xous::Error::InternalError)).expect("couldn't serialize krs buffer");
|
||||
buf.send(conn as xous::CID, OqcOp::KeyCode.to_u32().unwrap()).expect("couldn't send raw scancodes");
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
"keyboard",
|
||||
"trng",
|
||||
"llio",
|
||||
//"rtc",
|
||||
"susres",
|
||||
"codec",
|
||||
"sha2",
|
||||
|
|
@ -56,7 +55,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
"spinor",
|
||||
"root-keys",
|
||||
"jtag",
|
||||
"oqc-test",
|
||||
"net",
|
||||
"dns",
|
||||
"pddb",
|
||||
|
|
|
|||
Loading…
Reference in a new issue