adjust rust code to new config file, fix bq34z100 flasher

This commit is contained in:
2024-12-16 02:15:03 +01:00
parent c89a617d9d
commit 74f9c17461
4 changed files with 267 additions and 220 deletions

View File

@@ -1,68 +1,77 @@
use std::{array::from_fn, str::FromStr};
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use crate::PLANT_COUNT;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Config {
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 max_consecutive_pump_count: u8,
}
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,
}
}
}
pub tank_allow_pumping_if_sensor_error: bool,
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct NightLampConfig {
pub night_lamp_hour_start: u8,
pub night_lamp_hour_end: u8,
pub night_lamp_only_when_dark: bool,
}
impl Default for NightLampConfig {
fn default() -> Self {
Self {
night_lamp_hour_start: 19,
night_lamp_hour_end: 2,
night_lamp_only_when_dark: true,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
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,
pub night_lamp_hour_start: u8,
pub night_lamp_hour_end: u8,
pub night_lamp_only_when_dark: bool,
pub plants: [Plant; PLANT_COUNT],
}
impl Default for Config {
impl Default for TankConfig {
fn default() -> Self {
Self {
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_sensor_enabled: false,
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: from_fn(|_i| Plant::default()),
max_consecutive_pump_count: 15,
tank_useable_ml: 5000,
tank_empty_percent: 0_u8,
tank_full_percent: 100_u8,
tank_useable_ml: 50000,
tank_warn_percent: 40,
tank_empty_percent: 5,
tank_full_percent: 95,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub enum Mode {
OFF,
TargetMoisture,
TimerOnly,
TimerAndDeadzone,
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, 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)]
pub struct Plant {
pub struct PlantConfig {
pub mode: Mode,
pub target_moisture: u8,
pub pump_time_s: u16,
@@ -70,17 +79,27 @@ pub struct Plant {
pub pump_hour_start: u8,
pub pump_hour_end: u8,
pub sensor_b: bool,
pub max_consecutive_pump_count: u8,
}
impl Default for Plant {
impl Default for PlantConfig {
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,
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,
}