From e0ddee9e074c3f82be7e0a3de4d633ac7494d6b8 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 18 Nov 2023 15:55:17 -0500 Subject: [PATCH] Update .json to .ron in various places, fix tests --- backend/src/api/handler.rs | 2 +- backend/src/consts.rs | 6 +- backend/src/settings/detect/utility.rs | 2 +- backend/src/settings/mod.rs | 2 +- backend/src/settings/util.rs | 1 + backend/src/utility.rs | 23 ++++ limits_override.ron | 142 +++++++++++++++++++++++++ 7 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 limits_override.ron diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index 56b2177..69234c6 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -368,7 +368,7 @@ impl ApiMessageHandler { false } ApiMessage::LoadSettings(id, name, variant_id, variant_name) => { - let path = format!("{}.json", id); + let path = format!("{}.ron", id); match settings.load_file(path.into(), name, variant_id, variant_name, false) { Ok(success) => log::info!("Loaded settings file? {}", success), Err(e) => log::warn!("Load file err: {}", e), diff --git a/backend/src/consts.rs b/backend/src/consts.rs index ec650fe..531ce20 100644 --- a/backend/src/consts.rs +++ b/backend/src/consts.rs @@ -3,12 +3,12 @@ pub const PORT: u16 = 44443; pub const PACKAGE_NAME: &'static str = env!("CARGO_PKG_NAME"); pub const PACKAGE_VERSION: &'static str = env!("CARGO_PKG_VERSION"); -pub const DEFAULT_SETTINGS_FILE: &str = "default_settings.json"; +pub const DEFAULT_SETTINGS_FILE: &str = "default_settings.ron"; pub const DEFAULT_SETTINGS_NAME: &str = "Main"; pub const DEFAULT_SETTINGS_VARIANT_NAME: &str = "Primary"; -pub const LIMITS_FILE: &str = "limits_cache.json"; -pub const LIMITS_OVERRIDE_FILE: &str = "limits_override.json"; +pub const LIMITS_FILE: &str = "limits_cache.ron"; +pub const LIMITS_OVERRIDE_FILE: &str = "limits_override.ron"; pub const MESSAGE_SEEN_ID_FILE: &str = "seen_message.bin"; diff --git a/backend/src/settings/detect/utility.rs b/backend/src/settings/detect/utility.rs index 7d42be0..7f14b5f 100644 --- a/backend/src/settings/detect/utility.rs +++ b/backend/src/settings/detect/utility.rs @@ -12,7 +12,7 @@ pub fn limits_override_path() -> std::path::PathBuf { pub fn get_dev_messages() -> Vec { let limits_path = limits_path(); if let Ok(file) = std::fs::File::open(&limits_path) { - if let Ok(base) = serde_json::from_reader::<_, Base>(file) { + if let Ok(base) = ron::de::from_reader::<_, Base>(file) { base.messages } else { vec![] diff --git a/backend/src/settings/mod.rs b/backend/src/settings/mod.rs index 5aa3483..5bcb3f4 100644 --- a/backend/src/settings/mod.rs +++ b/backend/src/settings/mod.rs @@ -23,7 +23,7 @@ pub use traits::{OnPowerEvent, OnResume, OnSet, PowerMode, TBattery, TCpu, TCpus mod tests { #[test] fn system_defaults_test() { - let settings = super::Settings::system_default("idc".into(), "Cool name".into()); + let settings = super::Settings::system_default("idc".into(), "Cool name".into(), 0, "Variant 0".into()); println!("Loaded system settings: {:?}", settings); } } diff --git a/backend/src/settings/util.rs b/backend/src/settings/util.rs index cede8f6..6d4e8ed 100644 --- a/backend/src/settings/util.rs +++ b/backend/src/settings/util.rs @@ -58,6 +58,7 @@ mod test { fn cpu_with_online(status: bool) -> CpuJson { CpuJson { + root: None, online: status, clock_limits: None, governor: "schedutil".to_owned(), diff --git a/backend/src/utility.rs b/backend/src/utility.rs index 00dae0b..595f17a 100644 --- a/backend/src/utility.rs +++ b/backend/src/utility.rs @@ -103,3 +103,26 @@ pub fn read_version_file() -> String { } } } +#[cfg(test)] +mod generate { + #[test] + fn generate_default_limits_override() { + let limits = limits_core::json_v2::Limits { + cpu: limits_core::json_v2::Limit { + provider: limits_core::json_v2::CpuLimitType::SteamDeck, + limits: limits_core::json_v2::GenericCpusLimit::default_for(limits_core::json_v2::CpuLimitType::SteamDeck), + }, + gpu: limits_core::json_v2::Limit { + provider: limits_core::json_v2::GpuLimitType::SteamDeck, + limits: limits_core::json_v2::GenericGpuLimit::default_for(limits_core::json_v2::GpuLimitType::SteamDeck), + }, + battery: limits_core::json_v2::Limit { + provider: limits_core::json_v2::BatteryLimitType::SteamDeck, + 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(); + ron::ser::to_writer_pretty(output_file, &limits, crate::utility::ron_pretty_config()).unwrap(); + } +} + diff --git a/limits_override.ron b/limits_override.ron new file mode 100644 index 0000000..f5cb160 --- /dev/null +++ b/limits_override.ron @@ -0,0 +1,142 @@ +Limits( + cpu: Limit( + provider: SteamDeck, + limits: GenericCpusLimit( + cpus: [GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), GenericCpuLimit( + clock_min: Some(RangeLimit( + min: Some(1400), + max: Some(3500), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(3500), + )), + clock_step: Some(100), + skip_resume_reclock: false, + )], + global_governors: true, + ), + ), + gpu: Limit( + provider: SteamDeck, + limits: GenericGpuLimit( + fast_ppt: Some(RangeLimit( + min: Some(1000000), + max: Some(30000000), + )), + fast_ppt_default: Some(15000000), + slow_ppt: Some(RangeLimit( + min: Some(1000000), + max: Some(29000000), + )), + slow_ppt_default: Some(15000000), + ppt_divisor: Some(1000000), + ppt_step: Some(1), + tdp: None, + tdp_boost: None, + tdp_step: None, + clock_min: Some(RangeLimit( + min: Some(400), + max: Some(1600), + )), + clock_max: Some(RangeLimit( + min: Some(400), + max: Some(1600), + )), + clock_step: Some(100), + skip_resume_reclock: false, + ), + ), + battery: Limit( + provider: SteamDeck, + limits: GenericBatteryLimit( + charge_rate: Some(RangeLimit( + min: Some(250), + max: Some(2500), + )), + charge_modes: ["normal", "discharge", "idle"], + charge_limit: Some(RangeLimit( + min: Some(10.0), + max: Some(90.0), + )), + extra_readouts: false, + ), + ), +) \ No newline at end of file