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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,47 +227,47 @@ export class PlantView {
|
||||
let showTarget = plantConfig.mode === "TargetMoisture"
|
||||
let showMin = plantConfig.mode === "MinMoisture"
|
||||
|
||||
if(this.showDisabled || plantConfig.sensor_a || plantConfig.sensor_b) {
|
||||
console.log("Showing plant " + this.plantId);
|
||||
this.plantDiv.style.display = "block";
|
||||
} else {
|
||||
console.log("Hiding plant " + this.plantId);
|
||||
this.plantDiv.style.display = "none";
|
||||
}
|
||||
// if(this.showDisabled || plantConfig.sensor_a || plantConfig.sensor_b) {
|
||||
// console.log("Showing plant " + this.plantId);
|
||||
// this.plantDiv.style.display = "block";
|
||||
// } else {
|
||||
// console.log("Hiding plant " + this.plantId);
|
||||
// this.plantDiv.style.display = "none";
|
||||
// }
|
||||
|
||||
console.log("updateVisibility showsensor: " + showSensor + " pump " + showPump + " target " +showTarget + " min " + showMin)
|
||||
|
||||
for (const element of Array.from(sensorOnly)) {
|
||||
if (showSensor) {
|
||||
element.classList.remove("plantHidden_" + this.plantId)
|
||||
} else {
|
||||
element.classList.add("plantHidden_" + this.plantId)
|
||||
}
|
||||
}
|
||||
|
||||
for (const element of Array.from(pumpOnly)) {
|
||||
if (showPump) {
|
||||
element.classList.remove("plantHidden_" + this.plantId)
|
||||
} else {
|
||||
element.classList.add("plantHidden_" + this.plantId)
|
||||
}
|
||||
}
|
||||
|
||||
for (const element of Array.from(targetOnly)) {
|
||||
if (showTarget) {
|
||||
element.classList.remove("plantHidden_" + this.plantId)
|
||||
} else {
|
||||
element.classList.add("plantHidden_" + this.plantId)
|
||||
}
|
||||
}
|
||||
|
||||
for (const element of Array.from(minOnly)) {
|
||||
if (showMin) {
|
||||
element.classList.remove("plantHidden_" + this.plantId)
|
||||
} else {
|
||||
element.classList.add("plantHidden_" + this.plantId)
|
||||
}
|
||||
}
|
||||
// for (const element of Array.from(sensorOnly)) {
|
||||
// if (showSensor) {
|
||||
// element.classList.remove("plantHidden_" + this.plantId)
|
||||
// } else {
|
||||
// element.classList.add("plantHidden_" + this.plantId)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (const element of Array.from(pumpOnly)) {
|
||||
// if (showPump) {
|
||||
// element.classList.remove("plantHidden_" + this.plantId)
|
||||
// } else {
|
||||
// element.classList.add("plantHidden_" + this.plantId)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (const element of Array.from(targetOnly)) {
|
||||
// if (showTarget) {
|
||||
// element.classList.remove("plantHidden_" + this.plantId)
|
||||
// } else {
|
||||
// element.classList.add("plantHidden_" + this.plantId)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (const element of Array.from(minOnly)) {
|
||||
// if (showMin) {
|
||||
// element.classList.remove("plantHidden_" + this.plantId)
|
||||
// } else {
|
||||
// element.classList.add("plantHidden_" + this.plantId)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
setTestResult(result: PumpTestResult) {
|
||||
@@ -335,8 +335,9 @@ export class PlantView {
|
||||
}
|
||||
|
||||
setDetectionResult(plantResult: DetectionPlant) {
|
||||
console.log("setDetectionResult plantResult: " + plantResult.sensor_a + " " + plantResult.sensor_b)
|
||||
var changed = false;
|
||||
if (this.sensorAInstalled.checked != plantResult.sensor_b){
|
||||
if (this.sensorAInstalled.checked != plantResult.sensor_a){
|
||||
changed = true;
|
||||
this.sensorAInstalled.checked = plantResult.sensor_a;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user