tanksensor and rtc sync

This commit is contained in:
2025-09-23 22:59:08 +02:00
parent d010c5d12a
commit 5b009f50e5
10 changed files with 116 additions and 102 deletions

View File

@@ -8,13 +8,15 @@ 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::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;
use crate::hal::v4_sensor::{SensorImpl, SensorInteraction};
use crate::FatError::{FatError, FatResult};
use esp_hal::gpio::{Flex, Input, InputConfig, Level, Output, OutputConfig};
use esp_hal::gpio::{Flex, Input, InputConfig, Level, Output, OutputConfig, Pull};
use esp_hal::i2c::master::I2c;
use esp_hal::pcnt::Pcnt;
use esp_hal::twai::{EspTwaiFrame, StandardId, TwaiMode};
use esp_println::println;
use ina219::address::{Address, Pin};
@@ -150,20 +152,23 @@ pub(crate) async fn create_v4(
let mut general_fault = Output::new(peripherals.gpio23, Level::Low, OutputConfig::default());
general_fault.set_low();
let mut extra1 = Output::new(peripherals.gpio6, Level::Low, OutputConfig::default());
let mut extra2 = Output::new(peripherals.gpio15, Level::Low, OutputConfig::default());
let extra1 = Output::new(peripherals.gpio6, Level::Low, OutputConfig::default());
let extra2 = Output::new(peripherals.gpio15, Level::Low, OutputConfig::default());
let one_wire_pin = Flex::new(peripherals.gpio18);
let tank_power_pin = peripherals.gpio11;
let flow_sensor_pin = peripherals.gpio4;
let tank_power_pin = Output::new(peripherals.gpio11, Level::Low, OutputConfig::default());
let flow_sensor_pin = Input::new(
peripherals.gpio4,
InputConfig::default().with_pull(Pull::Up),
);
let tank_sensor = TankSensor::create(
one_wire_pin,
//peripherals.adc1,
//peripherals.gpio5,
//tank_power_pin,
//flow_sensor_pin,
//peripherals.pcnt1,
peripherals.adc1,
peripherals.gpio5,
tank_power_pin,
flow_sensor_pin,
peripherals.pcnt1,
)?;
let sensor_expander_device = I2cDevice::new(I2C_DRIVER.get().await);
@@ -208,7 +213,7 @@ pub(crate) async fn create_v4(
}
Err(_) => {
log::info!("Can bus mode ");
let mut twai_config = twai::TwaiConfiguration::new(
let twai_config = twai::TwaiConfiguration::new(
peripherals.twai,
peripherals.gpio0,
peripherals.gpio2,
@@ -218,9 +223,10 @@ pub(crate) async fn create_v4(
let mut twai = twai_config.start();
let frame = EspTwaiFrame::new(StandardId::ZERO, &[1, 2, 3]).unwrap();
twai.transmit(&frame).unwrap();
let frame = twai.receive().unwrap();
// let frame = twai.receive().unwrap();
println!("Received a frame: {frame:?}");
//can bus version
SensorImpl::CanBus { twai }
@@ -332,8 +338,7 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
}
fn set_charge_indicator(&mut self, charging: bool) -> Result<(), FatError> {
bail!("not implemented");
// self.charger.set_charge_indicator(charging)
self.charger.set_charge_indicator(charging)
}
async fn deep_sleep(&mut self, duration_in_ms: u64) -> ! {
@@ -402,8 +407,7 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
}
async fn measure_moisture_hz(&mut self, plant: usize, sensor: Sensor) -> Result<f32, FatError> {
bail!("not implemented");
//self.sensor.measure_moisture_hz(plant, sensor)
self.sensor.measure_moisture_hz(plant, sensor).await
}
async fn general_fault(&mut self, enable: bool) {