bring selftest online, bring tz online, fix set_config/get_config race
This commit is contained in:
@@ -3,17 +3,19 @@ use crate::hal::battery::BatteryInteraction;
|
||||
use crate::hal::esp::Esp;
|
||||
use crate::hal::rtc::RTCModuleInteraction;
|
||||
use crate::hal::water::TankSensor;
|
||||
use crate::hal::{BoardInteraction, FreePeripherals, Sensor, I2C_DRIVER};
|
||||
use crate::hal::{BoardInteraction, FreePeripherals, Sensor, I2C_DRIVER, PLANT_COUNT};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::ToString;
|
||||
use async_trait::async_trait;
|
||||
use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_time::Timer;
|
||||
use esp_hal::analog::adc::{Adc, AdcConfig, Attenuation};
|
||||
use esp_hal::{twai, Blocking};
|
||||
//use embedded_hal_bus::i2c::MutexDevice;
|
||||
use crate::bail;
|
||||
use crate::hal::v4_sensor::{SensorImpl, SensorInteraction};
|
||||
use crate::FatError::{FatError, FatResult};
|
||||
use crate::fat_error::{FatError, FatResult};
|
||||
use esp_hal::gpio::{Flex, Input, InputConfig, Level, Output, OutputConfig, Pull};
|
||||
use esp_hal::i2c::master::I2c;
|
||||
use esp_hal::pcnt::Pcnt;
|
||||
@@ -26,6 +28,7 @@ use ina219::SyncIna219;
|
||||
use measurements::Resistance;
|
||||
use measurements::{Current, Voltage};
|
||||
use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface};
|
||||
use crate::log::{LogMessage, LOG_ACCESS};
|
||||
|
||||
const MPPT_CURRENT_SHUNT_OHMS: f64 = 0.05_f64;
|
||||
const TWAI_BAUDRATE: twai::BaudRate = twai::BaudRate::B125K;
|
||||
@@ -348,16 +351,14 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
}
|
||||
|
||||
fn is_day(&self) -> bool {
|
||||
false
|
||||
//self.charger.is_day()
|
||||
self.charger.is_day()
|
||||
}
|
||||
|
||||
fn light(&mut self, enable: bool) -> Result<(), FatError> {
|
||||
bail!("not implemented");
|
||||
async fn light(&mut self, enable: bool) -> Result<(), FatError> {
|
||||
// unsafe { gpio_hold_dis(self.light.pin()) };
|
||||
// self.light.set_state(enable.into())?;
|
||||
self.light.set_level(enable.into());
|
||||
// unsafe { gpio_hold_en(self.light.pin()) };
|
||||
// anyhow::Ok(())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn pump(&mut self, plant: usize, enable: bool) -> FatResult<()> {
|
||||
@@ -417,40 +418,40 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
}
|
||||
|
||||
async fn test(&mut self) -> Result<(), FatError> {
|
||||
// self.general_fault(true);
|
||||
// self.esp.delay.delay_ms(100);
|
||||
// self.general_fault(false);
|
||||
// self.esp.delay.delay_ms(500);
|
||||
// self.light(true)?;
|
||||
// self.esp.delay.delay_ms(500);
|
||||
// self.light(false)?;
|
||||
// self.esp.delay.delay_ms(500);
|
||||
// for i in 0..PLANT_COUNT {
|
||||
// self.fault(i, true)?;
|
||||
// self.esp.delay.delay_ms(500);
|
||||
// self.fault(i, false)?;
|
||||
// self.esp.delay.delay_ms(500);
|
||||
// }
|
||||
// for i in 0..PLANT_COUNT {
|
||||
// self.pump(i, true)?;
|
||||
// self.esp.delay.delay_ms(100);
|
||||
// self.pump(i, false)?;
|
||||
// self.esp.delay.delay_ms(100);
|
||||
// }
|
||||
// for plant in 0..PLANT_COUNT {
|
||||
// let a = self.measure_moisture_hz(plant, Sensor::A);
|
||||
// let b = self.measure_moisture_hz(plant, Sensor::B);
|
||||
// let aa = match a {
|
||||
// OkStd(a) => a as u32,
|
||||
// Err(_) => u32::MAX,
|
||||
// };
|
||||
// let bb = match b {
|
||||
// OkStd(b) => b as u32,
|
||||
// Err(_) => u32::MAX,
|
||||
// };
|
||||
// log(LogMessage::TestSensor, aa, bb, &plant.to_string(), "");
|
||||
// }
|
||||
// self.esp.delay.delay_ms(10);
|
||||
self.general_fault(true).await;
|
||||
Timer::after_millis(100).await;
|
||||
self.general_fault(false).await;
|
||||
Timer::after_millis(500).await;
|
||||
self.light(true).await?;
|
||||
Timer::after_millis(500).await;
|
||||
self.light(false).await?;
|
||||
Timer::after_millis(500).await;
|
||||
for i in 0..PLANT_COUNT {
|
||||
self.fault(i, true).await?;
|
||||
Timer::after_millis(500).await;
|
||||
self.fault(i, false).await?;
|
||||
Timer::after_millis(500).await;
|
||||
}
|
||||
for i in 0..PLANT_COUNT {
|
||||
self.pump(i, true).await?;
|
||||
Timer::after_millis(100).await;
|
||||
self.pump(i, false).await?;
|
||||
Timer::after_millis(100).await;
|
||||
}
|
||||
for plant in 0..PLANT_COUNT {
|
||||
let a = self.measure_moisture_hz(plant, Sensor::A).await;
|
||||
let b = self.measure_moisture_hz(plant, Sensor::B).await;
|
||||
let aa = match a {
|
||||
Ok(a) => a as u32,
|
||||
Err(_) => u32::MAX,
|
||||
};
|
||||
let bb = match b {
|
||||
Ok(b) => b as u32,
|
||||
Err(_) => u32::MAX,
|
||||
};
|
||||
LOG_ACCESS.lock().await.log(LogMessage::TestSensor, aa, bb, &plant.to_string(), "").await;
|
||||
}
|
||||
Timer::after_millis(10).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user