mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add backlight commands
This commit is contained in:
parent
5328e09a5b
commit
87b6d9b6d7
5 changed files with 95 additions and 1 deletions
|
|
@ -68,7 +68,7 @@ pub(crate) enum Opcode {
|
|||
//IsCharging,
|
||||
|
||||
/// Set the backlight brightness
|
||||
//SetBackLight,
|
||||
SetBackLight,
|
||||
|
||||
/// Request charging
|
||||
//RequestCharging,
|
||||
|
|
|
|||
|
|
@ -189,6 +189,17 @@ impl Com {
|
|||
send_message(self.conn, Message::new_scalar(Opcode::BoostOff.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
// numbers from 0-255 represent backlight brightness. Note that only the top 5 bits are used.
|
||||
pub fn set_backlight(&self, main: u8, secondary: u8) -> Result<(), xous::Error> {
|
||||
send_message(self.conn,
|
||||
Message::new_scalar(Opcode::SetBackLight.to_usize().unwrap(),
|
||||
(main >> 3) as usize,
|
||||
(secondary >> 3) as usize,
|
||||
0, 0
|
||||
)
|
||||
).map(|_| ())
|
||||
}
|
||||
// note to future self: add other event listener registrations (such as network events) here
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,8 @@ mod implementation {
|
|||
self.susres.resume();
|
||||
// issue a "link sync" command because the COM had continued running, and we may have sent garbage during suspend
|
||||
self.txrx(ComState::LINK_SYNC.verb);
|
||||
// wait a moment for the link to stabilize, before allowing any other commands to issue
|
||||
self.ticktimer.sleep_ms(5).unwrap();
|
||||
}
|
||||
|
||||
pub fn txrx(&mut self, tx: u16) -> u16 {
|
||||
|
|
@ -292,15 +294,24 @@ fn xmain() -> ! {
|
|||
let mut battstats_conns: [Option<xous::CID>; 32] = [None; 32];
|
||||
// other future notification vectors shall go here
|
||||
|
||||
let mut bl_main = 0;
|
||||
let mut bl_sec = 0;
|
||||
|
||||
trace!("starting main loop");
|
||||
loop {
|
||||
let mut msg = xous::receive_message(com_sid).unwrap();
|
||||
trace!("Message: {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
|
||||
if bl_main != 0 || bl_sec != 0 {
|
||||
com.txrx(ComState::BL_START.verb); // this will turn off the backlights
|
||||
}
|
||||
com.suspend();
|
||||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
||||
com.resume();
|
||||
if bl_main != 0 || bl_sec != 0 { // restore the backlight settings, if they are not 0
|
||||
com.txrx(ComState::BL_START.verb | (bl_main as u16) & 0x1f | (((bl_sec as u16) & 0x1f) << 5));
|
||||
}
|
||||
}),
|
||||
Some(Opcode::RegisterBattStatsListener) => msg_scalar_unpack!(msg, sid0, sid1, sid2, sid3, {
|
||||
let sid = xous::SID::from_u32(sid0 as _, sid1 as _, sid2 as _, sid3 as _);
|
||||
|
|
@ -360,6 +371,11 @@ fn xmain() -> ! {
|
|||
Some(Opcode::BoostOn) => {
|
||||
com.txrx(ComState::CHG_BOOST_ON.verb);
|
||||
}
|
||||
Some(Opcode::SetBackLight) => msg_scalar_unpack!(msg, main, secondary, _, _, {
|
||||
bl_main = main;
|
||||
bl_sec = secondary;
|
||||
com.txrx(ComState::BL_START.verb | (main as u16) & 0x1f | (((secondary as u16) & 0x1f) << 5));
|
||||
}),
|
||||
Some(Opcode::BattStats) => {
|
||||
info!("batt stats request received");
|
||||
let stats = com.get_battstats();
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ mod vibe; use vibe::*;
|
|||
mod ssid; use ssid::*;
|
||||
mod ver; use ver::*;
|
||||
mod audio; use audio::*;
|
||||
mod backlight; use backlight::*;
|
||||
|
||||
mod fcc; use fcc::*;
|
||||
mod pds; // dependency of the FCC file
|
||||
|
|
@ -140,6 +141,7 @@ impl CmdEnv {
|
|||
|
||||
let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions)
|
||||
let mut ver_cmd = Ver{};
|
||||
let mut backlight_cmd = Backlight{};
|
||||
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||
&mut echo_cmd,
|
||||
|
|
@ -152,6 +154,7 @@ impl CmdEnv {
|
|||
&mut self.ssid_cmd,
|
||||
&mut ver_cmd,
|
||||
&mut self.audio_cmd,
|
||||
&mut backlight_cmd,
|
||||
|
||||
&mut self.fcc_cmd,
|
||||
];
|
||||
|
|
|
|||
64
services/shellchat/src/cmds/backlight.rs
Normal file
64
services/shellchat/src/cmds/backlight.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use crate::{ShellCmdApi, CommonEnv};
|
||||
use xous_ipc::String;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Backlight {
|
||||
}
|
||||
|
||||
impl<'a> ShellCmdApi<'a> for Backlight {
|
||||
cmd_api!(backlight); // inserts boilerplate for command API
|
||||
|
||||
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
let mut ret = String::<1024>::new();
|
||||
let helpstring = "backlight [on] [off] [0-5]";
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
// note that the secondary backlight appears brighter, so generally, we want to set it to a lower setting
|
||||
// to save battery power
|
||||
match sub_cmd {
|
||||
"on" => {
|
||||
env.com.set_backlight(255, 255).unwrap();
|
||||
write!(ret, "backlight set to 100%").unwrap();
|
||||
}
|
||||
"off" => {
|
||||
env.com.set_backlight(0, 0).unwrap();
|
||||
write!(ret, "backlight turned off").unwrap();
|
||||
}
|
||||
"0" => {
|
||||
env.com.set_backlight(0, 0).unwrap();
|
||||
write!(ret, "backlight 0").unwrap();
|
||||
}
|
||||
"1" => {
|
||||
env.com.set_backlight(32, 32).unwrap();
|
||||
write!(ret, "backlight 1").unwrap();
|
||||
}
|
||||
"2" => {
|
||||
env.com.set_backlight(96, 48).unwrap();
|
||||
write!(ret, "backlight 2").unwrap();
|
||||
}
|
||||
"3" => {
|
||||
env.com.set_backlight(128, 64).unwrap();
|
||||
write!(ret, "backlight 3").unwrap();
|
||||
}
|
||||
"4" => {
|
||||
env.com.set_backlight(196, 96).unwrap();
|
||||
write!(ret, "backlight 4").unwrap();
|
||||
}
|
||||
"5" => {
|
||||
env.com.set_backlight(255, 128).unwrap();
|
||||
write!(ret, "backlight 5").unwrap();
|
||||
}
|
||||
_ => {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue