mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-28 01:17:45 +00:00
config: prefer a named struct over tuple for battery conf
This commit is contained in:
parent
45b6672c64
commit
b9cce7b634
3 changed files with 19 additions and 10 deletions
|
@ -86,7 +86,8 @@ fn load_and_parse_config(path: &Path) -> Result<AppConfig, ConfigError> {
|
||||||
|
|
||||||
// If profile-specific battery thresholds are not set, inherit from global config
|
// If profile-specific battery thresholds are not set, inherit from global config
|
||||||
if charger_profile.battery_charge_thresholds.is_none() {
|
if charger_profile.battery_charge_thresholds.is_none() {
|
||||||
charger_profile.battery_charge_thresholds = toml_app_config.battery_charge_thresholds;
|
charger_profile.battery_charge_thresholds =
|
||||||
|
toml_app_config.battery_charge_thresholds.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
if battery_profile.battery_charge_thresholds.is_none() {
|
if battery_profile.battery_charge_thresholds.is_none() {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
// Configuration types and structures for superfreq
|
// Configuration types and structures for superfreq
|
||||||
use crate::core::TurboSetting;
|
use crate::core::TurboSetting;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||||
|
pub struct BatteryChargeThresholds {
|
||||||
|
pub start: u8,
|
||||||
|
pub stop: u8,
|
||||||
|
}
|
||||||
|
|
||||||
// Structs for configuration using serde::Deserialize
|
// Structs for configuration using serde::Deserialize
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
@ -13,7 +19,8 @@ pub struct ProfileConfig {
|
||||||
pub max_freq_mhz: Option<u32>,
|
pub max_freq_mhz: Option<u32>,
|
||||||
pub platform_profile: Option<String>,
|
pub platform_profile: Option<String>,
|
||||||
pub turbo_auto_settings: Option<TurboAutoSettings>,
|
pub turbo_auto_settings: Option<TurboAutoSettings>,
|
||||||
pub battery_charge_thresholds: Option<(u8, u8)>,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub battery_charge_thresholds: Option<BatteryChargeThresholds>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ProfileConfig {
|
impl Default for ProfileConfig {
|
||||||
|
@ -87,7 +94,8 @@ pub struct ProfileConfigToml {
|
||||||
pub min_freq_mhz: Option<u32>,
|
pub min_freq_mhz: Option<u32>,
|
||||||
pub max_freq_mhz: Option<u32>,
|
pub max_freq_mhz: Option<u32>,
|
||||||
pub platform_profile: Option<String>,
|
pub platform_profile: Option<String>,
|
||||||
pub battery_charge_thresholds: Option<(u8, u8)>,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub battery_charge_thresholds: Option<BatteryChargeThresholds>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone, Default)]
|
#[derive(Deserialize, Debug, Clone, Default)]
|
||||||
|
@ -96,10 +104,9 @@ pub struct AppConfigToml {
|
||||||
pub charger: ProfileConfigToml,
|
pub charger: ProfileConfigToml,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub battery: ProfileConfigToml,
|
pub battery: ProfileConfigToml,
|
||||||
pub battery_charge_thresholds: Option<(u8, u8)>,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub battery_charge_thresholds: Option<BatteryChargeThresholds>,
|
||||||
pub ignored_power_supplies: Option<Vec<String>>,
|
pub ignored_power_supplies: Option<Vec<String>>,
|
||||||
#[serde(default = "default_poll_interval_sec")]
|
|
||||||
pub poll_interval_sec: u64,
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub daemon: DaemonConfigToml,
|
pub daemon: DaemonConfigToml,
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,9 +147,10 @@ pub fn determine_and_apply_settings(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set battery charge thresholds if configured
|
// Set battery charge thresholds if configured
|
||||||
if let Some((start_threshold, stop_threshold)) =
|
if let Some(thresholds) = &selected_profile_config.battery_charge_thresholds {
|
||||||
selected_profile_config.battery_charge_thresholds
|
let start_threshold = thresholds.start;
|
||||||
{
|
let stop_threshold = thresholds.stop;
|
||||||
|
|
||||||
if start_threshold < stop_threshold && stop_threshold <= 100 {
|
if start_threshold < stop_threshold && stop_threshold <= 100 {
|
||||||
info!("Setting battery charge thresholds: {start_threshold}-{stop_threshold}%");
|
info!("Setting battery charge thresholds: {start_threshold}-{stop_threshold}%");
|
||||||
match battery::set_battery_charge_thresholds(start_threshold, stop_threshold) {
|
match battery::set_battery_charge_thresholds(start_threshold, stop_threshold) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue