Update .json to .ron in various places, fix tests

This commit is contained in:
NGnius (Graham) 2023-11-18 15:55:17 -05:00
parent 396a52da5e
commit e0ddee9e07
7 changed files with 172 additions and 6 deletions

View file

@ -368,7 +368,7 @@ impl ApiMessageHandler {
false false
} }
ApiMessage::LoadSettings(id, name, variant_id, variant_name) => { 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) { match settings.load_file(path.into(), name, variant_id, variant_name, false) {
Ok(success) => log::info!("Loaded settings file? {}", success), Ok(success) => log::info!("Loaded settings file? {}", success),
Err(e) => log::warn!("Load file err: {}", e), Err(e) => log::warn!("Load file err: {}", e),

View file

@ -3,12 +3,12 @@ pub const PORT: u16 = 44443;
pub const PACKAGE_NAME: &'static str = env!("CARGO_PKG_NAME"); pub const PACKAGE_NAME: &'static str = env!("CARGO_PKG_NAME");
pub const PACKAGE_VERSION: &'static str = env!("CARGO_PKG_VERSION"); 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_NAME: &str = "Main";
pub const DEFAULT_SETTINGS_VARIANT_NAME: &str = "Primary"; pub const DEFAULT_SETTINGS_VARIANT_NAME: &str = "Primary";
pub const LIMITS_FILE: &str = "limits_cache.json"; pub const LIMITS_FILE: &str = "limits_cache.ron";
pub const LIMITS_OVERRIDE_FILE: &str = "limits_override.json"; pub const LIMITS_OVERRIDE_FILE: &str = "limits_override.ron";
pub const MESSAGE_SEEN_ID_FILE: &str = "seen_message.bin"; pub const MESSAGE_SEEN_ID_FILE: &str = "seen_message.bin";

View file

@ -12,7 +12,7 @@ pub fn limits_override_path() -> std::path::PathBuf {
pub fn get_dev_messages() -> Vec<DeveloperMessage> { pub fn get_dev_messages() -> Vec<DeveloperMessage> {
let limits_path = limits_path(); let limits_path = limits_path();
if let Ok(file) = std::fs::File::open(&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 base.messages
} else { } else {
vec![] vec![]

View file

@ -23,7 +23,7 @@ pub use traits::{OnPowerEvent, OnResume, OnSet, PowerMode, TBattery, TCpu, TCpus
mod tests { mod tests {
#[test] #[test]
fn system_defaults_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); println!("Loaded system settings: {:?}", settings);
} }
} }

View file

@ -58,6 +58,7 @@ mod test {
fn cpu_with_online(status: bool) -> CpuJson { fn cpu_with_online(status: bool) -> CpuJson {
CpuJson { CpuJson {
root: None,
online: status, online: status,
clock_limits: None, clock_limits: None,
governor: "schedutil".to_owned(), governor: "schedutil".to_owned(),

View file

@ -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();
}
}

142
limits_override.ron Normal file
View file

@ -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,
),
),
)