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",
"log",
"log-server",
"modals",
"net",
"num-derive",
"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.
const TOKEN_SLOTS: usize = 9;
const TOKEN_SLOTS: usize = 8;
const EXPECTED_BOOT_CONTEXTS: [&'static str; TOKEN_SLOTS] = [
"shellchat",
"main menu",
@ -20,7 +20,6 @@ const EXPECTED_BOOT_CONTEXTS: [&'static str; TOKEN_SLOTS] = [
"emoji menu",
"rootkeys modal",
"rootkeys menu",
"test modal",
"pddb modal",
"shared modal",
];

View file

@ -51,6 +51,16 @@ pub struct ManagedProgress {
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)]
pub(crate) enum Opcode {
// these are blocking calls
@ -62,10 +72,12 @@ pub(crate) enum Opcode {
PromptWithTextResponse,
/// simple notification
Notification,
/// dynamic notification - a simple non-interactive notification that allows its text to be dynamically updated
DynamicNotification,
// these are non-blocking calls
/// 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,
/// raise a progress bar
StartProgress,
@ -73,6 +85,10 @@ pub(crate) enum Opcode {
UpdateProgress,
/// lower a progress bar
StopProgress,
/// update a dynamic notification's text
UpdateDynamicNotification,
/// close dynamic notification
CloseDynamicNotification,
GetMutex,

View file

@ -177,6 +177,40 @@ impl Modals {
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
fn lock(&self) {
while !self.try_get_mutex() {

View file

@ -30,6 +30,7 @@ enum RendererState {
ResponseText(TextEntryPayload),
ResponseRadio(ItemName),
ResponseCheckBox(CheckBoxPayload),
RunDynamicNotification(DynamicNotification),
}
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
@ -45,10 +46,14 @@ pub(crate) enum RendererOp {
AddModalItem,
UpdateDynamicNotification,
CloseDynamicNotification,
ModalRedraw,
ModalKeypress,
ModalDrop,
Quit,
Gutter,
}
#[xous::xous_main]
@ -85,6 +90,11 @@ fn xmain() -> ! {
renderer_cid,
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(),
0, 100, 1, Some("%"), 0, true, true
);
@ -111,18 +121,18 @@ fn xmain() -> ! {
log::debug!("renderer message: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) {
Some(RendererOp::InitiateOp) => {
log::info!("InitiateOp called");
log::debug!("InitiateOp called");
let mutex_op = op.lock().unwrap();
match *mutex_op {
RendererState::RunText(config) => {
log::info!("initiating text entry modal");
log::debug!("initiating text entry modal");
renderer_modal.modify(
Some(ActionType::TextEntry(text_action)),
Some(config.prompt.as_str().unwrap()), false,
None, true, None
);
renderer_modal.activate();
log::info!("should be active!");
log::debug!("should be active!");
},
RendererState::RunNotification(config) => {
renderer_modal.modify(
@ -137,7 +147,7 @@ fn xmain() -> ! {
end_work = config.end_work;
last_percentage = compute_checked_percentage(
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);
renderer_modal.modify(
@ -179,6 +189,23 @@ fn xmain() -> ! {
);
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 => {
log::error!("Operation initiated with no argument specified. Ignoring request.");
continue;
@ -209,6 +236,35 @@ fn xmain() -> ! {
Some(RendererOp::FinishProgress) => {
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) => {
let mut mutex_op = op.lock().unwrap();
match *mutex_op {
@ -258,6 +314,9 @@ fn xmain() -> ! {
}
}
},
Some(RendererOp::Gutter) => {
log::info!("gutter op, doing nothing");
},
Some(RendererOp::AddModalItem) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let item = buffer.to_original::<ItemName, _>().unwrap();
@ -499,6 +558,44 @@ fn xmain() -> ! {
let fwd_buf = Buffer::into_buf(manageditem.item).unwrap();
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) => {
log::warn!("Shared modal UX handler exiting.");
break

View file

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

View file

@ -1,5 +1,4 @@
use num_traits::*;
use gam::modal::*;
use keyboard::{RowCol, KeyRawStates};
use core::sync::atomic::{AtomicU32, Ordering, AtomicBool};
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 llio = llio::Llio::new(&xns);
let gam = gam::Gam::new(&xns).unwrap();
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 modal = modals::Modals::new(&xns).unwrap();
let mut test_run = false;
let mut remaining = populate_vectors();
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()) {
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
gam.selftest(8_000); // 12_000 by default
// now start the keyboard test
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;
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();
modal.dynamic_notification(None, Some(bot_str.as_str())).expect("couldn't raise test modal");
// 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();
@ -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
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();
modal.dynamic_notification_update(None, Some(bot_str.as_str())).expect("couldn't update test modal");
last_redraw_time = elapsed;
llio.vibe(llio::VibePattern::Short).unwrap();
}
@ -156,7 +131,7 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
if finished {
passing = Some(true);
com.set_backlight(0, 0).unwrap();
test_modal.gam.relinquish_focus().unwrap();
modal.dynamic_notification_close().unwrap();
log::info!("all keys hit, exiting");
test_finished = true;
}
@ -164,7 +139,7 @@ pub(crate) fn oqc_test(oqc_cid: Arc<AtomicU32>, kbd: keyboard::Keyboard) {
// timeout
passing = Some(false);
com.set_backlight(0, 0).unwrap();
test_modal.gam.relinquish_focus().unwrap();
modal.dynamic_notification_close().unwrap();
log::info!("test done, relinquishing focus");
test_finished = true;
}