mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-13 07:48:30 +00:00
feat: move time-related preferences under the Preferences menu
Time UX thread is now started from the preference manager. PDDB is still handled in time.rs, but I'm working on that.
This commit is contained in:
parent
85b55798cf
commit
6176987fec
3 changed files with 66 additions and 37 deletions
|
|
@ -312,11 +312,7 @@ fn wrapped_main() -> ! {
|
|||
t!("secnote.usb_unlock", xous::LANG).to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
// --------------------------- spawn a time UX manager thread
|
||||
let time_sid = xous::create_server().unwrap();
|
||||
let time_cid = xous::connect(time_sid).unwrap();
|
||||
time::start_time_ux(time_sid);
|
||||
|
||||
// this is used by the main loop to get the localtime to show on the status bar
|
||||
let mut localtime = llio::LocalTime::new();
|
||||
|
||||
|
|
@ -334,7 +330,7 @@ fn wrapped_main() -> ! {
|
|||
log::debug!("starting main menu thread");
|
||||
let main_menu_sid = xous::create_server().unwrap();
|
||||
let status_cid = xous::connect(status_sid).unwrap();
|
||||
let menu_manager = create_main_menu(keys.clone(), main_menu_sid, status_cid, &com, time_cid);
|
||||
let menu_manager = create_main_menu(keys.clone(), main_menu_sid, status_cid, &com);
|
||||
create_app_menu(xous::connect(status_sid).unwrap());
|
||||
let kbd = Arc::new(Mutex::new(keyboard::Keyboard::new(&xns).unwrap()));
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use num_traits::*;
|
|||
use crate::StatusOpcode;
|
||||
|
||||
#[allow(unused_variables)] // quiets a warning about unused com that is emitted in tts config. Would be nice to make this more targeted...
|
||||
pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, menu_management_sid: xous::SID, status_conn: xous::CID, com: &com::Com, time_ux_conn: xous::CID) -> MenuMatic {
|
||||
pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, menu_management_sid: xous::SID, status_conn: xous::CID, com: &com::Com) -> MenuMatic {
|
||||
let key_conn = keys.lock().unwrap().conn();
|
||||
|
||||
let mut menuitems = Vec::<MenuItem>::new();
|
||||
|
|
@ -100,21 +100,6 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, menu_management_sid: xous::S
|
|||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
|
||||
menuitems.push(MenuItem {
|
||||
name: String::from_str(t!("mainmenu.set_rtc", xous::LANG)),
|
||||
action_conn: Some(time_ux_conn),
|
||||
action_opcode: crate::time::TimeUxOp::SetTime.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
menuitems.push(MenuItem {
|
||||
name: String::from_str(t!("mainmenu.set_tz", xous::LANG)),
|
||||
action_conn: Some(time_ux_conn),
|
||||
action_opcode: crate::time::TimeUxOp::SetTimeZone.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
}
|
||||
|
||||
menuitems.push(MenuItem {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ enum DevicePrefsOp {
|
|||
AutobacklightTimeout,
|
||||
KeyboardLayout,
|
||||
WLANMenu,
|
||||
SetTime,
|
||||
SetTimezone,
|
||||
}
|
||||
|
||||
impl Display for DevicePrefsOp {
|
||||
|
|
@ -30,6 +32,8 @@ impl Display for DevicePrefsOp {
|
|||
Self::RadioOnOnBoot => write!(f, "Enable WiFi on boot"),
|
||||
Self::KeyboardLayout => write!(f, "Keyboard layout"),
|
||||
Self::WLANMenu => write!(f, "WLAN settings"),
|
||||
Self::SetTime => write!(f, "{}", t!("mainmenu.set_rtc", xous::LANG)),
|
||||
Self::SetTimezone => write!(f, "{}", t!("mainmenu.set_tz", xous::LANG)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +62,7 @@ struct DevicePrefs {
|
|||
modals: modals::Modals,
|
||||
gam: gam::Gam,
|
||||
kbd: keyboard::Keyboard,
|
||||
time_ux_cid: xous::CID,
|
||||
}
|
||||
|
||||
impl PrefHandler for DevicePrefs {
|
||||
|
|
@ -101,12 +106,13 @@ impl PrefHandler for DevicePrefs {
|
|||
}
|
||||
|
||||
impl DevicePrefs {
|
||||
fn new(xns: &xous_names::XousNames) -> Self {
|
||||
fn new(xns: &xous_names::XousNames, time_ux_cid: xous::CID) -> Self {
|
||||
Self {
|
||||
up: Manager::new(),
|
||||
modals: modals::Modals::new(&xns).unwrap(),
|
||||
gam: gam::Gam::new(&xns).unwrap(),
|
||||
kbd: keyboard::Keyboard::new(&xns).unwrap(),
|
||||
time_ux_cid,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,6 +126,8 @@ impl DevicePrefs {
|
|||
AutobacklightTimeout,
|
||||
KeyboardLayout,
|
||||
WLANMenu,
|
||||
SetTime,
|
||||
SetTimezone,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -131,6 +139,8 @@ impl DevicePrefs {
|
|||
DevicePrefsOp::AutobacklightTimeout => self.autobacklight_timeout(),
|
||||
DevicePrefsOp::KeyboardLayout => self.keyboard_layout(),
|
||||
DevicePrefsOp::WLANMenu => self.wlan_menu(),
|
||||
DevicePrefsOp::SetTime => self.set_time_menu(),
|
||||
DevicePrefsOp::SetTimezone => self.set_timezone_menu(),
|
||||
};
|
||||
|
||||
resp.unwrap_or_else(|error| self.show_error_modal(error));
|
||||
|
|
@ -228,40 +238,73 @@ impl DevicePrefs {
|
|||
}
|
||||
|
||||
fn wlan_menu(&self) -> Result<(), DevicePrefsError> {
|
||||
log::info!("wlan menu invoked");
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
self.gam.raise_menu(gam::WIFI_MENU_NAME).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_time_menu(&self) -> Result<(), DevicePrefsError> {
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
|
||||
xous::send_message(
|
||||
self.time_ux_cid,
|
||||
xous::Message::new_scalar(
|
||||
crate::time::TimeUxOp::SetTime.to_usize().unwrap(),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_timezone_menu(&self) -> Result<(), DevicePrefsError> {
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
|
||||
xous::send_message(
|
||||
self.time_ux_cid,
|
||||
xous::Message::new_scalar(
|
||||
crate::time::TimeUxOp::SetTimeZone.to_usize().unwrap(),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn keyboard_layout(&mut self) -> Result<(), DevicePrefsError> {
|
||||
let kl = self.up.keyboard_layout_or_default()?;
|
||||
|
||||
let mappings = vec![
|
||||
"QWERTY",
|
||||
"AZERTY",
|
||||
"QWERTZ",
|
||||
"Dvorak",
|
||||
];
|
||||
let mappings = vec!["QWERTY", "AZERTY", "QWERTZ", "Dvorak"];
|
||||
|
||||
self.modals
|
||||
.add_list(mappings.clone())
|
||||
.unwrap();
|
||||
self.modals.add_list(mappings.clone()).unwrap();
|
||||
|
||||
let new_result = self
|
||||
.modals
|
||||
.get_radiobutton(&format!("Current layout: {}", keyboard::KeyMap::from(kl)))
|
||||
.unwrap();
|
||||
|
||||
let new_result = match mappings.iter().position(|&elem| elem == new_result.as_str()) {
|
||||
|
||||
let new_result = match mappings
|
||||
.iter()
|
||||
.position(|&elem| elem == new_result.as_str())
|
||||
{
|
||||
Some(val) => val,
|
||||
None => 0,
|
||||
};
|
||||
|
||||
self.up.set_keyboard_layout(new_result)?;
|
||||
|
||||
self.kbd.set_keymap(keyboard::KeyMap::from(new_result)).unwrap();
|
||||
self.kbd
|
||||
.set_keymap(keyboard::KeyMap::from(new_result))
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -292,8 +335,13 @@ fn run_menu_thread() {
|
|||
let sid = xous::create_server().unwrap();
|
||||
let menu_conn = xous::connect(sid).unwrap();
|
||||
|
||||
// --------------------------- spawn a time UX manager thread
|
||||
let time_sid = xous::create_server().unwrap();
|
||||
let time_cid = xous::connect(time_sid).unwrap();
|
||||
crate::time::start_time_ux(time_sid);
|
||||
|
||||
let mut handlers: Vec<Box<dyn PrefHandler>> = vec![
|
||||
Box::new(DevicePrefs::new(&xns)),
|
||||
Box::new(DevicePrefs::new(&xns, time_cid)),
|
||||
Box::new(wifi::WLANMan::new(&xns)),
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue