diff --git a/Cargo.lock b/Cargo.lock index 382f92652..78880695d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2540,6 +2540,7 @@ dependencies = [ "modals", "num-derive", "num-traits", + "pddb", "rkyv", "root-keys", "susres", diff --git a/services/modals/src/main.rs b/services/modals/src/main.rs index 2d103f593..f967f472a 100644 --- a/services/modals/src/main.rs +++ b/services/modals/src/main.rs @@ -17,6 +17,7 @@ use gam::modal::*; use num_traits::*; +#[derive(Debug)] enum RendererState { /// idle state None, @@ -309,7 +310,7 @@ fn xmain() -> ! { match *mutex_op { RendererState::RunNotification(_) => *mutex_op = RendererState::None, _ => { - log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error."); + log::error!("UX return opcode does not match our current operation in flight: {:?}", mutex_op); panic!("UX return opcode does not match our current operation in flight. This is a serious internal error."); } } diff --git a/services/pddb/locales/i18n.json b/services/pddb/locales/i18n.json index a5edb7101..c4ba397c4 100644 --- a/services/pddb/locales/i18n.json +++ b/services/pddb/locales/i18n.json @@ -98,5 +98,10 @@ "en": "List unlocked bases", "zh": "基础列表", "en-audio": "List unlocked bases" + }, + "pddb.menu.listbasis_response": { + "en": "Unlocked bases:\n", + "zh": "透露列表:\n", + "en-audio": "Unlocked bases:" } } \ No newline at end of file diff --git a/services/pddb/src/api.rs b/services/pddb/src/api.rs index 01695b849..a441bcbae 100644 --- a/services/pddb/src/api.rs +++ b/services/pddb/src/api.rs @@ -72,6 +72,8 @@ pub(crate) const BCRYPT_COST: u32 = 7; // 10 is the minimum recommended by OWA #[allow(dead_code)] pub(crate) const PDDB_MODAL_NAME: &'static str = "pddb modal"; +#[allow(dead_code)] +pub const PDDB_MENU_NAME: &'static str = "pddb menu"; #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] pub(crate) enum Opcode { diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 308769f20..84f701d1f 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -1022,7 +1022,12 @@ fn xmain() -> ! { }; }), Some(Opcode::MenuListBasis) => { - unimplemented!(); + let bases = basis_cache.basis_list(); + let mut note = String::from(t!("pddb.menu.listbasis_response", xous::LANG)); + for basis in bases.iter() { + note.push_str(basis); + } + modals.show_notification(¬e).expect("couldn't show basis list"); }, Some(Opcode::Quit) => { log::warn!("quitting the PDDB server"); diff --git a/services/pddb/src/menu.rs b/services/pddb/src/menu.rs index 1fa013022..0b0d4eab3 100644 --- a/services/pddb/src/menu.rs +++ b/services/pddb/src/menu.rs @@ -1,17 +1,13 @@ -use xous::msg_scalar_unpack; +use gam::*; use num_traits::*; -use xous_ipc::String; use locales::t; use crate::api::*; - -use gam::*; - -pub(crate) const PDDB_MENU_NAME: &'static str = "pddb menu"; +use xous_ipc::String; pub(crate) fn pddb_menu(conn: xous::CID) { - let mut menu = Menu::new(PDDB_MENU_NAME); + let mut menu_items = Vec::::new(); - menu.add_item( + menu_items.push( MenuItem { name: String::from_str(t!("pddb.menu.listbasis", xous::LANG)), action_conn: Some(conn), @@ -20,47 +16,13 @@ pub(crate) fn pddb_menu(conn: xous::CID) { close_on_select: true, } ); - loop { - let msg = xous::receive_message(menu.sid).unwrap(); - log::trace!("message: {:?}", msg); - match FromPrimitive::from_usize(msg.body.id()) { - Some(MenuOpcode::Redraw) => { - menu.redraw(); - }, - Some(MenuOpcode::Rawkeys) => msg_scalar_unpack!(msg, k1, k2, k3, k4, { - let keys = [ - if let Some(a) = core::char::from_u32(k1 as u32) { - a - } else { - '\u{0000}' - }, - if let Some(a) = core::char::from_u32(k2 as u32) { - a - } else { - '\u{0000}' - }, - if let Some(a) = core::char::from_u32(k3 as u32) { - a - } else { - '\u{0000}' - }, - if let Some(a) = core::char::from_u32(k4 as u32) { - a - } else { - '\u{0000}' - }, - ]; - menu.key_event(keys); - }), - Some(MenuOpcode::Quit) => { - break; - }, - None => { - log::error!("unknown opcode {:?}", msg.body.id()); - } - } - } - log::trace!("menu thread exit, destroying servers"); - // do we want to add a deregister_ux call to the system? - xous::destroy_server(menu.sid).unwrap(); + menu_items.push(MenuItem { + name: String::from_str(t!("mainmenu.closemenu", xous::LANG)), + action_conn: None, + action_opcode: 0, + action_payload: MenuPayload::Scalar([0, 0, 0, 0]), + close_on_select: true, + }); + + menu_matic(menu_items, PDDB_MENU_NAME, None); } \ No newline at end of file diff --git a/services/status/Cargo.toml b/services/status/Cargo.toml index f3285a619..f55d55439 100644 --- a/services/status/Cargo.toml +++ b/services/status/Cargo.toml @@ -24,6 +24,7 @@ locales = {path = "../../locales"} susres = {path = "../susres"} root-keys = {path = "../root-keys"} modals = {path = "../modals"} +pddb = {path = "../pddb"} num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} diff --git a/services/status/locales/i18n.json b/services/status/locales/i18n.json index 51099332e..2dc4cde7f 100644 --- a/services/status/locales/i18n.json +++ b/services/status/locales/i18n.json @@ -64,6 +64,11 @@ "zh": "设置时间", "en-audio": "Set time" }, + "mainmenu.pddb": { + "en": "PDDB Submenu", + "zh": "PDDB子菜单", + "en-audio": "PDDB submenu" + }, "mainmenu.reboot": { "en": "Reboot", "zh": "重启", diff --git a/services/status/src/main.rs b/services/status/src/main.rs index ff316313d..52a193eb1 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -43,6 +43,8 @@ enum StatusOpcode { UxSetTime, /// Initiates a reboot Reboot, + /// Raise the PDDB menu + SubmenuPddb, /// Suspend handler from the main menu TrySuspend, Quit, @@ -620,6 +622,9 @@ fn xmain() -> ! { panic!("system did not reboot"); } } + Some(StatusOpcode::SubmenuPddb) => { + gam.raise_menu(pddb::PDDB_MENU_NAME).expect("couldn't raise PDDB submenu"); + }, Some(StatusOpcode::TrySuspend) => { if ((llio.adc_vbus().unwrap() as f64) * 0.005033) > 1.5 { modals.show_notification(t!("mainmenu.cant_sleep", xous::LANG)).expect("couldn't notify that power is plugged in"); diff --git a/services/status/src/mainmenu.rs b/services/status/src/mainmenu.rs index bcfed0477..d003386d1 100644 --- a/services/status/src/mainmenu.rs +++ b/services/status/src/mainmenu.rs @@ -79,12 +79,20 @@ pub fn create_main_menu(keys: Arc>, status_conn: xous::CID, com: close_on_select: true, }); + menuitems.push(MenuItem { + name: String::from_str(t!("mainmenu.pddb", xous::LANG)), + action_conn: Some(status_conn), + action_opcode: StatusOpcode::SubmenuPddb.to_u32().unwrap(), + action_payload: MenuPayload::Scalar([0, 0, 0, 0]), + close_on_select: true, + }); + menuitems.push(MenuItem { name: String::from_str(t!("mainmenu.closemenu", xous::LANG)), action_conn: None, action_opcode: 0, action_payload: MenuPayload::Scalar([0, 0, 0, 0]), - close_on_select: true, // don't close because we're already closing + close_on_select: true, }); menu_matic(menuitems, MAIN_MENU_NAME, None);