add pump expander
This commit is contained in:
@@ -3,14 +3,21 @@ 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};
|
||||
use crate::hal::{BoardInteraction, FreePeripherals, Sensor, I2C_DRIVER};
|
||||
use alloc::boxed::Box;
|
||||
use async_trait::async_trait;
|
||||
use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use esp_hal::Blocking;
|
||||
//use embedded_hal_bus::i2c::MutexDevice;
|
||||
use crate::bail;
|
||||
use crate::FatError::FatError;
|
||||
use crate::FatError::{FatError, FatResult};
|
||||
use esp_hal::gpio::{Flex, Level, Output, OutputConfig};
|
||||
use esp_hal::i2c::master::I2c;
|
||||
use ina219::address::{Address, Pin};
|
||||
use ina219::SyncIna219;
|
||||
use measurements::{Current, Voltage};
|
||||
use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface};
|
||||
// pub enum Charger<'a> {
|
||||
// SolarMpptV1 {
|
||||
// mppt_ina: SyncIna219<MutexDevice<'a, I2cDriver<'a>>, UnCalibrated>,
|
||||
@@ -101,7 +108,7 @@ pub struct V4<'a> {
|
||||
awake: Output<'a>,
|
||||
light: Output<'a>,
|
||||
general_fault: Output<'a>,
|
||||
//pump_expander: Pca9535Immediate<MutexDevice<'a, I2cDriver<'a>>>,
|
||||
pump_expander: Pca9535Immediate<I2cDevice<'a, CriticalSectionRawMutex, I2c<'static, Blocking>>>,
|
||||
//pump_ina: Option<SyncIna219<MutexDevice<'a, I2cDriver<'a>>, UnCalibrated>>,
|
||||
//sensor: SensorImpl<'a>,
|
||||
extra1: Output<'a>,
|
||||
@@ -112,7 +119,7 @@ struct InputOutput<'a> {
|
||||
pin: Flex<'a>,
|
||||
}
|
||||
|
||||
pub(crate) fn create_v4(
|
||||
pub(crate) async fn create_v4(
|
||||
peripherals: FreePeripherals<'static>,
|
||||
esp: Esp<'static>,
|
||||
config: PlantControllerConfig,
|
||||
@@ -209,19 +216,18 @@ pub(crate) fn create_v4(
|
||||
let mut light = Output::new(peripherals.gpio10, Level::Low, Default::default());
|
||||
let mut charge_indicator = Output::new(peripherals.gpio3, Level::Low, Default::default());
|
||||
|
||||
// let mut pump_expander = Pca9535Immediate::new(MutexDevice::new(&I2C_DRIVER), 32);
|
||||
// for pin in 0..8 {
|
||||
// let _ = pump_expander.pin_into_output(GPIOBank::Bank0, pin);
|
||||
// let _ = pump_expander.pin_into_output(GPIOBank::Bank1, pin);
|
||||
// let _ = pump_expander.pin_set_low(GPIOBank::Bank0, pin);
|
||||
// let _ = pump_expander.pin_set_low(GPIOBank::Bank1, pin);
|
||||
// }
|
||||
//
|
||||
// let mppt_ina = SyncIna219::new(
|
||||
// MutexDevice::new(&I2C_DRIVER),
|
||||
// Address::from_pins(Pin::Vcc, Pin::Gnd),
|
||||
// );
|
||||
//
|
||||
let pump_device = I2cDevice::new(I2C_DRIVER.get().await);
|
||||
let mut pump_expander = Pca9535Immediate::new(pump_device, 32);
|
||||
for pin in 0..8 {
|
||||
let _ = pump_expander.pin_into_output(GPIOBank::Bank0, pin);
|
||||
let _ = pump_expander.pin_into_output(GPIOBank::Bank1, pin);
|
||||
let _ = pump_expander.pin_set_low(GPIOBank::Bank0, pin);
|
||||
let _ = pump_expander.pin_set_low(GPIOBank::Bank1, pin);
|
||||
}
|
||||
|
||||
let mppt_current = I2cDevice::new(I2C_DRIVER.get().await);
|
||||
let mppt_ina = SyncIna219::new(mppt_current, Address::from_pins(Pin::Vcc, Pin::Gnd));
|
||||
|
||||
// let charger = match mppt_ina {
|
||||
// Ok(mut mppt_ina) => {
|
||||
// mppt_ina.set_configuration(Configuration {
|
||||
@@ -261,7 +267,7 @@ pub(crate) fn create_v4(
|
||||
light,
|
||||
general_fault,
|
||||
//pump_ina,
|
||||
//pump_expander,
|
||||
pump_expander,
|
||||
config,
|
||||
battery_monitor,
|
||||
//charger,
|
||||
@@ -318,16 +324,15 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
// anyhow::Ok(())
|
||||
}
|
||||
|
||||
async fn pump(&mut self, plant: usize, enable: bool) -> Result<(), FatError> {
|
||||
bail!("not implemented");
|
||||
// if enable {
|
||||
// self.pump_expander
|
||||
// .pin_set_high(GPIOBank::Bank0, plant.try_into()?)?;
|
||||
// } else {
|
||||
// self.pump_expander
|
||||
// .pin_set_low(GPIOBank::Bank0, plant.try_into()?)?;
|
||||
// }
|
||||
// anyhow::Ok(())
|
||||
async fn pump(&mut self, plant: usize, enable: bool) -> FatResult<()> {
|
||||
if enable {
|
||||
self.pump_expander
|
||||
.pin_set_high(GPIOBank::Bank0, plant as u8)?;
|
||||
} else {
|
||||
self.pump_expander
|
||||
.pin_set_low(GPIOBank::Bank0, plant as u8)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn pump_current(&mut self, _plant: usize) -> Result<Current, FatError> {
|
||||
@@ -349,16 +354,15 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
// }
|
||||
}
|
||||
|
||||
async fn fault(&mut self, plant: usize, enable: bool) -> Result<(), FatError> {
|
||||
bail!("not implemented");
|
||||
// if enable {
|
||||
// self.pump_expander
|
||||
// .pin_set_high(GPIOBank::Bank1, plant.try_into()?)?
|
||||
// } else {
|
||||
// self.pump_expander
|
||||
// .pin_set_low(GPIOBank::Bank1, plant.try_into()?)?
|
||||
// }
|
||||
// anyhow::Ok(())
|
||||
async fn fault(&mut self, plant: usize, enable: bool) -> FatResult<()> {
|
||||
if enable {
|
||||
self.pump_expander
|
||||
.pin_set_high(GPIOBank::Bank1, plant as u8)?;
|
||||
} else {
|
||||
self.pump_expander
|
||||
.pin_set_low(GPIOBank::Bank1, plant as u8)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn measure_moisture_hz(&mut self, plant: usize, sensor: Sensor) -> Result<f32, FatError> {
|
||||
|
Reference in New Issue
Block a user