cleann up the oqc test

This commit is contained in:
bunnie 2022-01-12 02:01:33 +08:00
parent c43e31c500
commit a8d7c7e9e2
7 changed files with 162 additions and 39 deletions

1
Cargo.lock generated
View file

@ -1978,6 +1978,7 @@ dependencies = [
"llio", "llio",
"log", "log",
"log-server", "log-server",
"modals",
"net", "net",
"num-derive", "num-derive",
"num-traits", "num-traits",

View file

@ -12,7 +12,7 @@ use xous_ipc::String;
*/ */
// if you add more UxContexts, and you want them authorized by the GAM, add their names here. // if you add more UxContexts, and you want them authorized by the GAM, add their names here.
const TOKEN_SLOTS: usize = 9; const TOKEN_SLOTS: usize = 8;
const EXPECTED_BOOT_CONTEXTS: [&'static str; TOKEN_SLOTS] = [ const EXPECTED_BOOT_CONTEXTS: [&'static str; TOKEN_SLOTS] = [
"shellchat", "shellchat",
"main menu", "main menu",
@ -20,7 +20,6 @@ const EXPECTED_BOOT_CONTEXTS: [&'static str; TOKEN_SLOTS] = [
"emoji menu", "emoji menu",
"rootkeys modal", "rootkeys modal",
"rootkeys menu", "rootkeys menu",
"test modal",
"pddb modal", "pddb modal",
"shared modal", "shared modal",
]; ];

View file

@ -51,6 +51,16 @@ pub struct ManagedProgress {
pub current_work: u32, pub current_work: u32,
} }
/// This isn't a terribly useful notification -- it's basically read-only, no interactivity,
/// but you can animate the text. Mainly used for testing routines. Might be modifiable
/// into something more useful with a bit of thought, but for now, MVP.
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
pub struct DynamicNotification {
pub token: [u32; 4],
pub title: Option<xous_ipc::String::<1024>>,
pub text: Option<xous_ipc::String::<2048>>,
}
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum Opcode { pub(crate) enum Opcode {
// these are blocking calls // these are blocking calls
@ -62,10 +72,12 @@ pub(crate) enum Opcode {
PromptWithTextResponse, PromptWithTextResponse,
/// simple notification /// simple notification
Notification, Notification,
/// dynamic notification - a simple non-interactive notification that allows its text to be dynamically updated
DynamicNotification,
// these are non-blocking calls // these are non-blocking calls
/// add an item to the radio box or check box. Note that all added items /// add an item to the radio box or check box. Note that all added items
/// are cleared after the relevant "action" call happens (PrmoptWith[Fixed,Multi]Response) /// are cleared after the relevant "action" call happens (PromptWith[Fixed,Multi]Response)
AddModalItem, AddModalItem,
/// raise a progress bar /// raise a progress bar
StartProgress, StartProgress,
@ -73,6 +85,10 @@ pub(crate) enum Opcode {
UpdateProgress, UpdateProgress,
/// lower a progress bar /// lower a progress bar
StopProgress, StopProgress,
/// update a dynamic notification's text
UpdateDynamicNotification,
/// close dynamic notification
CloseDynamicNotification,
GetMutex, GetMutex,

View file

@ -177,6 +177,40 @@ impl Modals {
Ok(ret) Ok(ret)
} }
pub fn dynamic_notification(&self, title: Option<&str>, text: Option<&str>) -> Result<(), xous::Error> {
self.lock();
let spec = DynamicNotification {
token: self.token,
title: if let Some(t) = title {Some(xous_ipc::String::from_str(t))} else {None},
text: if let Some(t) = text {Some(xous_ipc::String::from_str(t))} else {None},
};
let buf = Buffer::into_buf(spec).or(Err(xous::Error::InternalError))?;
buf.lend(self.conn, Opcode::DynamicNotification.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
Ok(())
}
pub fn dynamic_notification_update(&self, title: Option<&str>, text: Option<&str>) -> Result<(), xous::Error> {
let spec = DynamicNotification {
token: self.token,
title: if let Some(t) = title {Some(xous_ipc::String::from_str(t))} else {None},
text: if let Some(t) = text {Some(xous_ipc::String::from_str(t))} else {None},
};
let buf = Buffer::into_buf(spec).or(Err(xous::Error::InternalError))?;
buf.lend(self.conn, Opcode::UpdateDynamicNotification.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
Ok(())
}
pub fn dynamic_notification_close(&self) -> Result<(), xous::Error> {
self.lock();
send_message(self.conn,
Message::new_scalar(Opcode::CloseDynamicNotification.to_usize().unwrap(),
self.token[0] as usize,
self.token[1] as usize,
self.token[2] as usize,
self.token[3] as usize,
)
).expect("couldn't stop progress");
Ok(())
}
/// busy-wait until we have acquired a mutex on the Modals server /// busy-wait until we have acquired a mutex on the Modals server
fn lock(&self) { fn lock(&self) {
while !self.try_get_mutex() { while !self.try_get_mutex() {

View file

@ -30,6 +30,7 @@ enum RendererState {
ResponseText(TextEntryPayload), ResponseText(TextEntryPayload),
ResponseRadio(ItemName), ResponseRadio(ItemName),
ResponseCheckBox(CheckBoxPayload), ResponseCheckBox(CheckBoxPayload),
RunDynamicNotification(DynamicNotification),
} }
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
@ -45,10 +46,14 @@ pub(crate) enum RendererOp {
AddModalItem, AddModalItem,
UpdateDynamicNotification,
CloseDynamicNotification,
ModalRedraw, ModalRedraw,
ModalKeypress, ModalKeypress,
ModalDrop, ModalDrop,
Quit, Quit,
Gutter,
} }
#[xous::xous_main] #[xous::xous_main]
@ -85,6 +90,11 @@ fn xmain() -> ! {
renderer_cid, renderer_cid,
RendererOp::NotificationReturn.to_u32().unwrap() RendererOp::NotificationReturn.to_u32().unwrap()
); );
let mut gutter = gam::modal::Notification::new(
renderer_cid,
RendererOp::Gutter.to_u32().unwrap()
);
gutter.set_manual_dismiss(false);
let mut progress_action = Slider::new(renderer_cid, RendererOp::NotificationReturn.to_u32().unwrap(), let mut progress_action = Slider::new(renderer_cid, RendererOp::NotificationReturn.to_u32().unwrap(),
0, 100, 1, Some("%"), 0, true, true 0, 100, 1, Some("%"), 0, true, true
); );
@ -111,18 +121,18 @@ fn xmain() -> ! {
log::debug!("renderer message: {:?}", msg); log::debug!("renderer message: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) { match FromPrimitive::from_usize(msg.body.id()) {
Some(RendererOp::InitiateOp) => { Some(RendererOp::InitiateOp) => {
log::info!("InitiateOp called"); log::debug!("InitiateOp called");
let mutex_op = op.lock().unwrap(); let mutex_op = op.lock().unwrap();
match *mutex_op { match *mutex_op {
RendererState::RunText(config) => { RendererState::RunText(config) => {
log::info!("initiating text entry modal"); log::debug!("initiating text entry modal");
renderer_modal.modify( renderer_modal.modify(
Some(ActionType::TextEntry(text_action)), Some(ActionType::TextEntry(text_action)),
Some(config.prompt.as_str().unwrap()), false, Some(config.prompt.as_str().unwrap()), false,
None, true, None None, true, None
); );
renderer_modal.activate(); renderer_modal.activate();
log::info!("should be active!"); log::debug!("should be active!");
}, },
RendererState::RunNotification(config) => { RendererState::RunNotification(config) => {
renderer_modal.modify( renderer_modal.modify(
@ -137,7 +147,7 @@ fn xmain() -> ! {
end_work = config.end_work; end_work = config.end_work;
last_percentage = compute_checked_percentage( last_percentage = compute_checked_percentage(
config.current_work, start_work, end_work); config.current_work, start_work, end_work);
log::info!("init percentage: {}, current: {}, start: {}, end: {}", last_percentage, config.current_work, start_work, end_work); log::debug!("init percentage: {}, current: {}, start: {}, end: {}", last_percentage, config.current_work, start_work, end_work);
progress_action.set_state(last_percentage); progress_action.set_state(last_percentage);
renderer_modal.modify( renderer_modal.modify(
@ -179,6 +189,23 @@ fn xmain() -> ! {
); );
renderer_modal.activate(); renderer_modal.activate();
}, },
RendererState::RunDynamicNotification(config) => {
let mut top_text = String::new();
if let Some(title) = config.title {
top_text.push_str(title.as_str().unwrap());
}
let mut bot_text = String::new();
if let Some(text) = config.text {
bot_text.push_str(text.as_str().unwrap());
}
renderer_modal.modify(
Some(ActionType::Notification(gutter)),
Some(&top_text), config.title.is_none(),
Some(&bot_text), config.text.is_none(),
None
);
renderer_modal.activate();
},
RendererState::None => { RendererState::None => {
log::error!("Operation initiated with no argument specified. Ignoring request."); log::error!("Operation initiated with no argument specified. Ignoring request.");
continue; continue;
@ -209,6 +236,35 @@ fn xmain() -> ! {
Some(RendererOp::FinishProgress) => { Some(RendererOp::FinishProgress) => {
renderer_modal.gam.relinquish_focus().unwrap(); renderer_modal.gam.relinquish_focus().unwrap();
}, },
Some(RendererOp::UpdateDynamicNotification) => {
let mutex_op = op.lock().unwrap();
match *mutex_op {
RendererState::RunDynamicNotification(config) => {
let mut top_text = String::new();
if let Some(title) = config.title {
top_text.push_str(title.as_str().unwrap());
}
let mut bot_text = String::new();
if let Some(text) = config.text {
bot_text.push_str(text.as_str().unwrap());
}
renderer_modal.modify(
None,
Some(&top_text), config.title.is_none(),
Some(&bot_text), config.text.is_none(),
None
);
renderer_modal.redraw();
}
_ => {
log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
panic!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
}
}
},
Some(RendererOp::CloseDynamicNotification) => {
renderer_modal.gam.relinquish_focus().unwrap();
},
Some(RendererOp::TextEntryReturn) => { Some(RendererOp::TextEntryReturn) => {
let mut mutex_op = op.lock().unwrap(); let mut mutex_op = op.lock().unwrap();
match *mutex_op { match *mutex_op {
@ -258,6 +314,9 @@ fn xmain() -> ! {
} }
} }
}, },
Some(RendererOp::Gutter) => {
log::info!("gutter op, doing nothing");
},
Some(RendererOp::AddModalItem) => { Some(RendererOp::AddModalItem) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let item = buffer.to_original::<ItemName, _>().unwrap(); let item = buffer.to_original::<ItemName, _>().unwrap();
@ -499,6 +558,44 @@ fn xmain() -> ! {
let fwd_buf = Buffer::into_buf(manageditem.item).unwrap(); let fwd_buf = Buffer::into_buf(manageditem.item).unwrap();
fwd_buf.lend(renderer_cid, RendererOp::AddModalItem.to_u32().unwrap()).expect("couldn't add item"); fwd_buf.lend(renderer_cid, RendererOp::AddModalItem.to_u32().unwrap()).expect("couldn't add item");
} }
Some(Opcode::DynamicNotification) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let spec = buffer.to_original::<DynamicNotification, _>().unwrap();
if spec.token != token_lock.unwrap_or(default_nonce) {
log::warn!("Attempt to access modals without a mutex lock. Ignoring.");
continue;
}
*op.lock().unwrap() = RendererState::RunDynamicNotification(spec);
send_message(
renderer_cid,
Message::new_scalar(RendererOp::InitiateOp.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't initiate UX op");
},
Some(Opcode::UpdateDynamicNotification) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let spec = buffer.to_original::<DynamicNotification, _>().unwrap();
if spec.token != token_lock.unwrap_or(default_nonce) {
log::warn!("Attempt to access modals without a mutex lock. Ignoring.");
continue;
}
*op.lock().unwrap() = RendererState::RunDynamicNotification(spec);
send_message(
renderer_cid,
Message::new_scalar(RendererOp::UpdateDynamicNotification.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't initiate UX op");
},
Some(Opcode::CloseDynamicNotification) => msg_scalar_unpack!(msg, t0, t1, t2, t3, {
let token = [t0 as u32, t1 as u32, t2 as u32, t3 as u32];
if token != token_lock.unwrap_or(default_nonce) {
log::warn!("Attempt to access modals without a mutex lock. Ignoring.");
continue;
}
send_message(
renderer_cid,
Message::new_scalar(RendererOp::CloseDynamicNotification.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't close dynamic notification");
token_lock = None;
}),
Some(Opcode::Quit) => { Some(Opcode::Quit) => {
log::warn!("Shared modal UX handler exiting."); log::warn!("Shared modal UX handler exiting.");
break break

View file

@ -35,6 +35,7 @@ jtag = {path="../jtag"}
net = {path="../net"} net = {path="../net"}
dns = {path="../dns"} dns = {path="../dns"}
pddb = {path="../pddb"} pddb = {path="../pddb"}
modals = {path="../modals"}
trng = {path = "../trng"} trng = {path = "../trng"}

View file

@ -1,5 +1,4 @@
use num_traits::*; use num_traits::*;
use gam::modal::*;
use keyboard::{RowCol, KeyRawStates}; use keyboard::{RowCol, KeyRawStates};
use core::sync::atomic::{AtomicU32, Ordering, AtomicBool}; use core::sync::atomic::{AtomicU32, Ordering, AtomicBool};
use std::sync::Arc; use std::sync::Arc;
@ -38,21 +37,9 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
); );
let com = com::Com::new(&xns).unwrap(); let com = com::Com::new(&xns).unwrap();
let llio = llio::Llio::new(&xns); let llio = llio::Llio::new(&xns);
let gam = gam::Gam::new(&xns).unwrap();
let test_cid = xous::connect(oqc_sid).unwrap(); let modal = modals::Modals::new(&xns).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 test_run = false;
let mut remaining = populate_vectors(); let mut remaining = populate_vectors();
let mut bot_str = String::new(); let mut bot_str = String::new();
@ -69,15 +56,9 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
match FromPrimitive::from_usize(msg.body.id()) { match FromPrimitive::from_usize(msg.body.id()) {
Some(OqcOp::Trigger) => xous::msg_blocking_scalar_unpack!(msg, timeout_set, _, _, _, { Some(OqcOp::Trigger) => xous::msg_blocking_scalar_unpack!(msg, timeout_set, _, _, _, {
if !test_run { 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 // test the screen
com.set_backlight(255, 255).unwrap(); com.set_backlight(255, 255).unwrap();
test_modal.gam.selftest(8_000); // 12_000 by default gam.selftest(8_000); // 12_000 by default
// now start the keyboard test // now start the keyboard test
timeout = if timeout_set > 120_000 { timeout = if timeout_set > 120_000 {
@ -89,11 +70,7 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
last_redraw_time = start_time; last_redraw_time = start_time;
log::info!("raising modal"); log::info!("raising modal");
render_string(&mut bot_str, &remaining, timeout - (ticktimer.elapsed_ms() - start_time)); render_string(&mut bot_str, &remaining, timeout - (ticktimer.elapsed_ms() - start_time));
test_modal.modify(None, None, false, modal.dynamic_notification(None, Some(bot_str.as_str())).expect("couldn't raise test modal");
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 // 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::create_thread_2(ping_thread, xous::connect(oqc_sid).unwrap() as usize, timeout as usize).unwrap();
@ -137,9 +114,7 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
} }
if elapsed - last_redraw_time > 100 { // rate limit redraws to 10Hz if elapsed - last_redraw_time > 100 { // rate limit redraws to 10Hz
render_string(&mut bot_str, &remaining, timeout - (elapsed - start_time)); render_string(&mut bot_str, &remaining, timeout - (elapsed - start_time));
test_modal.modify(None, None, false, modal.dynamic_notification_update(None, Some(bot_str.as_str())).expect("couldn't update test modal");
Some(bot_str.as_str()), false, None);
test_modal.redraw();
last_redraw_time = elapsed; last_redraw_time = elapsed;
llio.vibe(llio::VibePattern::Short).unwrap(); llio.vibe(llio::VibePattern::Short).unwrap();
} }
@ -156,7 +131,7 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
if finished { if finished {
passing = Some(true); passing = Some(true);
com.set_backlight(0, 0).unwrap(); com.set_backlight(0, 0).unwrap();
test_modal.gam.relinquish_focus().unwrap(); modal.dynamic_notification_close().unwrap();
log::info!("all keys hit, exiting"); log::info!("all keys hit, exiting");
test_finished = true; test_finished = true;
} }
@ -164,7 +139,7 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
// timeout // timeout
passing = Some(false); passing = Some(false);
com.set_backlight(0, 0).unwrap(); com.set_backlight(0, 0).unwrap();
test_modal.gam.relinquish_focus().unwrap(); modal.dynamic_notification_close().unwrap();
log::info!("test done, relinquishing focus"); log::info!("test done, relinquishing focus");
test_finished = true; test_finished = true;
} }