services/status: if early sleep flag is present, sleep immediately

This flag is only set if the user selects "Lock (reboot)".

This way, the device sleeps immediately after boot, and makes easier turning it on and off in a safe manner.
This commit is contained in:
Gianguido Sorà 2023-04-21 18:12:36 +02:00
parent 523ec0ac80
commit 6abf497ac9
No known key found for this signature in database
2 changed files with 30 additions and 0 deletions

View file

@ -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}

View file

@ -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");
}