diff --git a/services/status/src/main.rs b/services/status/src/main.rs index ca3a7cae9..9d51c287d 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -355,7 +355,7 @@ fn wrapped_main() -> ! { let prefs_sid = xous::create_server().unwrap(); let prefs_cid = xous::connect(prefs_sid).unwrap(); - preferences::start_background_thread(prefs_sid); + preferences::start_background_thread(prefs_sid, status_cid); // load system preferences let prefs = Arc::new(Mutex::new(userprefs::Manager::new())); @@ -762,29 +762,24 @@ fn wrapped_main() -> ! { log::debug!("{:?}", opcode); match opcode { Some(StatusOpcode::EnableAutomaticBacklight) => { + if *autobacklight_enabled.lock().unwrap() { + // already enabled, don't re-enable + continue; + } *autobacklight_enabled.lock().unwrap() = true; // second: delete the first three elements off the menu menu_manager.delete_item(t!("mainmenu.backlighton", xous::LANG)); menu_manager.delete_item(t!("mainmenu.backlightoff", xous::LANG)); - menu_manager.delete_item(t!("mainmenu.autobacklighton", xous::LANG)); - - // third: add a "disable automatic backlight element" - menu_manager.insert_item(gam::MenuItem { - name: xous_ipc::String::from_str(t!("mainmenu.autobacklightoff", xous::LANG)), - action_conn: Some(status_cid), - action_opcode: StatusOpcode::DisableAutomaticBacklight.to_u32().unwrap(), - action_payload: gam::MenuPayload::Scalar([0, 0, 0, 0]), - close_on_select: true, - }, 0); } Some(StatusOpcode::DisableAutomaticBacklight) => { + if !(*autobacklight_enabled.lock().unwrap()) { + // already disabled, don't re-disable + continue; + } *autobacklight_enabled.lock().unwrap() = false; tx.send(BacklightThreadOps::Stop).unwrap(); - // second: delete the first element off the menu. - menu_manager.delete_item(t!("mainmenu.autobacklightoff", xous::LANG)); - // third: construct an array of the new elements to add to the menu. let new_elems = [ gam::MenuItem { @@ -801,13 +796,6 @@ fn wrapped_main() -> ! { action_payload: gam::MenuPayload::Scalar([0, 0, 0, 0]), close_on_select: true, }, - gam::MenuItem { - name: xous_ipc::String::from_str(t!("mainmenu.autobacklighton", xous::LANG)), - action_conn: Some(status_cid), - action_opcode: StatusOpcode::EnableAutomaticBacklight.to_u32().unwrap(), - action_payload: gam::MenuPayload::Scalar([0, 0, 0, 0]), - close_on_select: true, - } ]; new_elems.iter().enumerate().for_each(|(index, element)| {let _ = menu_manager.insert_item(*element, index);}); diff --git a/services/status/src/mainmenu.rs b/services/status/src/mainmenu.rs index 018bf832d..3d13e7e72 100644 --- a/services/status/src/mainmenu.rs +++ b/services/status/src/mainmenu.rs @@ -32,24 +32,6 @@ pub fn create_main_menu(keys: Arc>, menu_management_sid: xous::S close_on_select: true, }); - #[cfg(not(feature="tts"))] - menuitems.push(MenuItem { - name: String::from_str(t!("mainmenu.autobacklighton", xous::LANG)), - action_conn: Some(status_conn), - action_opcode: StatusOpcode::EnableAutomaticBacklight.to_u32().unwrap(), - action_payload: MenuPayload::Scalar([0, 0, 0, 0]), - close_on_select: true, - }); - - // #[cfg(not(feature="tts"))] - // menuitems.push(MenuItem { - // name: String::from_str(t!("mainmenu.autobacklightoff", xous::LANG)), - // action_conn: Some(kbb.cid()), - // action_opcode: KbbOps::DisableAutomaticBacklight.to_u32().unwrap(), - // action_payload: MenuPayload::Scalar([0, 0, 0, 0]), - // close_on_select: true, - // }); - menuitems.push(MenuItem { name: String::from_str(t!("mainmenu.sleep", xous::LANG)), action_conn: Some(status_conn), diff --git a/services/status/src/preferences.rs b/services/status/src/preferences.rs index 2f5241efb..67144f2aa 100644 --- a/services/status/src/preferences.rs +++ b/services/status/src/preferences.rs @@ -98,6 +98,7 @@ struct DevicePrefs { menu: Option, menu_manager_sid: xous::SID, menu_global_conn: xous::CID, + status_cid: xous::CID, } impl PrefHandler for DevicePrefs { @@ -159,7 +160,7 @@ impl PrefHandler for DevicePrefs { } impl DevicePrefs { - fn new(xns: &xous_names::XousNames, time_ux_cid: xous::CID, menu_manager_sid: xous::SID, menu_conn: xous::CID, codec: codec::Codec) -> Self { + fn new(xns: &xous_names::XousNames, time_ux_cid: xous::CID, menu_manager_sid: xous::SID, menu_conn: xous::CID, codec: codec::Codec, status_conn: xous::CID) -> Self { Self { up: Manager::new(), modals: modals::Modals::new(&xns).unwrap(), @@ -170,6 +171,7 @@ impl DevicePrefs { menu: None, menu_manager_sid, menu_global_conn: menu_conn, + status_cid: status_conn, } } @@ -248,6 +250,18 @@ impl DevicePrefs { .as_str(), ); + if cv { // true means off + xous::send_message(self.status_cid, xous::Message::new_scalar( + crate::StatusOpcode::DisableAutomaticBacklight.to_usize().unwrap(), + 0, 0, 0, 0) + ).ok(); + } else { + xous::send_message(self.status_cid, xous::Message::new_scalar( + crate::StatusOpcode::EnableAutomaticBacklight.to_usize().unwrap(), + 0, 0, 0, 0) + ).ok(); + } + Ok(self.up.set_autobacklight_on_boot(new_result)?) } @@ -512,9 +526,9 @@ pub fn percentage_to_db(value: u32) -> i32 { } fn yes_no_to_bool(val: &str) -> bool { - if val.to_ascii_lowercase().as_str() == t!("prefs.yes", xous::LANG) { + if val == t!("prefs.yes", xous::LANG) { true - } else if val.to_ascii_lowercase().as_str() == t!("prefs.no", xous::LANG) { + } else if val == t!("prefs.no", xous::LANG) { false } else { unreachable!("cannot go here!"); @@ -528,12 +542,12 @@ fn bool_to_yes_no(val: bool) -> String { } } -pub fn start_background_thread(sid: xous::SID) { +pub fn start_background_thread(sid: xous::SID, status_cid: xous::CID) { let sid = sid.clone(); - std::thread::spawn(move || run_menu_thread(sid)); + std::thread::spawn(move || run_menu_thread(sid, status_cid)); } -fn run_menu_thread(sid: xous::SID) { +fn run_menu_thread(sid: xous::SID, status_cid: xous::CID) { let xns = xous_names::XousNames::new().unwrap(); let menu_conn = xous::connect(sid).unwrap(); @@ -548,7 +562,7 @@ fn run_menu_thread(sid: xous::SID) { let codec = codec::Codec::new(&xns).unwrap(); let mut handlers: Vec> = vec![ - Box::new(DevicePrefs::new(&xns, time_cid, menumatic_sid, menu_conn, codec)), + Box::new(DevicePrefs::new(&xns, time_cid, menumatic_sid, menu_conn, codec, status_cid)), Box::new(wifi::WLANMan::new(&xns)), ];