From f0f0e9f27ec20c482bfe4f6351f4d5f12b13a1f0 Mon Sep 17 00:00:00 2001 From: Empire Date: Mon, 4 Dec 2023 00:41:29 +0100 Subject: [PATCH] adjustments --- rust/src/main.rs | 17 ++++++++++++----- rust/src/plant_hal.rs | 15 +++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/rust/src/main.rs b/rust/src/main.rs index ef40660..fee2786 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -1,3 +1,5 @@ +use std::{fs::File, io::Write}; + use chrono::{Datelike, Timelike, NaiveDateTime}; use chrono_tz::Europe::Berlin; @@ -50,6 +52,9 @@ fn main() -> Result<()>{ println!("cur is {}", cur); + + + //continous/interrupt? //check if boot button is pressed, if longer than 5s delete config and reboot into config mode @@ -57,12 +62,14 @@ fn main() -> Result<()>{ let config = board.get_config(); match config { Ok(conf) => { - + + }, + Err(err) => { + }, - Err(err) => todo!(), } - let proceed = config.unwrap(); +// let proceed = config.unwrap(); //check if we have a config file // if not found or parsing error -> error very fast blink general fault @@ -72,9 +79,9 @@ fn main() -> Result<()>{ //blink general fault error_no_config_after_upgrade //once config is set store it and reboot - if proceed.tank_sensor_enabled() { + //if proceed.tank_sensor_enabled() { - } + //} //is tank sensor enabled in config? //measure tank level (without wifi due to interference) //TODO this should be a result// detect invalid measurement value diff --git a/rust/src/plant_hal.rs b/rust/src/plant_hal.rs index 7fd684d..017195e 100644 --- a/rust/src/plant_hal.rs +++ b/rust/src/plant_hal.rs @@ -1,12 +1,14 @@ -mod config; +//mod config; use embedded_svc::wifi::{Configuration, ClientConfiguration, AuthMethod}; use esp_idf_svc::eventloop::EspSystemEventLoop; use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::wifi::EspWifi; +use std::fs::File; +use std::io::Read; use std::sync::Mutex; -use anyhow::{Context, Result, bail}; +use anyhow::{Context, Result, bail, Ok}; use anyhow::anyhow; use chrono::{Utc, NaiveDateTime, DateTime}; @@ -26,6 +28,8 @@ use shift_register_driver::sipo::ShiftRegister40; use esp_idf_hal::gpio::{PinDriver, Gpio39, Gpio4, AnyInputPin}; use esp_idf_hal::prelude::Peripherals; +use crate::config; + pub const PLANT_COUNT:usize = 8; const PINS_PER_PLANT:usize = 5; const PLANT_PUMP_OFFSET:usize = 0; @@ -97,7 +101,7 @@ pub trait PlantCtrlBoardInteraction{ //keep state during deepsleep fn fault(&self,plant:usize, enable:bool); - fn get_config(&mut self) -> Result; + fn get_config(&mut self) -> Result; } pub trait CreatePlantHal<'a> { @@ -442,7 +446,10 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> { } fn get_config(&mut self) -> Result { - todo!() + let config_file = File::open("config.cfg")?; + //serde_json::from_str(&data); + bail!("Not implemented"); + }