remove: comment out unused plant visibility logic, update moisture sensor processing, and enhance plant ID handling in TWAI communication
This commit is contained in:
@@ -23,6 +23,7 @@ use esp_hal::gpio::{Flex, Input, InputConfig, Level, Output, OutputConfig, Pull}
|
||||
use esp_hal::i2c::master::I2c;
|
||||
use esp_hal::twai::{EspTwaiError, EspTwaiFrame, StandardId, Twai, TwaiConfiguration, TwaiMode};
|
||||
use esp_hal::{twai, Async, Blocking};
|
||||
use esp_println::println;
|
||||
use ina219::address::{Address, Pin};
|
||||
use ina219::calibration::UnCalibrated;
|
||||
use ina219::configuration::{Configuration, OperatingMode, Resolution};
|
||||
@@ -385,9 +386,10 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
for plant in 0..PLANT_COUNT {
|
||||
for sensor in [Sensor::A, Sensor::B] {
|
||||
let target =
|
||||
StandardId::new(plant_id(IDENTIFY_CMD_OFFSET, sensor.into(), plant as u16))
|
||||
StandardId::new(plant_id(IDENTIFY_CMD_OFFSET, sensor.into(), (plant +1) as u16))
|
||||
.context(">> Could not create address for sensor! (plant: {}) <<")?;
|
||||
let can_buffer = [0_u8; 0];
|
||||
info!("Sending test message to plant {} sensor {sensor:?} with id {}", plant +1, target.as_raw());
|
||||
if let Some(frame) = EspTwaiFrame::new(target, &can_buffer) {
|
||||
// Try a few times; we intentionally ignore rx here and rely on stub logic
|
||||
let resu = twai
|
||||
@@ -396,11 +398,10 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
.await;
|
||||
match resu {
|
||||
Ok(_) => {
|
||||
info!("Sent test message to plant {plant} sensor {sensor:?}");
|
||||
}
|
||||
Err(err) => {
|
||||
info!(
|
||||
"Error sending test message to plant {plant} sensor {sensor:?}: {err:?}"
|
||||
"Error sending test message to plant {} sensor {sensor:?}: {err:?}", plant +1
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -471,7 +472,7 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
LOG_ACCESS
|
||||
.lock()
|
||||
.await
|
||||
.log(LogMessage::TestSensor, a, b, &plant.to_string(), "")
|
||||
.log(LogMessage::TestSensor, a, b, &(plant+1).to_string(), "")
|
||||
.await;
|
||||
}
|
||||
Timer::after_millis(10).await;
|
||||
@@ -522,16 +523,19 @@ async fn wait_for_can_measurements(
|
||||
let plant = msg.1 as usize;
|
||||
let sensor = msg.2;
|
||||
let data = can_frame.data();
|
||||
if data.len() == 2 {
|
||||
let frequency = u16::from_be_bytes([data[0], data[1]]);
|
||||
info!("Received moisture data: {:?}", data);
|
||||
if let Ok(bytes) = data.try_into() {
|
||||
let frequency = u32::from_be_bytes(bytes);
|
||||
match sensor {
|
||||
SensorSlot::A => {
|
||||
moistures.sensor_a_hz[plant] = Some(frequency as f32);
|
||||
moistures.sensor_a_hz[plant-1] = Some(frequency as f32);
|
||||
}
|
||||
SensorSlot::B => {
|
||||
moistures.sensor_b_hz[plant] = Some(frequency as f32);
|
||||
moistures.sensor_b_hz[plant-1] = Some(frequency as f32);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error!("Received moisture data with invalid length: {} (expected 4)", data.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user