mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Read config before changing and writing
This commit is contained in:
@@ -53,22 +53,6 @@ impl CtrlCharge {
|
|||||||
Ok(CtrlCharge { path })
|
Ok(CtrlCharge { path })
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Spawns two tasks which continuously check for changes
|
|
||||||
// pub(crate) fn spawn_task(
|
|
||||||
// self,
|
|
||||||
// config: Arc<Mutex<Config>>,
|
|
||||||
// mut recv: Receiver<u8>,
|
|
||||||
// ) -> 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> {
|
fn get_battery_path() -> Result<&'static str, std::io::Error> {
|
||||||
if Path::new(BAT_CHARGE_PATH).exists() {
|
if Path::new(BAT_CHARGE_PATH).exists() {
|
||||||
Ok(BAT_CHARGE_PATH)
|
Ok(BAT_CHARGE_PATH)
|
||||||
@@ -80,15 +64,6 @@ impl CtrlCharge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub(super) fn reload_from_config(
|
|
||||||
// &self,
|
|
||||||
// config: &mut Config,
|
|
||||||
// ) -> Result<(), Box<dyn Error>> {
|
|
||||||
// config.read();
|
|
||||||
// info!("Reloaded battery charge limit");
|
|
||||||
// self.set_charge_limit(config.bat_charge_limit, config)
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub(super) fn set_charge_limit(
|
pub(super) fn set_charge_limit(
|
||||||
&self,
|
&self,
|
||||||
limit: u8,
|
limit: u8,
|
||||||
@@ -112,6 +87,7 @@ impl CtrlCharge {
|
|||||||
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", BAT_CHARGE_PATH, err));
|
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", BAT_CHARGE_PATH, err));
|
||||||
info!("Battery charge limit: {}", limit);
|
info!("Battery charge limit: {}", limit);
|
||||||
|
|
||||||
|
config.read();
|
||||||
config.bat_charge_limit = limit;
|
config.bat_charge_limit = limit;
|
||||||
config.write();
|
config.write();
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ impl CtrlFanAndCPU {
|
|||||||
file.read_exact(&mut buf)?;
|
file.read_exact(&mut buf)?;
|
||||||
if let Some(num) = char::from(buf[0]).to_digit(10) {
|
if let Some(num) = char::from(buf[0]).to_digit(10) {
|
||||||
if config.power_profile != num as u8 {
|
if config.power_profile != num as u8 {
|
||||||
|
config.read();
|
||||||
config.power_profile = num as u8;
|
config.power_profile = num as u8;
|
||||||
config.write();
|
config.write();
|
||||||
self.set_pstate_for_fan_mode(FanLevel::from(config.power_profile), config)?;
|
self.set_pstate_for_fan_mode(FanLevel::from(config.power_profile), config)?;
|
||||||
@@ -127,7 +128,7 @@ impl CtrlFanAndCPU {
|
|||||||
config: &mut Config,
|
config: &mut Config,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let mut fan_ctrl = OpenOptions::new().write(true).open(self.path)?;
|
let mut fan_ctrl = OpenOptions::new().write(true).open(self.path)?;
|
||||||
|
config.read();
|
||||||
config.power_profile = n;
|
config.power_profile = n;
|
||||||
config.write();
|
config.write();
|
||||||
fan_ctrl
|
fan_ctrl
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ impl CtrlKbdBacklight {
|
|||||||
AuraModes::LedBrightness(n) => {
|
AuraModes::LedBrightness(n) => {
|
||||||
let bytes: [u8; LED_MSG_LEN] = (&mode).into();
|
let bytes: [u8; LED_MSG_LEN] = (&mode).into();
|
||||||
self.write_bytes(&bytes).await?;
|
self.write_bytes(&bytes).await?;
|
||||||
|
config.read();
|
||||||
config.kbd_boot_brightness = n;
|
config.kbd_boot_brightness = n;
|
||||||
config.write();
|
config.write();
|
||||||
info!("LED brightness set to {:#?}", n);
|
info!("LED brightness set to {:#?}", n);
|
||||||
@@ -199,6 +200,7 @@ impl CtrlKbdBacklight {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
config.read();
|
||||||
let mode_num: u8 = u8::from(&mode);
|
let mode_num: u8 = u8::from(&mode);
|
||||||
self.write_mode(&mode).await?;
|
self.write_mode(&mode).await?;
|
||||||
config.kbd_backlight_mode = mode_num;
|
config.kbd_backlight_mode = mode_num;
|
||||||
@@ -245,9 +247,4 @@ impl CtrlKbdBacklight {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[inline]
|
|
||||||
// pub async fn reload_from_config(&mut self, config: &mut Config) -> Result<(), RogError> {
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user