1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-27 17:07:44 +00:00

config: prefer a named struct over tuple for battery conf

This commit is contained in:
NotAShelf 2025-05-15 20:32:59 +03:00
parent 45b6672c64
commit b9cce7b634
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF
3 changed files with 19 additions and 10 deletions

View file

@ -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 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() {

View file

@ -1,6 +1,12 @@
// Configuration types and structures for superfreq
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
#[derive(Deserialize, Debug, Clone)]
@ -13,7 +19,8 @@ pub struct ProfileConfig {
pub max_freq_mhz: Option<u32>,
pub platform_profile: Option<String>,
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 {
@ -87,7 +94,8 @@ pub struct ProfileConfigToml {
pub min_freq_mhz: Option<u32>,
pub max_freq_mhz: Option<u32>,
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)]
@ -96,10 +104,9 @@ pub struct AppConfigToml {
pub charger: ProfileConfigToml,
#[serde(default)]
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>>,
#[serde(default = "default_poll_interval_sec")]
pub poll_interval_sec: u64,
#[serde(default)]
pub daemon: DaemonConfigToml,
}

View file

@ -147,9 +147,10 @@ pub fn determine_and_apply_settings(
}
// Set battery charge thresholds if configured
if let Some((start_threshold, stop_threshold)) =
selected_profile_config.battery_charge_thresholds
{
if let Some(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 {
info!("Setting battery charge thresholds: {start_threshold}-{stop_threshold}%");
match battery::set_battery_charge_thresholds(start_threshold, stop_threshold) {