From 743f6425806d999d40ecea3b752082012386fa80 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 13 Jan 2024 12:32:12 -0500 Subject: [PATCH] Fix compile errors from smokepatio refactor, fix warnings from new compiler version --- backend/Cargo.lock | 7 +++ backend/Cargo.toml | 2 +- backend/src/persist/mod.rs | 2 +- backend/src/settings/generic_amd/mod.rs | 2 +- backend/src/settings/steam_deck/battery.rs | 54 +++++++++++++--------- backend/src/settings/steam_deck/mod.rs | 2 +- backend/src/settings/steam_deck/util.rs | 7 ++- backend/src/settings/unknown/mod.rs | 2 +- backend/src/state/mod.rs | 8 ++-- src/consts.ts | 2 + src/index.tsx | 4 ++ 11 files changed, 58 insertions(+), 34 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 0daaacc..8ea1bcf 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -370,6 +370,12 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "encoding" version = "0.2.33" @@ -1327,6 +1333,7 @@ dependencies = [ name = "smokepatio" version = "0.1.0" dependencies = [ + "embedded-io", "log", ] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 15a72f7..e419cd1 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -30,7 +30,7 @@ simplelog = "0.12" limits_core = { version = "3", path = "./limits_core" } community_settings_core = { version = "0.1", path = "./community_settings_core" } regex = "1" -smokepatio = { version = "*", path = "../../smokepatio" } +smokepatio = { version = "0.1", features = [ "std" ], path = "../../smokepatio" } #libryzenadj = { version = "0.14", path = "../../libryzenadj-rs-14" } libryzenadj = { version = "0.13" } # ureq's tls feature does not like musl targets diff --git a/backend/src/persist/mod.rs b/backend/src/persist/mod.rs index 809890d..bfc0b2a 100644 --- a/backend/src/persist/mod.rs +++ b/backend/src/persist/mod.rs @@ -13,6 +13,6 @@ pub use file::FileJson; pub use general::{MinMaxJson, SettingsJson}; pub use gpu::GpuJson; -pub use error::{SerdeError, RonError}; +pub use error::SerdeError; pub const LATEST_VERSION: u64 = 0; diff --git a/backend/src/settings/generic_amd/mod.rs b/backend/src/settings/generic_amd/mod.rs index 0f443a9..89a2292 100644 --- a/backend/src/settings/generic_amd/mod.rs +++ b/backend/src/settings/generic_amd/mod.rs @@ -1,7 +1,7 @@ mod cpu; mod gpu; -pub use cpu::{Cpu, Cpus}; +pub use cpu::Cpus; pub use gpu::Gpu; fn _impl_checker() { diff --git a/backend/src/settings/steam_deck/battery.rs b/backend/src/settings/steam_deck/battery.rs index 1dea06c..12514aa 100644 --- a/backend/src/settings/steam_deck/battery.rs +++ b/backend/src/settings/steam_deck/battery.rs @@ -1,12 +1,12 @@ use std::convert::Into; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use sysfuss::{PowerSupplyAttribute, PowerSupplyPath, HwMonAttribute, HwMonAttributeItem, HwMonAttributeType, HwMonPath, SysEntity, SysEntityAttributesExt, SysAttribute}; use sysfuss::capability::attributes; use limits_core::json_v2::GenericBatteryLimit; -use smokepatio::ec::ChargeMode; +use smokepatio::ec::{ControllerSet, unnamed_power::{UnnamedPowerEC, ChargeMode}}; use crate::api::RangeLimit; use crate::persist::{BatteryEventJson, BatteryJson}; use crate::settings::{TBattery, ProviderBuilder}; @@ -21,6 +21,7 @@ pub struct Battery { state: crate::state::steam_deck::Battery, sysfs_bat: PowerSupplyPath, sysfs_hwmon: Arc, + bat_ec: Arc>, } #[derive(Debug, Clone)] @@ -39,6 +40,7 @@ struct EventInstruction { charge_mode: Option, is_triggered: bool, sysfs_hwmon: Arc, + bat_ec: Arc>, } impl OnPowerEvent for EventInstruction { @@ -116,7 +118,7 @@ impl EventInstruction { } } - fn from_json(other: BatteryEventJson, _version: u64, hwmon: Arc) -> Self { + fn from_json(other: BatteryEventJson, _version: u64, hwmon: Arc, ec: Arc>) -> Self { Self { trigger: Self::str_to_trigger(&other.trigger).unwrap_or(EventTrigger::Ignored), charge_rate: other.charge_rate, @@ -126,17 +128,17 @@ impl EventInstruction { .flatten(), is_triggered: false, sysfs_hwmon: hwmon, + bat_ec: ec, } } fn set_charge_mode(&self) -> Result<(), SettingError> { if let Some(charge_mode) = self.charge_mode { - smokepatio::ec::set(smokepatio::ec::Setting::ChargeMode, charge_mode as _) - .map_err(|e| SettingError { - msg: format!("Failed to set charge mode: {}", e), - setting: crate::settings::SettingVariant::Battery, - }) - .map(|_| ()) + let mut lock = self.bat_ec.lock().expect("failed to lock battery controller"); + lock.set(charge_mode).map_err(|_| SettingError { + msg: format!("Failed to set charge mode"), + setting: crate::settings::SettingVariant::Battery, + }) } else { Ok(()) } @@ -329,20 +331,18 @@ impl Battery { fn set_charge_mode(&mut self) -> Result<(), SettingError> { if let Some(charge_mode) = self.charge_mode { self.state.charge_mode_set = true; - smokepatio::ec::set(smokepatio::ec::Setting::ChargeMode, charge_mode as _) - .map_err(|e| SettingError { - msg: format!("Failed to set charge mode: {}", e), - setting: crate::settings::SettingVariant::Battery, - }) - .map(|_| ()) + let mut lock = self.bat_ec.lock().expect("Failed to lock battery controller"); + lock.set(charge_mode).map_err(|_| SettingError { + msg: format!("Failed to set charge mode"), + setting: crate::settings::SettingVariant::Battery, + }) } else if self.state.charge_mode_set { self.state.charge_mode_set = false; - smokepatio::ec::set(smokepatio::ec::Setting::ChargeMode, ChargeMode::Normal as _) - .map_err(|e| SettingError { - msg: format!("Failed to set charge mode: {}", e), - setting: crate::settings::SettingVariant::Battery, - }) - .map(|_| ()) + let mut lock = self.bat_ec.lock().expect("Failed to lock battery controller"); + lock.set(ChargeMode::Normal).map_err(|_| SettingError { + msg: format!("Failed to set charge mode"), + setting: crate::settings::SettingVariant::Battery, + }) } else { Ok(()) } @@ -488,6 +488,7 @@ impl Into for Battery { impl ProviderBuilder for Battery { fn from_json_and_limits(persistent: BatteryJson, version: u64, limits: GenericBatteryLimit) -> Self { let hwmon_sys = Arc::new(Self::find_hwmon_sysfs(None::<&'static str>)); + let ec = Arc::new(Mutex::new(UnnamedPowerEC::new())); match version { 0 => Self { charge_rate: persistent.charge_rate, @@ -498,12 +499,13 @@ impl ProviderBuilder for Battery { events: persistent .events .into_iter() - .map(|x| EventInstruction::from_json(x, version, hwmon_sys.clone())) + .map(|x| EventInstruction::from_json(x, version, hwmon_sys.clone(), ec.clone())) .collect(), limits: limits, state: crate::state::steam_deck::Battery::default(), sysfs_bat: Self::find_battery_sysfs(None::<&'static str>), sysfs_hwmon: hwmon_sys, + bat_ec: ec, }, _ => Self { charge_rate: persistent.charge_rate, @@ -514,12 +516,13 @@ impl ProviderBuilder for Battery { events: persistent .events .into_iter() - .map(|x| EventInstruction::from_json(x, version, hwmon_sys.clone())) + .map(|x| EventInstruction::from_json(x, version, hwmon_sys.clone(), ec.clone())) .collect(), limits: limits, state: crate::state::steam_deck::Battery::default(), sysfs_bat: Self::find_battery_sysfs(None::<&'static str>), sysfs_hwmon: hwmon_sys, + bat_ec: ec, }, } } @@ -533,6 +536,7 @@ impl ProviderBuilder for Battery { state: crate::state::steam_deck::Battery::default(), sysfs_bat: Self::find_battery_sysfs(None::<&'static str>), sysfs_hwmon: Arc::new(Self::find_hwmon_sysfs(None::<&'static str>)), + bat_ec: Arc::new(Mutex::new(UnnamedPowerEC::new())), } } } @@ -728,6 +732,7 @@ impl TBattery for Battery { charge_mode: Some(ChargeMode::Idle), is_triggered: false, sysfs_hwmon: self.sysfs_hwmon.clone(), + bat_ec: self.bat_ec.clone(), }; } else { self.events.remove(index); @@ -743,6 +748,7 @@ impl TBattery for Battery { charge_mode: Some(ChargeMode::Idle), is_triggered: false, sysfs_hwmon: self.sysfs_hwmon.clone(), + bat_ec: self.bat_ec.clone(), }); } // lower limit @@ -760,6 +766,7 @@ impl TBattery for Battery { charge_mode: Some(ChargeMode::Normal), is_triggered: false, sysfs_hwmon: self.sysfs_hwmon.clone(), + bat_ec: self.bat_ec.clone(), }; } else { self.events.remove(index); @@ -776,6 +783,7 @@ impl TBattery for Battery { charge_mode: Some(ChargeMode::Normal), is_triggered: false, sysfs_hwmon: self.sysfs_hwmon.clone(), + bat_ec: self.bat_ec.clone(), }); } } diff --git a/backend/src/settings/steam_deck/mod.rs b/backend/src/settings/steam_deck/mod.rs index 676d7fe..b3f840d 100644 --- a/backend/src/settings/steam_deck/mod.rs +++ b/backend/src/settings/steam_deck/mod.rs @@ -5,7 +5,7 @@ mod power_dpm_force; mod util; pub use battery::Battery; -pub use cpu::{Cpu, Cpus}; +pub use cpu::Cpus; pub use gpu::Gpu; pub(self) use power_dpm_force::{POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT, DPM_FORCE_LIMITS_ATTRIBUTE}; diff --git a/backend/src/settings/steam_deck/util.rs b/backend/src/settings/steam_deck/util.rs index c57c70a..2d37f51 100644 --- a/backend/src/settings/steam_deck/util.rs +++ b/backend/src/settings/steam_deck/util.rs @@ -27,15 +27,18 @@ const THINGS: &[u8] = &[ const TIME_UNIT: std::time::Duration = std::time::Duration::from_millis(200); pub fn flash_led() { + use smokepatio::ec::ControllerSet; + let mut ec = smokepatio::ec::unnamed_power::UnnamedPowerEC::new(); for &code in THINGS { let on = code != 0; - if let Err(e) = smokepatio::ec::led::constant::set(if on { smokepatio::ec::led::constant::Colour::White } else { smokepatio::ec::led::constant::Colour::Off }) { + let colour = if on { smokepatio::ec::unnamed_power::StaticColour::Red } else { smokepatio::ec::unnamed_power::StaticColour::Off }; + if let Err(e) = ec.set(colour) { log::error!("Thing err: {}", e); } std::thread::sleep(TIME_UNIT); } log::debug!("Restoring LED state"); - smokepatio::ec::led::constant::set(smokepatio::ec::led::constant::Colour::Off) + ec.set(smokepatio::ec::unnamed_power::StaticColour::Off) .map_err(|e| log::error!("Failed to restore LED status: {}", e)) .unwrap(); } diff --git a/backend/src/settings/unknown/mod.rs b/backend/src/settings/unknown/mod.rs index bd0f419..200c1ea 100644 --- a/backend/src/settings/unknown/mod.rs +++ b/backend/src/settings/unknown/mod.rs @@ -3,7 +3,7 @@ mod cpu; mod gpu; pub use battery::Battery; -pub use cpu::{Cpu, Cpus}; +pub use cpu::Cpus; pub use gpu::Gpu; fn _impl_checker() { diff --git a/backend/src/state/mod.rs b/backend/src/state/mod.rs index 570de60..cd8d3bc 100644 --- a/backend/src/state/mod.rs +++ b/backend/src/state/mod.rs @@ -1,8 +1,8 @@ -mod error; -mod traits; +//mod error; +//mod traits; pub mod generic; pub mod steam_deck; -pub use error::StateError; -pub use traits::OnPoll; +//pub use error::StateError; +//pub use traits::OnPoll; diff --git a/src/consts.ts b/src/consts.ts index 4364cb6..415f5a5 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -30,6 +30,8 @@ export const SLOW_MEMORY_GPU = "GPU_slow_memory"; export const PERSISTENT_GEN = "GENERAL_persistent"; export const NAME_GEN = "GENERAL_name"; export const PATH_GEN = "GENERAL_path"; +export const VARIANTS_GEN = "GENERAL_setting_variants"; +export const CURRENT_VARIANT_GEN = "GENERAL_current_variant"; export const MESSAGE_LIST = "MESSAGE_messages"; diff --git a/src/index.tsx b/src/index.tsx index e65bfbe..9dd25e1 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -58,6 +58,8 @@ import { PERSISTENT_GEN, NAME_GEN, PATH_GEN, + VARIANTS_GEN, + CURRENT_VARIANT_GEN, MESSAGE_LIST, @@ -158,6 +160,8 @@ const reload = function() { backend.resolve(backend.getGeneralPersistent(), (value: boolean) => { set_value(PERSISTENT_GEN, value) }); backend.resolve(backend.getGeneralSettingsName(), (name: string) => { set_value(NAME_GEN, name) }); backend.resolve(backend.getGeneralSettingsPath(), (path: string) => { set_value(PATH_GEN, path) }); + backend.resolve(backend.getAllSettingVariants(), (variants: backend.VariantInfo[]) => { set_value(VARIANTS_GEN, variants) }); + backend.resolve(backend.getCurrentSettingVariant(), (variant: backend.VariantInfo) => { set_value(CURRENT_VARIANT_GEN, variant) }); backend.resolve(backend.getInfo(), (info: string) => { set_value(BACKEND_INFO, info) }); backend.resolve(backend.getDriverProviderName("gpu"), (driver: string) => { set_value(DRIVER_INFO, driver) });