Fix compile errors from smokepatio refactor, fix warnings from new compiler version
This commit is contained in:
parent
4eaf6fae2b
commit
743f642580
11 changed files with 58 additions and 34 deletions
7
backend/Cargo.lock
generated
7
backend/Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mod cpu;
|
||||
mod gpu;
|
||||
|
||||
pub use cpu::{Cpu, Cpus};
|
||||
pub use cpu::Cpus;
|
||||
pub use gpu::Gpu;
|
||||
|
||||
fn _impl_checker() {
|
||||
|
|
|
@ -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<HwMonPath>,
|
||||
bat_ec: Arc<Mutex<UnnamedPowerEC>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -39,6 +40,7 @@ struct EventInstruction {
|
|||
charge_mode: Option<ChargeMode>,
|
||||
is_triggered: bool,
|
||||
sysfs_hwmon: Arc<HwMonPath>,
|
||||
bat_ec: Arc<Mutex<UnnamedPowerEC>>,
|
||||
}
|
||||
|
||||
impl OnPowerEvent for EventInstruction {
|
||||
|
@ -116,7 +118,7 @@ impl EventInstruction {
|
|||
}
|
||||
}
|
||||
|
||||
fn from_json(other: BatteryEventJson, _version: u64, hwmon: Arc<HwMonPath>) -> Self {
|
||||
fn from_json(other: BatteryEventJson, _version: u64, hwmon: Arc<HwMonPath>, ec: Arc<Mutex<UnnamedPowerEC>>) -> 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<BatteryJson> for Battery {
|
|||
impl ProviderBuilder<BatteryJson, GenericBatteryLimit> 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<BatteryJson, GenericBatteryLimit> 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<BatteryJson, GenericBatteryLimit> 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<BatteryJson, GenericBatteryLimit> 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(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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) });
|
||||
|
|
Loading…
Reference in a new issue