Compare commits

...

4 commits

13 changed files with 160 additions and 14 deletions

View file

@ -1,5 +1,5 @@
use std::default::Default;
use serde::{Deserialize, Serialize};
use std::default::Default;
/// Base JSON limits information
#[derive(Serialize, Deserialize, Debug, Clone)]
@ -131,7 +131,7 @@ impl Default for Base {
name: "AMD R7 6800U".to_owned(),
conditions: super::Conditions {
dmi: None,
cpuinfo: Some("model name\t+: AMD Ryzen 7 6800U\n".to_owned()),
cpuinfo: Some("model name\t+: AMD Ryzen 7 6800U( with Radeon Graphics)?\n".to_owned()),
os: None,
command: None,
file_exists: None,

View file

@ -4,7 +4,9 @@ use super::RangeLimit;
#[derive(Serialize, Deserialize, Debug, Clone)]
//#[serde(tag = "target")]
pub enum BatteryLimitType {
#[serde(rename = "GabeBoy", alias = "SteamDeck")]
SteamDeck,
#[serde(rename = "GabeBoyAdvance", alias = "SteamDeckAdvance")]
SteamDeckAdvance,
Generic,
Unknown,

View file

@ -5,7 +5,9 @@ use super::RangeLimit;
#[derive(Serialize, Deserialize, Debug, Clone)]
//#[serde(tag = "target")]
pub enum CpuLimitType {
#[serde(rename = "GabeBoy", alias = "SteamDeck")]
SteamDeck,
#[serde(rename = "GabeBoyAdvance", alias = "SteamDeckAdvance")]
SteamDeckAdvance,
Generic,
GenericAMD,

View file

@ -4,7 +4,9 @@ use super::RangeLimit;
#[derive(Serialize, Deserialize, Debug, Clone)]
//#[serde(tag = "target")]
pub enum GpuLimitType {
#[serde(rename = "GabeBoy", alias = "SteamDeck")]
SteamDeck,
#[serde(rename = "GabeBoyAdvance", alias = "SteamDeckAdvance")]
SteamDeckAdvance,
Generic,
GenericAMD,

View file

@ -214,7 +214,7 @@
"name": "AMD R7 6800U",
"conditions": {
"dmi": null,
"cpuinfo": "model name\t+: AMD Ryzen 7 6800U\n",
"cpuinfo": "model name\t+: AMD Ryzen 7 6800U( with Radeon Graphics)?\n",
"os": null,
"command": null,
"file_exists": null

View file

@ -76,7 +76,7 @@ fn main() -> Result<(), ()> {
let mut loaded_settings =
persist::FileJson::open(utility::settings_dir().join(DEFAULT_SETTINGS_FILE))
.map(|mut file| file.variants.remove("0")
.map(|mut file| file.variants.remove(&0)
.map(|settings| settings::Settings::from_json(DEFAULT_SETTINGS_NAME.into(), settings, DEFAULT_SETTINGS_FILE.into()))
.unwrap_or_else(|| settings::Settings::system_default(
DEFAULT_SETTINGS_FILE.into(),

View file

@ -9,7 +9,7 @@ use super::SettingsJson;
pub struct FileJson {
pub version: u64,
pub name: String,
pub variants: HashMap<String, SettingsJson>,
pub variants: HashMap<u64, SettingsJson>,
}
impl FileJson {
@ -45,11 +45,11 @@ impl FileJson {
let file = if path.exists() {
let mut file = Self::open(path)?;
file.variants.insert(setting.variant.to_string(), setting);
file.variants.insert(setting.variant, setting);
file
} else {
let mut setting_variants = HashMap::with_capacity(1);
setting_variants.insert(setting.variant.to_string(), setting);
setting_variants.insert(setting.variant, setting);
Self {
version: 0,
name: given_name,

View file

@ -20,7 +20,7 @@ impl Default for SettingsJson {
fn default() -> Self {
Self {
version: 0,
name: crate::consts::DEFAULT_SETTINGS_NAME.to_owned(),
name: crate::consts::DEFAULT_SETTINGS_VARIANT_NAME.to_owned(),
variant: 0,
persistent: false,
cpus: Vec::with_capacity(8),

View file

@ -178,7 +178,7 @@ impl Settings {
}
pub fn get_variant<'a>(settings_file: &'a FileJson, variant_id: u64, variant_name: String) -> Result<&'a SettingsJson, SettingError> {
if let Some(variant) = settings_file.variants.get(&variant_id.to_string()) {
if let Some(variant) = settings_file.variants.get(&variant_id) {
Ok(variant)
} else {
Err(SettingError {

View file

@ -597,7 +597,7 @@ impl OnPowerEvent for Battery {
// only true when charge_limit_set is false and self.state.charge_limit_set is true
self.state.charge_limit_set = false;
if attr_exists {
self.sysfs_hwmon.set(MAX_BATTERY_CHARGE_LEVEL_ATTR, 100)
self.sysfs_hwmon.set(MAX_BATTERY_CHARGE_LEVEL_ATTR, 0)
.unwrap_or_else(|e| errors.push(
SettingError {
msg: format!("Failed to reset (write to) {:?}: {}", MAX_BATTERY_CHARGE_LEVEL_ATTR, e),

View file

@ -121,8 +121,40 @@ mod generate {
limits: limits_core::json_v2::GenericBatteryLimit::default_for(limits_core::json_v2::BatteryLimitType::SteamDeck),
},
};
let output_file = std::fs::File::create("../limits_override.ron").unwrap();
let output_file = std::fs::File::create(format!("../{}", crate::consts::LIMITS_OVERRIDE_FILE)).unwrap();
ron::ser::to_writer_pretty(output_file, &limits, crate::utility::ron_pretty_config()).unwrap();
}
#[test]
fn generate_default_minimal_save_file() {
let mut mini_variants = std::collections::HashMap::with_capacity(2);
mini_variants.insert(0, crate::persist::SettingsJson {
version: 0,
name: crate::consts::DEFAULT_SETTINGS_VARIANT_NAME.to_owned(),
variant: 0,
persistent: false,
cpus: vec![crate::persist::CpuJson::default(); 8],
gpu: crate::persist::GpuJson::default(),
battery: crate::persist::BatteryJson::default(),
provider: None,
});
mini_variants.insert(42, crate::persist::SettingsJson {
version: 0,
name: "FortySecondary".to_owned(),
variant: 42,
persistent: false,
cpus: vec![crate::persist::CpuJson::default(); 8],
gpu: crate::persist::GpuJson::default(),
battery: crate::persist::BatteryJson::default(),
provider: None,
});
let savefile = crate::persist::FileJson {
version: 0,
name: crate::consts::DEFAULT_SETTINGS_NAME.to_owned(),
variants: mini_variants,
};
let output_file = std::fs::File::create(format!("../{}", crate::consts::DEFAULT_SETTINGS_FILE)).unwrap();
ron::ser::to_writer_pretty(output_file, &savefile, crate::utility::ron_pretty_config()).unwrap();
}
}

108
default_settings.ron Normal file
View file

@ -0,0 +1,108 @@
FileJson(
version: 0,
name: "Main",
variants: {
0: SettingsJson(
version: 0,
name: "Primary",
variant: 0,
persistent: false,
cpus: [CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
)],
gpu: GpuJson(
fast_ppt: None,
slow_ppt: None,
clock_limits: None,
slow_memory: false,
),
battery: BatteryJson(
charge_rate: None,
charge_mode: None,
events: [],
),
provider: None,
),
42: SettingsJson(
version: 0,
name: "FortySecondary",
variant: 42,
persistent: false,
cpus: [CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
), CpuJson(
online: true,
clock_limits: None,
governor: "schedutil",
)],
gpu: GpuJson(
fast_ppt: None,
slow_ppt: None,
clock_limits: None,
slow_memory: false,
),
battery: BatteryJson(
charge_rate: None,
charge_mode: None,
events: [],
),
provider: None,
),
},
)

View file

@ -1,6 +1,6 @@
Limits(
cpu: Limit(
provider: SteamDeck,
provider: GabeBoy,
limits: GenericCpusLimit(
cpus: [GenericCpuLimit(
clock_min: Some(RangeLimit(
@ -95,7 +95,7 @@ Limits(
),
),
gpu: Limit(
provider: SteamDeck,
provider: GabeBoy,
limits: GenericGpuLimit(
fast_ppt: Some(RangeLimit(
min: Some(1000000),
@ -125,7 +125,7 @@ Limits(
),
),
battery: Limit(
provider: SteamDeck,
provider: GabeBoy,
limits: GenericBatteryLimit(
charge_rate: Some(RangeLimit(
min: Some(250),