2024-01-14 09:40:34 +11:00
|
|
|
use std::{path::PathBuf, sync::OnceLock};
|
|
|
|
|
2023-12-25 21:22:08 +11:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2024-01-08 12:00:09 +11:00
|
|
|
use crate::types::Coords;
|
2023-12-28 12:41:05 +11:00
|
|
|
|
2024-01-14 09:40:34 +11:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-25 21:22:08 +11:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
2023-12-26 08:58:14 +11:00
|
|
|
pub struct Config {
|
2024-01-16 11:00:11 +11:00
|
|
|
pub tesla_update_interval_seconds: u64,
|
2024-01-16 12:28:15 +11:00
|
|
|
pub tesla_update_interval_while_charging_seconds: u64,
|
2024-01-12 09:27:38 +11:00
|
|
|
pub pl_watch_interval_seconds: u64,
|
|
|
|
pub pl_timeout_milliseconds: u64,
|
2023-12-28 12:41:05 +11:00
|
|
|
pub coords: Coords,
|
2024-01-10 15:22:28 +11:00
|
|
|
pub serial_port: String,
|
|
|
|
pub baud_rate: u32,
|
2024-01-16 11:00:11 +11:00
|
|
|
pub shutoff_voltage: f64,
|
2024-01-16 12:28:15 +11:00
|
|
|
pub shutoff_voltage_time_seconds: u64,
|
2024-01-16 11:00:11 +11:00
|
|
|
pub min_rate: i64,
|
|
|
|
pub max_rate: i64,
|
|
|
|
pub duty_cycle_too_high: f64,
|
|
|
|
pub duty_cycle_too_low: f64,
|
2023-12-26 08:58:14 +11:00
|
|
|
}
|
2023-12-25 21:22:08 +11:00
|
|
|
|
2023-12-26 08:58:14 +11:00
|
|
|
impl Default for Config {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2024-01-16 11:00:11 +11:00
|
|
|
tesla_update_interval_seconds: 120,
|
2024-01-16 12:28:15 +11:00
|
|
|
tesla_update_interval_while_charging_seconds: 5,
|
2024-01-12 09:27:38 +11:00
|
|
|
pl_watch_interval_seconds: 30,
|
|
|
|
pl_timeout_milliseconds: 250,
|
2023-12-28 12:41:05 +11:00
|
|
|
coords: Coords {
|
|
|
|
latitude: 0.,
|
|
|
|
longitude: 0.,
|
|
|
|
},
|
2024-01-10 15:22:28 +11:00
|
|
|
serial_port: String::from("/dev/ttyUSB0"),
|
|
|
|
baud_rate: 9600,
|
2024-01-16 11:00:11 +11:00
|
|
|
shutoff_voltage: 52.,
|
2024-01-16 12:28:15 +11:00
|
|
|
shutoff_voltage_time_seconds: 15,
|
2024-01-16 11:00:11 +11:00
|
|
|
min_rate: 5,
|
|
|
|
max_rate: 10,
|
|
|
|
duty_cycle_too_high: 0.9,
|
|
|
|
duty_cycle_too_low: 0.7,
|
2023-12-26 08:58:14 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|