trigger off of the new value setting not the old; fix default value on boot for autobacklight

This commit is contained in:
bunnie 2022-11-24 05:06:03 +08:00
parent cc9cffcd39
commit bacf2b65ab
3 changed files with 17 additions and 7 deletions

View file

@ -345,7 +345,7 @@ fn wrapped_main() -> ! {
StatusOpcode::Keypress.to_u32().unwrap() as usize, StatusOpcode::Keypress.to_u32().unwrap() as usize,
); );
let autobacklight_enabled = Arc::new(Mutex::new(false)); let autobacklight_enabled = Arc::new(Mutex::new(true));
let (tx, rx): (Sender<BacklightThreadOps>, Receiver<BacklightThreadOps>) = unbounded(); let (tx, rx): (Sender<BacklightThreadOps>, Receiver<BacklightThreadOps>) = unbounded();
let rx = Box::new(rx); let rx = Box::new(rx);
@ -404,7 +404,8 @@ fn wrapped_main() -> ! {
match prefs.autobacklight_on_boot_or_value(true).unwrap() { match prefs.autobacklight_on_boot_or_value(true).unwrap() {
true => send_message(status_cid, Message::new_scalar( true => send_message(status_cid, Message::new_scalar(
StatusOpcode::EnableAutomaticBacklight.to_usize().unwrap(), 0,0,0,0)), StatusOpcode::EnableAutomaticBacklight.to_usize().unwrap(), 0,0,0,0)),
false => Ok(xous::Result::Ok), false => send_message(status_cid, Message::new_scalar(
StatusOpcode::DisableAutomaticBacklight.to_usize().unwrap(), 0,0,0,0)),
}.unwrap_or_else(|error| { }.unwrap_or_else(|error| {
log::error!("cannot set autobacklight status: {:?}", error); log::error!("cannot set autobacklight status: {:?}", error);
xous::Result::Ok xous::Result::Ok

View file

@ -14,6 +14,7 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, menu_management_sid: xous::S
let mut menuitems = Vec::<MenuItem>::new(); let mut menuitems = Vec::<MenuItem>::new();
// no backlight on versions with no display // no backlight on versions with no display
/*
#[cfg(not(feature="tts"))] #[cfg(not(feature="tts"))]
menuitems.push(MenuItem { menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.backlighton", xous::LANG)), name: String::from_str(t!("mainmenu.backlighton", xous::LANG)),
@ -30,7 +31,7 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, menu_management_sid: xous::S
action_opcode: com.getop_backlight(), action_opcode: com.getop_backlight(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]), action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true, close_on_select: true,
}); }); */
menuitems.push(MenuItem { menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.sleep", xous::LANG)), name: String::from_str(t!("mainmenu.sleep", xous::LANG)),

View file

@ -249,11 +249,11 @@ impl DevicePrefs {
impl DevicePrefs { impl DevicePrefs {
fn autobacklight_on_boot(&mut self) -> Result<(), DevicePrefsError> { fn autobacklight_on_boot(&mut self) -> Result<(), DevicePrefsError> {
let cv = self.up.autobacklight_on_boot_or_value(true)?; // note inversion of storage sense to make it on when false let cv = self.up.autobacklight_on_boot_or_value(true)?;
self.modals.add_list(vec![t!("prefs.yes", xous::LANG), t!("prefs.no", xous::LANG)]).unwrap(); self.modals.add_list(vec![t!("prefs.yes", xous::LANG), t!("prefs.no", xous::LANG)]).unwrap();
let new_result = yes_no_to_bool( // inversion of storage sense: false = on let new_result = yes_no_to_bool(
self.modals self.modals
.get_radiobutton(&format!("{} {}", t!("prefs.current_setting", xous::LANG), .get_radiobutton(&format!("{} {}", t!("prefs.current_setting", xous::LANG),
bool_to_yes_no(cv))) bool_to_yes_no(cv)))
@ -261,12 +261,16 @@ impl DevicePrefs {
.as_str(), .as_str(),
); );
if cv { // already inverted, so the meaning is true (true is on) if new_result {
#[cfg(not(target_os = "xous"))]
log::info!("HOSTED: enable bl");
xous::send_message(self.status_cid, xous::Message::new_scalar( xous::send_message(self.status_cid, xous::Message::new_scalar(
crate::StatusOpcode::EnableAutomaticBacklight.to_usize().unwrap(), crate::StatusOpcode::EnableAutomaticBacklight.to_usize().unwrap(),
0, 0, 0, 0) 0, 0, 0, 0)
).ok(); ).ok();
} else { } else {
#[cfg(not(target_os = "xous"))]
log::info!("HOSTED: disable bl");
xous::send_message(self.status_cid, xous::Message::new_scalar( xous::send_message(self.status_cid, xous::Message::new_scalar(
crate::StatusOpcode::DisableAutomaticBacklight.to_usize().unwrap(), crate::StatusOpcode::DisableAutomaticBacklight.to_usize().unwrap(),
0, 0, 0, 0) 0, 0, 0, 0)
@ -323,9 +327,13 @@ impl DevicePrefs {
.unwrap() .unwrap()
.as_str(), .as_str(),
); );
if cv { if new_result {
#[cfg(not(target_os = "xous"))]
log::info!("HOSTED: killing wifi");
self.netmgr.connection_manager_wifi_off_and_stop().ok(); self.netmgr.connection_manager_wifi_off_and_stop().ok();
} else { } else {
#[cfg(not(target_os = "xous"))]
log::info!("HOSTED: enabling wifi");
self.netmgr.connection_manager_wifi_on().ok(); self.netmgr.connection_manager_wifi_on().ok();
} }