tesla-charge-controller/src/config.rs

55 lines
1.6 KiB
Rust

use std::{path::PathBuf, sync::OnceLock};
use serde::{Deserialize, Serialize};
use crate::types::Coords;
pub(super) static CONFIG_PATH: OnceLock<PathBuf> = OnceLock::new();
static CONFIG: OnceLock<Config> = OnceLock::new();
pub fn access_config<'a>() -> &'a Config {
CONFIG.get_or_init(|| {
ron::from_str(&std::fs::read_to_string(CONFIG_PATH.get().unwrap()).unwrap()).unwrap()
})
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Config {
pub tesla_update_interval_seconds: u64,
pub tesla_update_interval_while_charging_seconds: u64,
pub pl_watch_interval_seconds: u64,
pub pl_timeout_milliseconds: u64,
pub coords: Coords,
pub serial_port: String,
pub baud_rate: u32,
pub shutoff_voltage: f64,
pub shutoff_voltage_time_seconds: u64,
pub min_rate: i64,
pub max_rate: i64,
pub duty_cycle_too_high: f64,
pub duty_cycle_too_low: f64,
}
impl Default for Config {
fn default() -> Self {
Self {
tesla_update_interval_seconds: 120,
tesla_update_interval_while_charging_seconds: 5,
pl_watch_interval_seconds: 30,
pl_timeout_milliseconds: 250,
coords: Coords {
latitude: 0.,
longitude: 0.,
},
serial_port: String::from("/dev/ttyUSB0"),
baud_rate: 9600,
shutoff_voltage: 52.,
shutoff_voltage_time_seconds: 15,
min_rate: 5,
max_rate: 10,
duty_cycle_too_high: 0.9,
duty_cycle_too_low: 0.7,
}
}
}