we should be feature compatible with main version now!

This commit is contained in:
2025-09-30 22:37:45 +02:00
parent cfe23c8a09
commit cf58486cf5
5 changed files with 65 additions and 93 deletions

View File

@@ -19,6 +19,10 @@ use embassy_sync::mutex::Mutex;
use embassy_time::Timer;
use embedded_hal::digital::OutputPin as _;
use esp_hal::gpio::{Flex, Input, InputConfig, Level, Output, OutputConfig, Pull};
use esp_hal::pcnt::channel::CtrlMode::Keep;
use esp_hal::pcnt::channel::EdgeMode;
use esp_hal::pcnt::channel::EdgeMode::{Hold, Increment};
use esp_hal::pcnt::unit::Unit;
use measurements::{Current, Voltage};
const PUMP8_BIT: usize = 0;
@@ -81,6 +85,7 @@ pub struct V3<'a> {
light: Output<'a>,
main_pump: Output<'a>,
general_fault: Output<'a>,
pub signal_counter: Unit<'static, 0>,
}
pub(crate) fn create_v3(
@@ -139,6 +144,18 @@ pub(crate) fn create_v3(
Output::new(peripherals.gpio21, Level::Low, OutputConfig::default());
shift_register_enable_invert.set_low();
let signal_counter = peripherals.pcnt0;
signal_counter.set_low_limit(Some(0))?;
signal_counter.set_high_limit(Some(i16::MAX))?;
let ch0 = &signal_counter.channel0;
let edge_pin = Input::new(peripherals.gpio22, InputConfig::default());
ch0.set_edge_signal(edge_pin.peripheral_input());
ch0.set_input_mode(Hold, Increment);
ch0.set_ctrl_mode(Keep, Keep);
signal_counter.listen();
Ok(Box::new(V3 {
config,
battery_monitor,
@@ -151,6 +168,7 @@ pub(crate) fn create_v3(
light,
main_pump,
general_fault,
signal_counter,
}))
}
@@ -262,8 +280,8 @@ impl<'a> BoardInteraction<'a> for V3<'a> {
async fn measure_moisture_hz(&mut self, plant: usize, sensor: Sensor) -> Result<f32, FatError> {
let mut results = [0_f32; REPEAT_MOIST_MEASURE];
for repeat in 0..REPEAT_MOIST_MEASURE {
//self.signal_counter.counter_pause()?;
//self.signal_counter.counter_clear()?;
self.signal_counter.pause();
self.signal_counter.clear();
//Disable all
{
let shift_register = self.shift_register.lock().await;
@@ -331,16 +349,16 @@ impl<'a> BoardInteraction<'a> for V3<'a> {
//give some time to stabilize
Timer::after_millis(10).await;
//self.signal_counter.counter_resume()?;
self.signal_counter.resume();
Timer::after_millis(measurement).await;
//self.signal_counter.counter_pause()?;
self.signal_counter.pause();
{
let shift_register = self.shift_register.lock().await;
shift_register.decompose()[MS_4].set_high()?;
shift_register.decompose()[SENSOR_ON].set_low()?;
}
Timer::after_millis(10).await;
let unscaled = 1337; //self.signal_counter.get_counter_value()? as i32;
let unscaled = self.signal_counter.value();
let hz = unscaled as f32 * factor;
LOG_ACCESS
.lock()