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,22 +560,30 @@ impl TBattery for Battery {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_current_now(&self) -> Option<f64> {
|
fn read_current_now(&self) -> Option<f64> {
|
||||||
match Self::read_current_now() {
|
if self.limits.extra_readouts {
|
||||||
Ok(x) => Some(x as f64),
|
match Self::read_current_now() {
|
||||||
Err(e) => {
|
Ok(x) => Some(x as f64),
|
||||||
log::warn!("read_current_now err: {}", e.msg);
|
Err(e) => {
|
||||||
None
|
log::warn!("read_current_now err: {}", e.msg);
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_charge_power(&self) -> Option<f64> {
|
fn read_charge_power(&self) -> Option<f64> {
|
||||||
match Self::read_charge_power() {
|
if self.limits.extra_readouts {
|
||||||
Ok(x) => Some(x as f64),
|
match Self::read_charge_power() {
|
||||||
Err(e) => {
|
Ok(x) => Some(x as f64),
|
||||||
log::warn!("read_current_now err: {}", e.msg);
|
Err(e) => {
|
||||||
None
|
log::warn!("read_current_now err: {}", e.msg);
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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