PlantCtrl/rust/src/config.rs
2025-03-31 21:33:10 +02:00

120 lines
3.1 KiB
Rust

use std::str::FromStr;
use chrono_tz::{Europe::Berlin, Tz};
use serde::{Deserialize, Serialize};
use crate::PLANT_COUNT;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(default)]
pub struct NetworkConfig {
pub ap_ssid: heapless::String<32>,
pub ssid: Option<heapless::String<32>>,
pub password: Option<heapless::String<64>>,
pub mqtt_url: Option<heapless::String<128>>,
pub base_topic: Option<heapless::String<64>>,
pub timezone: heapless::String<64>,
}
impl Default for NetworkConfig {
fn default() -> Self {
Self {
ap_ssid: heapless::String::from_str("PlantCtrl Init").unwrap(),
ssid: None,
password: None,
mqtt_url: None,
base_topic: None,
timezone: heapless::String::from_str("Europe/Berlin").unwrap(),
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(default)]
pub struct NightLampConfig {
pub enabled: bool,
pub night_lamp_hour_start: u8,
pub night_lamp_hour_end: u8,
pub night_lamp_only_when_dark: bool,
pub low_soc_cutoff: u8,
pub low_soc_restore: u8,
}
impl Default for NightLampConfig {
fn default() -> Self {
Self {
enabled: true,
night_lamp_hour_start: 19,
night_lamp_hour_end: 2,
night_lamp_only_when_dark: true,
low_soc_cutoff: 30,
low_soc_restore: 50,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(default)]
pub struct TankConfig {
pub tank_sensor_enabled: bool,
pub tank_allow_pumping_if_sensor_error: bool,
pub tank_useable_ml: u32,
pub tank_warn_percent: u8,
pub tank_empty_percent: u8,
pub tank_full_percent: u8,
}
impl Default for TankConfig {
fn default() -> Self {
Self {
tank_sensor_enabled: false,
tank_allow_pumping_if_sensor_error: true,
tank_useable_ml: 50000,
tank_warn_percent: 40,
tank_empty_percent: 5,
tank_full_percent: 95,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
#[serde(default)]
pub struct PlantControllerConfig {
pub network: NetworkConfig,
pub tank: TankConfig,
pub night_lamp: NightLampConfig,
pub plants: [PlantConfig; PLANT_COUNT],
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(default)]
pub struct PlantConfig {
pub mode: Mode,
pub target_moisture: u8,
pub pump_time_s: u16,
pub pump_cooldown_min: u16,
pub pump_hour_start: u8,
pub pump_hour_end: u8,
pub sensor_b: bool,
pub max_consecutive_pump_count: u8,
}
impl Default for PlantConfig {
fn default() -> Self {
Self {
mode: Mode::OFF,
target_moisture: 40,
pump_time_s: 30,
pump_cooldown_min: 60,
pump_hour_start: 9,
pump_hour_end: 20,
sensor_b: false,
max_consecutive_pump_count: 10,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub enum Mode {
OFF,
TargetMoisture,
TimerOnly,
TimerAndDeadzone,
}