From c0f258f09f394a0bb43719e0cc6084500da948b1 Mon Sep 17 00:00:00 2001 From: Luke D Jones Date: Tue, 11 Aug 2020 12:24:57 +1200 Subject: [PATCH] Read config before changing and writing --- asus-nb-ctrl/src/ctrl_charge.rs | 28 ++-------------------------- asus-nb-ctrl/src/ctrl_fan_cpu.rs | 3 ++- asus-nb-ctrl/src/ctrl_leds.rs | 7 ++----- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/asus-nb-ctrl/src/ctrl_charge.rs b/asus-nb-ctrl/src/ctrl_charge.rs index 423b9e97..6b803eae 100644 --- a/asus-nb-ctrl/src/ctrl_charge.rs +++ b/asus-nb-ctrl/src/ctrl_charge.rs @@ -53,22 +53,6 @@ impl CtrlCharge { Ok(CtrlCharge { path }) } - // /// Spawns two tasks which continuously check for changes - // pub(crate) fn spawn_task( - // self, - // config: Arc>, - // mut recv: Receiver, - // ) -> JoinHandle<()> { - // tokio::spawn(async move { - // while let Some(n) = recv.recv().await { - // let mut config = config.lock().await; - // self - // .set_charge_limit(n, &mut config) - // .unwrap_or_else(|err| warn!("{:?}", err)); - // } - // }) - // } - fn get_battery_path() -> Result<&'static str, std::io::Error> { if Path::new(BAT_CHARGE_PATH).exists() { Ok(BAT_CHARGE_PATH) @@ -80,15 +64,6 @@ impl CtrlCharge { } } - // pub(super) fn reload_from_config( - // &self, - // config: &mut Config, - // ) -> Result<(), Box> { - // config.read(); - // info!("Reloaded battery charge limit"); - // self.set_charge_limit(config.bat_charge_limit, config) - // } - pub(super) fn set_charge_limit( &self, limit: u8, @@ -111,7 +86,8 @@ impl CtrlCharge { file.write_all(limit.to_string().as_bytes()) .unwrap_or_else(|err| error!("Could not write to {}, {:?}", BAT_CHARGE_PATH, err)); info!("Battery charge limit: {}", limit); - + + config.read(); config.bat_charge_limit = limit; config.write(); diff --git a/asus-nb-ctrl/src/ctrl_fan_cpu.rs b/asus-nb-ctrl/src/ctrl_fan_cpu.rs index d46849c3..e14bfd5d 100644 --- a/asus-nb-ctrl/src/ctrl_fan_cpu.rs +++ b/asus-nb-ctrl/src/ctrl_fan_cpu.rs @@ -104,6 +104,7 @@ impl CtrlFanAndCPU { file.read_exact(&mut buf)?; if let Some(num) = char::from(buf[0]).to_digit(10) { if config.power_profile != num as u8 { + config.read(); config.power_profile = num as u8; config.write(); self.set_pstate_for_fan_mode(FanLevel::from(config.power_profile), config)?; @@ -127,7 +128,7 @@ impl CtrlFanAndCPU { config: &mut Config, ) -> Result<(), Box> { let mut fan_ctrl = OpenOptions::new().write(true).open(self.path)?; - + config.read(); config.power_profile = n; config.write(); fan_ctrl diff --git a/asus-nb-ctrl/src/ctrl_leds.rs b/asus-nb-ctrl/src/ctrl_leds.rs index eac90e12..2cea0ed1 100644 --- a/asus-nb-ctrl/src/ctrl_leds.rs +++ b/asus-nb-ctrl/src/ctrl_leds.rs @@ -186,6 +186,7 @@ impl CtrlKbdBacklight { AuraModes::LedBrightness(n) => { let bytes: [u8; LED_MSG_LEN] = (&mode).into(); self.write_bytes(&bytes).await?; + config.read(); config.kbd_boot_brightness = n; config.write(); info!("LED brightness set to {:#?}", n); @@ -199,6 +200,7 @@ impl CtrlKbdBacklight { } } _ => { + config.read(); let mode_num: u8 = u8::from(&mode); self.write_mode(&mode).await?; config.kbd_backlight_mode = mode_num; @@ -245,9 +247,4 @@ impl CtrlKbdBacklight { } Ok(()) } - - // #[inline] - // pub async fn reload_from_config(&mut self, config: &mut Config) -> Result<(), RogError> { - - // } }