diff --git a/services/status/Cargo.toml b/services/status/Cargo.toml index f865b30c8..d0341213d 100644 --- a/services/status/Cargo.toml +++ b/services/status/Cargo.toml @@ -30,6 +30,8 @@ usb-device-xous = {path="../usb-device-xous"} codec = {path="../codec"} userprefs = {path = "../../libs/userprefs"} dns = {path="../dns"} +early_settings ={ path = "../early_settings"} + num-derive = {version = "0.3.3", default-features = false} num-traits = {version = "0.2.14", default-features = false} diff --git a/services/status/src/main.rs b/services/status/src/main.rs index ee6261317..a23571f21 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -153,6 +153,7 @@ fn wrapped_main() -> ! { // ------------------ acquire the status canvas GID let xns = xous_names::XousNames::new().unwrap(); + let early_settings = early_settings::EarlySettings::new(&xns).unwrap(); // 1 connection exactly -- from the GAM to set our canvas GID let status_gam_getter = xns .register_name(SERVER_NAME_STATUS_GID, Some(1)) @@ -626,6 +627,29 @@ fn wrapped_main() -> ! { #[cfg(any(feature="precursor", feature="renode"))] llio.clear_wakeup_alarm().unwrap(); // this is here to clear any wake-up alarms that were set by a prior coldboot command + // get the last status + let must_sleep = early_settings.early_sleep().unwrap(); + + // reset it for good measure + early_settings.set_early_sleep(false).unwrap(); + + if must_sleep { + while ((llio.adc_vbus().unwrap() as u32) * 503) > 150_000 { + modals.show_notification(t!("mainmenu.cant_sleep", xous::LANG), None).expect("couldn't notify that power is plugged in"); + } + + match susres.initiate_suspend() { + Ok(_) => {}, + Err(xous::Error::Timeout) => { + // TODO: maybe this branch needs a different log message/flow? + modals.show_notification(t!("suspend.fail", xous::LANG), None).unwrap(); + } + Err(_e) => { + panic!("Unhandled error on suspend request"); + } + } + } + // spawn a thread to auto-mount the PDDB let _ = thread::spawn({ move || { @@ -1103,6 +1127,10 @@ fn wrapped_main() -> ! { if !pddb.try_unmount() { // sync the pddb prior to lock modals.show_notification(t!("socup.unmount_fail", xous::LANG), None).ok(); } else { + early_settings.set_early_sleep(true).unwrap(); + + log::info!("forcing sleep on reboot"); + pddb.pddb_halt(); susres.reboot(true).expect("couldn't issue reboot command"); }