From 907594fade987a04eac634844f1a9b6ef5810362 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 17 Jun 2023 12:34:52 -0400 Subject: [PATCH] Make current and charge power hidden by default --- backend/src/settings/steam_deck/battery.rs | 41 ++++++++++++++------ backend/src/settings/steam_deck/oc_limits.rs | 2 + pt_oc.json | 3 +- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/backend/src/settings/steam_deck/battery.rs b/backend/src/settings/steam_deck/battery.rs index f6481c3..2405380 100644 --- a/backend/src/settings/steam_deck/battery.rs +++ b/backend/src/settings/steam_deck/battery.rs @@ -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_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_CURRENT_PATH: &str = "/sys/class/hwmon/hwmon5/curr1_input"; // read-only impl Battery { #[inline] @@ -321,7 +322,7 @@ impl Battery { } pub fn read_charge_power() -> Result { - let current = Self::read_current_now()? as f64 / 1000.0; // mA -> A + let current = Self::read_usb_current()?; let voltage = Self::read_usb_voltage()?; Ok(current * voltage) } @@ -373,6 +374,16 @@ impl Battery { } } + pub fn read_usb_current() -> Result { + 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 { let (oc_limits, is_default) = OverclockLimits::load_or_default(); let oc_limits = oc_limits.battery; @@ -549,22 +560,30 @@ impl TBattery for Battery { } fn read_current_now(&self) -> Option { - match Self::read_current_now() { - Ok(x) => Some(x as f64), - Err(e) => { - log::warn!("read_current_now err: {}", e.msg); - None + if self.limits.extra_readouts { + match Self::read_current_now() { + Ok(x) => Some(x as f64), + Err(e) => { + log::warn!("read_current_now err: {}", e.msg); + None + } } + } else { + None } } fn read_charge_power(&self) -> Option { - match Self::read_charge_power() { - Ok(x) => Some(x as f64), - Err(e) => { - log::warn!("read_current_now err: {}", e.msg); - None + if self.limits.extra_readouts { + match Self::read_charge_power() { + Ok(x) => Some(x as f64), + Err(e) => { + log::warn!("read_current_now err: {}", e.msg); + None + } } + } else { + None } } diff --git a/backend/src/settings/steam_deck/oc_limits.rs b/backend/src/settings/steam_deck/oc_limits.rs index 74c2bf2..f229a0c 100644 --- a/backend/src/settings/steam_deck/oc_limits.rs +++ b/backend/src/settings/steam_deck/oc_limits.rs @@ -67,6 +67,7 @@ impl OverclockLimits { #[derive(Serialize, Deserialize, Clone, Debug)] pub(super) struct BatteryLimits { pub charge_rate: MinMax, + pub extra_readouts: bool, } impl Default for BatteryLimits { @@ -76,6 +77,7 @@ impl Default for BatteryLimits { min: 250, max: 2500, }, + extra_readouts: false, } } } diff --git a/pt_oc.json b/pt_oc.json index 79d3c37..4ebd7c1 100644 --- a/pt_oc.json +++ b/pt_oc.json @@ -3,7 +3,8 @@ "charge_rate": { "min": 250, "max": 2500 - } + }, + "extra_readouts": false }, "cpus": { "cpus": [