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,
);
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 rx = Box::new(rx);
@ -404,7 +404,8 @@ fn wrapped_main() -> ! {
match prefs.autobacklight_on_boot_or_value(true).unwrap() {
true => send_message(status_cid, Message::new_scalar(
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| {
log::error!("cannot set autobacklight status: {:?}", error);
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();
// no backlight on versions with no display
/*
#[cfg(not(feature="tts"))]
menuitems.push(MenuItem {
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_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true,
});
}); */
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.sleep", xous::LANG)),

View file

@ -249,11 +249,11 @@ impl DevicePrefs {
impl DevicePrefs {
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();
let new_result = yes_no_to_bool( // inversion of storage sense: false = on
let new_result = yes_no_to_bool(
self.modals
.get_radiobutton(&format!("{} {}", t!("prefs.current_setting", xous::LANG),
bool_to_yes_no(cv)))
@ -261,12 +261,16 @@ impl DevicePrefs {
.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(
crate::StatusOpcode::EnableAutomaticBacklight.to_usize().unwrap(),
0, 0, 0, 0)
).ok();
} else {
#[cfg(not(target_os = "xous"))]
log::info!("HOSTED: disable bl");
xous::send_message(self.status_cid, xous::Message::new_scalar(
crate::StatusOpcode::DisableAutomaticBacklight.to_usize().unwrap(),
0, 0, 0, 0)
@ -323,9 +327,13 @@ impl DevicePrefs {
.unwrap()
.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();
} else {
#[cfg(not(target_os = "xous"))]
log::info!("HOSTED: enabling wifi");
self.netmgr.connection_manager_wifi_on().ok();
}