From 4ac930375472c4214a02601fba13a282bbf72e7d Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 10 Jun 2023 16:27:13 -0400 Subject: [PATCH] Add battery power API --- backend/build.sh | 8 ++++---- backend/src/settings/generic/battery.rs | 4 ++++ backend/src/settings/steam_deck/battery.rs | 16 ++++++++++++++++ backend/src/settings/traits.rs | 2 ++ backend/src/settings/unknown/battery.rs | 4 ++++ translations/fr-CA.mo | Bin 2697 -> 2943 bytes translations/fr-FR.mo | Bin 2697 -> 2943 bytes 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/backend/build.sh b/backend/build.sh index d99c6e4..7e408f6 100755 --- a/backend/build.sh +++ b/backend/build.sh @@ -6,7 +6,7 @@ cargo build mkdir -p ../bin -#cp ./target/x86_64-unknown-linux-musl/release/powertools ../bin/backend -#cp ./target/x86_64-unknown-linux-musl/debug/powertools ../bin/backend -#cp ./target/debug/powertools ../bin/backend -cp ./target/debug/powertools ../bin/backend +#cp --preserve=mode ./target/x86_64-unknown-linux-musl/release/powertools ../bin/backend +#cp --preserve=mode ./target/x86_64-unknown-linux-musl/debug/powertools ../bin/backend +#cp --preserve=mode ./target/debug/powertools ../bin/backend +cp --preserve=mode ./target/debug/powertools ../bin/backend diff --git a/backend/src/settings/generic/battery.rs b/backend/src/settings/generic/battery.rs index 1a70c37..3390f1f 100644 --- a/backend/src/settings/generic/battery.rs +++ b/backend/src/settings/generic/battery.rs @@ -129,6 +129,10 @@ impl TBattery for Battery { None } + fn read_charge_power(&self) -> Option { + None + } + fn charge_limit(&mut self, _limit: Option) {} fn get_charge_limit(&self) -> Option { diff --git a/backend/src/settings/steam_deck/battery.rs b/backend/src/settings/steam_deck/battery.rs index 9ea5372..f6481c3 100644 --- a/backend/src/settings/steam_deck/battery.rs +++ b/backend/src/settings/steam_deck/battery.rs @@ -320,6 +320,12 @@ impl Battery { } } + pub fn read_charge_power() -> Result { + let current = Self::read_current_now()? as f64 / 1000.0; // mA -> A + let voltage = Self::read_usb_voltage()?; + Ok(current * voltage) + } + pub fn read_charge_now() -> Result { match usdpl_back::api::files::read_single::<_, u64, _>(BATTERY_CHARGE_NOW_PATH) { Err(e) => Err(SettingError { @@ -552,6 +558,16 @@ impl TBattery for Battery { } } + 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 + } + } + } + fn charge_limit(&mut self, limit: Option) { // upper limit let index = self.find_limit_event(); diff --git a/backend/src/settings/traits.rs b/backend/src/settings/traits.rs index f98c44d..4e96882 100644 --- a/backend/src/settings/traits.rs +++ b/backend/src/settings/traits.rs @@ -129,6 +129,8 @@ pub trait TBattery: OnSet + OnResume + OnPowerEvent + Debug + Send { fn read_current_now(&self) -> Option; + fn read_charge_power(&self) -> Option; + fn charge_limit(&mut self, limit: Option); fn get_charge_limit(&self) -> Option; diff --git a/backend/src/settings/unknown/battery.rs b/backend/src/settings/unknown/battery.rs index c4ba71a..f0c67a3 100644 --- a/backend/src/settings/unknown/battery.rs +++ b/backend/src/settings/unknown/battery.rs @@ -75,6 +75,10 @@ impl TBattery for Battery { None } + fn read_charge_power(&self) -> Option { + None + } + fn charge_limit(&mut self, _limit: Option) {} fn get_charge_limit(&self) -> Option { diff --git a/translations/fr-CA.mo b/translations/fr-CA.mo index d0cc852e6b2fcb053eb825676fa7b028969eac38..673bd8cdbaeff09eddcc21fff3955057543bafee 100644 GIT binary patch delta 1267 zcmZA0OGs2v9LMqFD|0HdF&~-LDIaM%AVP(RkXl5LAx29VSLdXc=H)n}X$u!dAW<7j zf*=Tl5P~8Lp`eXL3tP2l*~1n=xsF=d_czW!bnt&a=iGbefBxs3>s-ZV<;pf&pua{62>)10#lDFR6#?iJaOEG*RuEL zGUFLz7P1c(kvYsWR6#4K1h2E>HB^BgFo+wd0ya@AEaOKSSECAQ#v>R)<>^QLeh^jA zBo;HjnWb})ZNI4-j6ZW}!SARQm2*+TTGSC))I?oaiWjg62T{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