move to central config, make TZ compile time const, confgureable later!
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{fmt, str::FromStr};
|
||||
use std::{array::from_fn, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -6,8 +6,13 @@ use crate::PLANT_COUNT;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct Config {
|
||||
pub mqtt_url: heapless::String<128>,
|
||||
pub base_topic: heapless::String<64>,
|
||||
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 max_consecutive_pump_count: u8,
|
||||
|
||||
pub tank_allow_pumping_if_sensor_error: bool,
|
||||
@@ -27,15 +32,20 @@ pub struct Config {
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
base_topic: heapless::String::from_str("plant/one").unwrap(),
|
||||
mqtt_url: heapless::String::from_str("mqtt://192.168.1.1:1883").unwrap(),
|
||||
ap_ssid: heapless::String::from_str("Plantctrl").unwrap(),
|
||||
ssid: None,
|
||||
password: None,
|
||||
|
||||
base_topic: Some(heapless::String::from_str("plant/one").unwrap()),
|
||||
mqtt_url: Some(heapless::String::from_str("mqtt://192.168.1.1:1883").unwrap()),
|
||||
|
||||
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],
|
||||
plants: from_fn(|_i| Plant::default()),
|
||||
max_consecutive_pump_count: 15,
|
||||
tank_useable_ml: 5000,
|
||||
tank_empty_percent: 0_u8,
|
||||
@@ -43,7 +53,7 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub enum Mode {
|
||||
OFF,
|
||||
TargetMoisture,
|
||||
@@ -51,7 +61,7 @@ pub enum Mode {
|
||||
TimerAndDeadzone,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct Plant {
|
||||
pub mode: Mode,
|
||||
pub target_moisture: u8,
|
||||
@@ -74,15 +84,3 @@ impl Default for Plant {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user