From d4377872aa0e56a9d16e894e1831d36fc0598383 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Tue, 7 May 2024 17:51:44 -0400 Subject: [PATCH] Update to sysfuss v0.3, sort of fix #156 --- backend/Cargo.lock | 8 ++++---- backend/Cargo.toml | 6 +++--- backend/limits_core/src/json_v2/battery_limit.rs | 4 ++-- backend/src/settings/steam_deck/battery.rs | 14 +++++++------- backend/src/settings/steam_deck/gpu.rs | 9 ++++----- backend/src/settings/steam_deck/power_dpm_force.rs | 2 +- backend/src/settings/steam_deck/util.rs | 10 ++++++++-- package.json | 2 +- 8 files changed, 30 insertions(+), 25 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 0c0b7e5..0ea6e5a 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1170,7 +1170,7 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "powertools" -version = "2.0.2-alpha1" +version = "2.0.3-alpha1" dependencies = [ "async-trait", "chrono", @@ -1481,7 +1481,7 @@ dependencies = [ [[package]] name = "smokepatio" -version = "0.1.0" +version = "0.2.0" dependencies = [ "embedded-io", "log", @@ -1538,9 +1538,9 @@ dependencies = [ [[package]] name = "sysfuss" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fa4dd5879b3fd41aff63991a59970cdfeced6f0d5920c5da0937279904d9f45" +checksum = "f33bae529511a671b5f2ed4cc46ae0b2ccdf8c03ccf7eebe95a5a886ff7914dc" [[package]] name = "termcolor" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 074257f..b686141 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "powertools" -version = "2.0.2-alpha1" +version = "2.0.3-alpha1" edition = "2021" authors = ["NGnius (Graham) "] description = "Backend (superuser) functionality for PowerTools" @@ -16,7 +16,7 @@ usdpl-back = { version = "0.10.1", features = ["blocking", "decky"] }#, path = " serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" ron = "0.8" -sysfuss = { version = "0.2", features = ["derive"] }#,path = "../../sysfs-nav"} +sysfuss = { version = "0.3", features = ["derive"] }#,path = "../../sysfs-nav"} # async tokio = { version = "*", features = ["time"] } @@ -31,7 +31,7 @@ limits_core = { version = "3", path = "./limits_core" } regex = "1" # steam deck libs -smokepatio = { version = "0.1", features = [ "std" ], path = "../../smokepatio" } +smokepatio = { version = "0.2", default-features = false, path = "../../smokepatio" } libc = "0.2" # online settings diff --git a/backend/limits_core/src/json_v2/battery_limit.rs b/backend/limits_core/src/json_v2/battery_limit.rs index 3506d4b..d9bc581 100644 --- a/backend/limits_core/src/json_v2/battery_limit.rs +++ b/backend/limits_core/src/json_v2/battery_limit.rs @@ -34,8 +34,8 @@ impl GenericBatteryLimit { fn default_steam_deck() -> Self { Self { charge_rate: Some(RangeLimit { - min: Some(250), - max: Some(2500), + min: Some(0), + max: Some(100), }), charge_modes: vec![ "normal".to_owned(), diff --git a/backend/src/settings/steam_deck/battery.rs b/backend/src/settings/steam_deck/battery.rs index d48e2a5..6b092c3 100644 --- a/backend/src/settings/steam_deck/battery.rs +++ b/backend/src/settings/steam_deck/battery.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex}; use sysfuss::capability::attributes; use sysfuss::{ HwMonAttribute, HwMonAttributeItem, HwMonAttributeType, HwMonPath, PowerSupplyAttribute, - PowerSupplyPath, SysAttribute, SysEntity, SysEntityAttributesExt, + PowerSupplyPath, SysEntity, SysEntityAttributesExt, SysAttributeExt, }; use limits_core::json_v2::GenericBatteryLimit; @@ -230,12 +230,12 @@ const HWMON_NEEDS: &[HwMonAttribute] = &[ ]; const MAX_BATTERY_CHARGE_RATE_ATTR: HwMonAttribute = - HwMonAttribute::custom("maximum_battery_charge_rate"); + HwMonAttribute::custom("max_battery_charge_rate"); const MAX_BATTERY_CHARGE_LEVEL_ATTR: HwMonAttribute = HwMonAttribute::custom("max_battery_charge_level"); -const MAX_CHARGE_RATE: u64 = 2500; -const MIN_CHARGE_RATE: u64 = 250; +const MAX_CHARGE_RATE: u64 = 100; +const MIN_CHARGE_RATE: u64 = 0; impl Battery { fn find_battery_sysfs(root: Option>) -> PowerSupplyPath { @@ -325,7 +325,7 @@ impl Battery { self.state.charge_rate_set = true; let path = MAX_BATTERY_CHARGE_RATE_ATTR.path(&*self.sysfs_hwmon); self.sysfs_hwmon - .set(MAX_BATTERY_CHARGE_RATE_ATTR, charge_rate) + .set(MAX_BATTERY_CHARGE_RATE_ATTR, format!("{}\n", charge_rate)) .map_err(|e| SettingError { msg: format!("Failed to write to `{}`: {}", path.display(), e), setting: crate::settings::SettingVariant::Battery, @@ -336,10 +336,10 @@ impl Battery { self.sysfs_hwmon .set( MAX_BATTERY_CHARGE_RATE_ATTR, - self.limits + format!("{}\n", self.limits .charge_rate .and_then(|lim| lim.max) - .unwrap_or(2500), + .unwrap_or(100)), ) .map_err(|e| SettingError { msg: format!("Failed to write to `{}`: {}", path.display(), e), diff --git a/backend/src/settings/steam_deck/gpu.rs b/backend/src/settings/steam_deck/gpu.rs index 2899e1b..6eea1de 100644 --- a/backend/src/settings/steam_deck/gpu.rs +++ b/backend/src/settings/steam_deck/gpu.rs @@ -1,8 +1,7 @@ use std::convert::Into; use sysfuss::{ - capability::attributes, BasicEntityPath, HwMonPath, SysAttribute, SysEntity, - SysEntityAttributes, SysEntityAttributesExt, + capability::attributes, BasicEntityPath, HwMonPath, SysEntity, SysEntityAttributesExt, SysAttributeExt, }; use limits_core::json_v2::GenericGpuLimit; @@ -151,7 +150,7 @@ impl Gpu { if let super::Model::OLED = self.variant { if let Ok(f) = self .sysfs_card - .read_value(GPU_CLOCK_READOUT_ATTRIBUTE.to_owned()) + .read_value(&GPU_CLOCK_READOUT_ATTRIBUTE.to_owned()) { let options = parse_pp_dpm_sclk(&String::from_utf8_lossy(&f)); return options @@ -192,7 +191,7 @@ impl Gpu { fn quantize_memory_clock(&self, clock: u64) -> u64 { if let Ok(f) = self .sysfs_card - .read_value(GPU_MEMORY_DOWNCLOCK_ATTRIBUTE.to_owned()) + .read_value(&GPU_MEMORY_DOWNCLOCK_ATTRIBUTE.to_owned()) { let options = parse_pp_dpm_fclk(&String::from_utf8_lossy(&f)); // round (and find) nearest valid clock step @@ -238,7 +237,7 @@ impl Gpu { { let options_count = self .sysfs_card - .read_value(GPU_MEMORY_DOWNCLOCK_ATTRIBUTE.to_owned()) + .read_value(&GPU_MEMORY_DOWNCLOCK_ATTRIBUTE.to_owned()) .map(|b| parse_pp_dpm_fclk(&String::from_utf8_lossy(&b)).len()) .unwrap_or_else(|_| if is_oled { 4 } else { 2 }); let modifier = (options_count - 1) as u64; diff --git a/backend/src/settings/steam_deck/power_dpm_force.rs b/backend/src/settings/steam_deck/power_dpm_force.rs index 039026a..ce1c891 100644 --- a/backend/src/settings/steam_deck/power_dpm_force.rs +++ b/backend/src/settings/steam_deck/power_dpm_force.rs @@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; -use sysfuss::{BasicEntityPath, SysAttribute, SysEntityAttributesExt}; +use sysfuss::{BasicEntityPath, SysEntityAttributesExt, SysAttributeExt}; use crate::settings::SettingError; diff --git a/backend/src/settings/steam_deck/util.rs b/backend/src/settings/steam_deck/util.rs index 3f02be1..9343757 100644 --- a/backend/src/settings/steam_deck/util.rs +++ b/backend/src/settings/steam_deck/util.rs @@ -1,9 +1,13 @@ #![allow(dead_code)] +use std::sync::Mutex; + pub const JUPITER_HWMON_NAME: &'static str = "jupiter"; pub const STEAMDECK_HWMON_NAME: &'static str = "steamdeck_hwmon"; pub const GPU_HWMON_NAME: &'static str = "amdgpu"; +pub static THING_EC: Mutex = Mutex::new(smokepatio::ec::unnamed_power::UnnamedPowerEC::new()); + pub fn range_min_or_fallback( range: &Option>, fallback: I, @@ -25,6 +29,7 @@ pub fn card_also_has(card: &dyn sysfuss::SysEntity, extensions: &'static [&'stat } const THINGS: &[u8] = &[ + 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, @@ -35,13 +40,14 @@ const TIME_UNIT: std::time::Duration = std::time::Duration::from_millis(250); pub fn flash_led() { use smokepatio::ec::ControllerSet; - let mut ec = smokepatio::ec::unnamed_power::UnnamedPowerEC::new(); + + let mut ec = THING_EC.lock().unwrap(); for &code in THINGS { let on = code != 0; let colour = if on { smokepatio::ec::unnamed_power::StaticColour::Red } else { - smokepatio::ec::unnamed_power::StaticColour::Off + smokepatio::ec::unnamed_power::StaticColour::Disabled }; if let Err(e) = ec.set(colour) { log::error!("Thing err: {}", e); diff --git a/package.json b/package.json index e3e3573..1406247 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PowerTools", - "version": "2.0.2-alpha1", + "version": "2.0.3-alpha1", "description": "Power tweaks for power users", "scripts": { "build": "shx rm -rf dist && rollup -c",