From 0dbfa6a66880019afa2f4920550ed36784e68302 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 11 Mar 2021 04:09:47 +0800 Subject: [PATCH] clean up warnings --- services/llio/src/api.rs | 2 +- services/llio/src/lib.rs | 5 ++-- services/llio/src/main.rs | 10 +++---- services/shellchat/src/cmds/sleep.rs | 41 ++++++++++++++++------------ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/services/llio/src/api.rs b/services/llio/src/api.rs index 8b152e8d5..0f297879a 100644 --- a/services/llio/src/api.rs +++ b/services/llio/src/api.rs @@ -83,7 +83,7 @@ pub struct I2cTransactionResolver { } impl rkyv::Resolve for I2cTransactionResolver { type Archived = ArchivedI2cTransaction; - fn resolve(self, pos: usize, value: &I2cTransaction) -> Self::Archived { + fn resolve(self, pos: usize, _value: &I2cTransaction) -> Self::Archived { Self::Archived { ptr: unsafe { rkyv::RelPtr::new(pos + rkyv::offset_of!(ArchivedI2cTransaction, ptr), self.bytes_pos) diff --git a/services/llio/src/lib.rs b/services/llio/src/lib.rs index 59ffb7263..af6e12159 100644 --- a/services/llio/src/lib.rs +++ b/services/llio/src/lib.rs @@ -4,11 +4,10 @@ /// are calling these functions inside a different process. pub mod api; -use api::*; -use xous::{send_message, Error, CID}; +use xous::{send_message, CID}; pub fn allow_power_off(cid: CID, allow: bool) -> Result<(), xous::Error> { - send_message(cid, api::Opcode::PowerSelf(allow).into()).map(|_| ()) + send_message(cid, api::Opcode::PowerSelf(!allow).into()).map(|_| ()) } pub fn allow_ec_snoop(cid: CID, allow: bool) -> Result<(), xous::Error> { diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 4c3d4a561..522d16de3 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -8,14 +8,11 @@ use core::convert::TryFrom; use log::{error, info}; -use xous::CID; - #[cfg(target_os = "none")] mod implementation { use crate::api::*; use log::{error, info}; use utralib::generated::*; - use ticktimer_server::*; const STD_TIMEOUT: u32 = 100; @@ -242,8 +239,11 @@ mod implementation { } pub fn power_self(&mut self, power_on: bool) { if power_on { + info!("LLIO: setting self-power state to on"); self.power_csr.rmwf(utra::power::POWER_SELF, 1); } else { + info!("LLIO: setting self-power state to OFF"); + self.power_csr.rmwf(utra::power::POWER_STATE, 0); self.power_csr.rmwf(utra::power::POWER_SELF, 0); } } @@ -406,8 +406,8 @@ mod implementation { fn xmain() -> ! { let debug1 = false; use crate::implementation::Llio; - use heapless::Vec; - use heapless::consts::*; + //use heapless::Vec; + //use heapless::consts::*; log_server::init_wait().unwrap(); info!("LLIO: my PID is {}", xous::process::id()); diff --git a/services/shellchat/src/cmds/sleep.rs b/services/shellchat/src/cmds/sleep.rs index 054713d9e..080d0d8d1 100644 --- a/services/shellchat/src/cmds/sleep.rs +++ b/services/shellchat/src/cmds/sleep.rs @@ -16,25 +16,30 @@ impl<'a> ShellCmdApi<'a> for Sleep { fn process(&mut self, _rest: String::<1024>, env: &mut CommonEnv) -> Result>, xous::Error> { use core::fmt::Write; - // TODO: check if power is plugged in first, we can't sleep when plugged in - - if Ok(true) == gam::powerdown_request(env.gam) { - // allow EC to snoop, so that it can wake up the system - llio::allow_ec_snoop(env.llio, true).unwrap(); - // allow the EC to power me down - llio::allow_power_off(env.llio, true).unwrap(); - // now send the power off command - com::power_off_soc(env.com).unwrap(); - - log::info!("CMD: powering down now!"); - // pause execution, nothing after this should be reachable - ticktimer_server::sleep_ms(env.ticktimer, 2000).unwrap(); // should power off within 2 seconds - log::info!("CMD: if you can read this, power down failed!"); - } - let mut ret = String::<1024>::new(); - write!(ret, "Powerdown request denied").unwrap(); - Ok(Some(ret)) + if ((llio::adc_vbus(env.llio).unwrap() as f64) * 0.005033) > 1.5 { + // if power is plugged in, deny powerdown request + write!(ret, "System can't sleep while charging. Unplug charging cable and try again.").unwrap(); + Ok(Some(ret)) + } else { + if Ok(true) == gam::powerdown_request(env.gam) { + ticktimer_server::sleep_ms(env.ticktimer, 500).unwrap(); // let the screen redraw + + // allow EC to snoop, so that it can wake up the system + llio::allow_ec_snoop(env.llio, true).unwrap(); + // allow the EC to power me down + llio::allow_power_off(env.llio, true).unwrap(); + // now send the power off command + com::power_off_soc(env.com).unwrap(); + + log::info!("CMD: powering down now!"); + // pause execution, nothing after this should be reachable + ticktimer_server::sleep_ms(env.ticktimer, 2000).unwrap(); // should power off within 2 seconds + log::info!("CMD: if you can read this, power down failed!"); + } + write!(ret, "Powerdown request denied").unwrap(); + Ok(Some(ret)) + } }