Add ability to set BAT0/charge_control_end_threshold

This commit is contained in:
Luke
2020-06-26 16:23:14 +12:00
parent 710e8228b0
commit baa5cef625
4 changed files with 42 additions and 2 deletions

View File

@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for G531GT
- Remove duplicated code: it looks like there is at least *some* consistency in Consumer-Device keycodes that ASUS uses
### BREAKING CHANGE
- `bat_charge_limit = 100` must be appended to the top of `/etc/rogcore.conf`
## [0.11.1] - 2020-11-06
### Changed
- Use DBUS_NAME instead of DBUS_IFACE when requesting the name

View File

@@ -8,6 +8,7 @@ pub static CONFIG_PATH: &str = "/etc/rogcore.conf";
#[derive(Default, Deserialize, Serialize)]
pub struct Config {
pub fan_mode: u8,
pub bat_charge_limit: u8,
pub brightness: u8,
pub current_mode: [u8; 4],
pub builtin_modes: BuiltInModeBytes,
@@ -29,6 +30,7 @@ impl Config {
if l == 0 {
// create a default config here
let mut c = Config::default();
c.bat_charge_limit = 100;
c.current_mode[0] = 0x5d;
c.current_mode[1] = 0xb3;
// Should be okay to unwrap this as is since it is a Default

View File

@@ -51,8 +51,11 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
// Reload settings
rogcore
.fan_mode_reload(&mut config)
.await
.unwrap_or_else(|err| warn!("Fan mode: {}", err));
rogcore
.bat_charge_limit_reload(&mut config)
.unwrap_or_else(|err| warn!("Battery charge limit: {}", err));
let mut led_writer = LedWriter::new(
rogcore.get_raw_device_handle(),
laptop.led_endpoint(),

View File

@@ -16,6 +16,7 @@ use std::time::Duration;
static FAN_TYPE_1_PATH: &str = "/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy";
static FAN_TYPE_2_PATH: &str = "/sys/devices/platform/asus-nb-wmi/fan_boost_mode";
static AMD_BOOST_PATH: &str = "/sys/devices/system/cpu/cpufreq/boost";
static BAT_CHARGE_PATH: &str = "/sys/class/power_supply/BAT0/charge_control_end_threshold";
/// ROG device controller
///
@@ -128,7 +129,7 @@ impl RogCore {
}
}
pub async fn fan_mode_reload(&mut self, config: &mut Config) -> Result<(), Box<dyn Error>> {
pub fn fan_mode_reload(&mut self, config: &mut Config) -> Result<(), Box<dyn Error>> {
let path = RogCore::get_fan_path()?;
let mut file = OpenOptions::new().write(true).open(path)?;
file.write_all(format!("{:?}\n", config.fan_mode).as_bytes())
@@ -258,6 +259,37 @@ impl RogCore {
Ok(())
}
pub fn bat_charge_limit_reload(&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 fn set_charge_limit(&self, limit: u8, config: &mut Config) -> Result<(), Box<dyn Error>> {
if limit < 20 || limit > 100 {
warn!(
"Unable to set battery charge limit, must be between 20-100: requested {}",
limit
);
}
let mut file = OpenOptions::new()
.write(true)
.open(BAT_CHARGE_PATH)
.map_err(|err| {
warn!("Failed to open battery charge limit path: {:?}", err);
err
})?;
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.bat_charge_limit = limit;
config.write();
Ok(())
}
/// A direct call to systemd to suspend the PC.
///
/// This avoids desktop environments being required to handle it