forked from NG-SD-Plugins/PowerTools
Make current and charge power hidden by default
This commit is contained in:
parent
f68abbfd1b
commit
907594fade
3 changed files with 34 additions and 12 deletions
|
@ -179,6 +179,7 @@ const BATTERY_CHARGE_NOW_PATH: &str = "/sys/class/power_supply/BAT1/charge_now";
|
||||||
const BATTERY_CHARGE_FULL_PATH: &str = "/sys/class/power_supply/BAT1/charge_full"; // read-only
|
const BATTERY_CHARGE_FULL_PATH: &str = "/sys/class/power_supply/BAT1/charge_full"; // read-only
|
||||||
const BATTERY_CHARGE_DESIGN_PATH: &str = "/sys/class/power_supply/BAT1/charge_full_design"; // read-only
|
const BATTERY_CHARGE_DESIGN_PATH: &str = "/sys/class/power_supply/BAT1/charge_full_design"; // read-only
|
||||||
const USB_PD_IN_MVOLTAGE_PATH: &str = "/sys/class/hwmon/hwmon5/in0_input"; // read-only
|
const USB_PD_IN_MVOLTAGE_PATH: &str = "/sys/class/hwmon/hwmon5/in0_input"; // read-only
|
||||||
|
const USB_PD_IN_CURRENT_PATH: &str = "/sys/class/hwmon/hwmon5/curr1_input"; // read-only
|
||||||
|
|
||||||
impl Battery {
|
impl Battery {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -321,7 +322,7 @@ impl Battery {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_charge_power() -> Result<f64, SettingError> {
|
pub fn read_charge_power() -> Result<f64, SettingError> {
|
||||||
let current = Self::read_current_now()? as f64 / 1000.0; // mA -> A
|
let current = Self::read_usb_current()?;
|
||||||
let voltage = Self::read_usb_voltage()?;
|
let voltage = Self::read_usb_voltage()?;
|
||||||
Ok(current * voltage)
|
Ok(current * voltage)
|
||||||
}
|
}
|
||||||
|
@ -373,6 +374,16 @@ impl Battery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_usb_current() -> Result<f64, SettingError> {
|
||||||
|
match usdpl_back::api::files::read_single::<_, u64, _>(USB_PD_IN_CURRENT_PATH) {
|
||||||
|
Err(e) => Err(SettingError {
|
||||||
|
msg: format!("Failed to read from `{}`: {}", USB_PD_IN_CURRENT_PATH, e),
|
||||||
|
setting: crate::settings::SettingVariant::Battery,
|
||||||
|
}),
|
||||||
|
Ok(val) => Ok((val as f64) / 1000.0), // mA -> A
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn system_default() -> Self {
|
pub fn system_default() -> Self {
|
||||||
let (oc_limits, is_default) = OverclockLimits::load_or_default();
|
let (oc_limits, is_default) = OverclockLimits::load_or_default();
|
||||||
let oc_limits = oc_limits.battery;
|
let oc_limits = oc_limits.battery;
|
||||||
|
@ -549,6 +560,7 @@ impl TBattery for Battery {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_current_now(&self) -> Option<f64> {
|
fn read_current_now(&self) -> Option<f64> {
|
||||||
|
if self.limits.extra_readouts {
|
||||||
match Self::read_current_now() {
|
match Self::read_current_now() {
|
||||||
Ok(x) => Some(x as f64),
|
Ok(x) => Some(x as f64),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -556,9 +568,13 @@ impl TBattery for Battery {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_charge_power(&self) -> Option<f64> {
|
fn read_charge_power(&self) -> Option<f64> {
|
||||||
|
if self.limits.extra_readouts {
|
||||||
match Self::read_charge_power() {
|
match Self::read_charge_power() {
|
||||||
Ok(x) => Some(x as f64),
|
Ok(x) => Some(x as f64),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -566,6 +582,9 @@ impl TBattery for Battery {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn charge_limit(&mut self, limit: Option<f64>) {
|
fn charge_limit(&mut self, limit: Option<f64>) {
|
||||||
|
|
|
@ -67,6 +67,7 @@ impl OverclockLimits {
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub(super) struct BatteryLimits {
|
pub(super) struct BatteryLimits {
|
||||||
pub charge_rate: MinMax<u64>,
|
pub charge_rate: MinMax<u64>,
|
||||||
|
pub extra_readouts: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BatteryLimits {
|
impl Default for BatteryLimits {
|
||||||
|
@ -76,6 +77,7 @@ impl Default for BatteryLimits {
|
||||||
min: 250,
|
min: 250,
|
||||||
max: 2500,
|
max: 2500,
|
||||||
},
|
},
|
||||||
|
extra_readouts: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
"charge_rate": {
|
"charge_rate": {
|
||||||
"min": 250,
|
"min": 250,
|
||||||
"max": 2500
|
"max": 2500
|
||||||
}
|
},
|
||||||
|
"extra_readouts": false
|
||||||
},
|
},
|
||||||
"cpus": {
|
"cpus": {
|
||||||
"cpus": [
|
"cpus": [
|
||||||
|
|
Loading…
Reference in a new issue