use std::{path::PathBuf, sync::OnceLock}; use serde::{Deserialize, Serialize}; use crate::types::Coords; pub(super) static CONFIG_PATH: OnceLock = OnceLock::new(); static CONFIG: OnceLock = 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_watch_interval_seconds: u64, pub pl_watch_interval_seconds: u64, pub pl_timeout_milliseconds: u64, pub coords: Coords, pub serial_port: String, pub baud_rate: u32, } impl Default for Config { fn default() -> Self { Self { tesla_watch_interval_seconds: 120, pl_watch_interval_seconds: 30, pl_timeout_milliseconds: 250, coords: Coords { latitude: 0., longitude: 0., }, serial_port: String::from("/dev/ttyUSB0"), baud_rate: 9600, } } }