2024-02-15 23:00:05 +01:00
|
|
|
use std::{fmt, str::FromStr};
|
2023-11-29 18:28:09 +01:00
|
|
|
|
2024-01-07 14:33:02 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
2023-11-29 18:28:09 +01:00
|
|
|
|
|
|
|
use crate::PLANT_COUNT;
|
|
|
|
|
2024-01-07 14:33:02 +01:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
2023-12-12 03:46:53 +01:00
|
|
|
pub struct Config {
|
2024-01-07 14:33:02 +01:00
|
|
|
pub mqtt_url: heapless::String<128>,
|
|
|
|
pub base_topic: heapless::String<64>,
|
|
|
|
pub max_consecutive_pump_count: u8,
|
|
|
|
|
|
|
|
pub tank_allow_pumping_if_sensor_error: bool,
|
|
|
|
pub tank_sensor_enabled: bool,
|
|
|
|
pub tank_useable_ml: u32,
|
|
|
|
pub tank_warn_percent: u8,
|
2024-02-15 23:00:05 +01:00
|
|
|
pub tank_empty_percent: u8,
|
|
|
|
pub tank_full_percent: u8,
|
2023-11-29 18:28:09 +01:00
|
|
|
|
2024-01-07 14:33:02 +01:00
|
|
|
pub night_lamp_hour_start: u8,
|
|
|
|
pub night_lamp_hour_end: u8,
|
|
|
|
pub night_lamp_only_when_dark: bool,
|
2023-12-23 01:59:00 +01:00
|
|
|
|
2024-01-07 14:33:02 +01:00
|
|
|
pub plants: [Plant; PLANT_COUNT],
|
2023-12-23 01:59:00 +01:00
|
|
|
}
|
|
|
|
|
2023-12-27 17:33:11 +01:00
|
|
|
impl Default for Config {
|
2024-01-07 14:33:02 +01:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2024-02-15 23:00:05 +01:00
|
|
|
base_topic: heapless::String::from_str("plant/one").unwrap(),
|
|
|
|
mqtt_url: heapless::String::from_str("mqtt://192.168.1.1:1883").unwrap(),
|
2024-01-07 14:33:02 +01:00
|
|
|
tank_allow_pumping_if_sensor_error: true,
|
|
|
|
tank_sensor_enabled: true,
|
|
|
|
tank_warn_percent: 50,
|
|
|
|
night_lamp_hour_start: 21,
|
|
|
|
night_lamp_hour_end: 2,
|
|
|
|
night_lamp_only_when_dark: true,
|
|
|
|
plants: [Plant::default(); PLANT_COUNT],
|
|
|
|
max_consecutive_pump_count: 15,
|
|
|
|
tank_useable_ml: 5000,
|
2024-02-15 23:00:05 +01:00
|
|
|
tank_empty_percent: 0_u8,
|
|
|
|
tank_full_percent: 100_u8,
|
2023-12-27 17:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-07 14:33:02 +01:00
|
|
|
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)]
|
|
|
|
pub enum Mode {
|
|
|
|
OFF,
|
|
|
|
TargetMoisture,
|
|
|
|
TimerOnly,
|
2024-01-09 00:16:13 +01:00
|
|
|
TimerAndDeadzone,
|
2024-01-07 14:33:02 +01:00
|
|
|
}
|
2023-12-27 17:33:11 +01:00
|
|
|
|
2024-01-07 14:33:02 +01:00
|
|
|
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)]
|
|
|
|
pub struct Plant {
|
|
|
|
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,
|
2023-12-12 03:46:53 +01:00
|
|
|
}
|
2023-12-27 17:33:11 +01:00
|
|
|
impl Default for Plant {
|
2024-01-07 14:33:02 +01:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
target_moisture: 40,
|
|
|
|
pump_time_s: 60,
|
|
|
|
pump_cooldown_min: 60,
|
|
|
|
pump_hour_start: 8,
|
|
|
|
pump_hour_end: 20,
|
|
|
|
mode: Mode::OFF,
|
|
|
|
}
|
2023-12-27 17:33:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-07 14:33:02 +01:00
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2023-12-12 03:46:53 +01:00
|
|
|
pub struct WifiConfig {
|
|
|
|
pub ssid: heapless::String<32>,
|
|
|
|
pub password: Option<heapless::String<64>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for WifiConfig {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "({}, ****)", self.ssid)
|
|
|
|
}
|
2024-01-07 14:33:02 +01:00
|
|
|
}
|