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::i2c::master::I2c;
|
||||||
use esp_hal::twai::{EspTwaiError, EspTwaiFrame, StandardId, Twai, TwaiConfiguration, TwaiMode};
|
use esp_hal::twai::{EspTwaiError, EspTwaiFrame, StandardId, Twai, TwaiConfiguration, TwaiMode};
|
||||||
use esp_hal::{twai, Async, Blocking};
|
use esp_hal::{twai, Async, Blocking};
|
||||||
|
use esp_println::println;
|
||||||
use ina219::address::{Address, Pin};
|
use ina219::address::{Address, Pin};
|
||||||
use ina219::calibration::UnCalibrated;
|
use ina219::calibration::UnCalibrated;
|
||||||
use ina219::configuration::{Configuration, OperatingMode, Resolution};
|
use ina219::configuration::{Configuration, OperatingMode, Resolution};
|
||||||
@@ -385,9 +386,10 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
|||||||
for plant in 0..PLANT_COUNT {
|
for plant in 0..PLANT_COUNT {
|
||||||
for sensor in [Sensor::A, Sensor::B] {
|
for sensor in [Sensor::A, Sensor::B] {
|
||||||
let target =
|
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: {}) <<")?;
|
.context(">> Could not create address for sensor! (plant: {}) <<")?;
|
||||||
let can_buffer = [0_u8; 0];
|
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) {
|
if let Some(frame) = EspTwaiFrame::new(target, &can_buffer) {
|
||||||
// Try a few times; we intentionally ignore rx here and rely on stub logic
|
// Try a few times; we intentionally ignore rx here and rely on stub logic
|
||||||
let resu = twai
|
let resu = twai
|
||||||
@@ -396,11 +398,10 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
|||||||
.await;
|
.await;
|
||||||
match resu {
|
match resu {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Sent test message to plant {plant} sensor {sensor:?}");
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
info!(
|
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
|
LOG_ACCESS
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
.log(LogMessage::TestSensor, a, b, &plant.to_string(), "")
|
.log(LogMessage::TestSensor, a, b, &(plant+1).to_string(), "")
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
Timer::after_millis(10).await;
|
Timer::after_millis(10).await;
|
||||||
@@ -522,16 +523,19 @@ async fn wait_for_can_measurements(
|
|||||||
let plant = msg.1 as usize;
|
let plant = msg.1 as usize;
|
||||||
let sensor = msg.2;
|
let sensor = msg.2;
|
||||||
let data = can_frame.data();
|
let data = can_frame.data();
|
||||||
if data.len() == 2 {
|
info!("Received moisture data: {:?}", data);
|
||||||
let frequency = u16::from_be_bytes([data[0], data[1]]);
|
if let Ok(bytes) = data.try_into() {
|
||||||
|
let frequency = u32::from_be_bytes(bytes);
|
||||||
match sensor {
|
match sensor {
|
||||||
SensorSlot::A => {
|
SensorSlot::A => {
|
||||||
moistures.sensor_a_hz[plant] = Some(frequency as f32);
|
moistures.sensor_a_hz[plant-1] = Some(frequency as f32);
|
||||||
}
|
}
|
||||||
SensorSlot::B => {
|
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 showTarget = plantConfig.mode === "TargetMoisture"
|
||||||
let showMin = plantConfig.mode === "MinMoisture"
|
let showMin = plantConfig.mode === "MinMoisture"
|
||||||
|
|
||||||
if(this.showDisabled || plantConfig.sensor_a || plantConfig.sensor_b) {
|
// if(this.showDisabled || plantConfig.sensor_a || plantConfig.sensor_b) {
|
||||||
console.log("Showing plant " + this.plantId);
|
// console.log("Showing plant " + this.plantId);
|
||||||
this.plantDiv.style.display = "block";
|
// this.plantDiv.style.display = "block";
|
||||||
} else {
|
// } else {
|
||||||
console.log("Hiding plant " + this.plantId);
|
// console.log("Hiding plant " + this.plantId);
|
||||||
this.plantDiv.style.display = "none";
|
// this.plantDiv.style.display = "none";
|
||||||
}
|
// }
|
||||||
|
|
||||||
console.log("updateVisibility showsensor: " + showSensor + " pump " + showPump + " target " +showTarget + " min " + showMin)
|
console.log("updateVisibility showsensor: " + showSensor + " pump " + showPump + " target " +showTarget + " min " + showMin)
|
||||||
|
|
||||||
for (const element of Array.from(sensorOnly)) {
|
// for (const element of Array.from(sensorOnly)) {
|
||||||
if (showSensor) {
|
// if (showSensor) {
|
||||||
element.classList.remove("plantHidden_" + this.plantId)
|
// element.classList.remove("plantHidden_" + this.plantId)
|
||||||
} else {
|
// } else {
|
||||||
element.classList.add("plantHidden_" + this.plantId)
|
// element.classList.add("plantHidden_" + this.plantId)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for (const element of Array.from(pumpOnly)) {
|
// for (const element of Array.from(pumpOnly)) {
|
||||||
if (showPump) {
|
// if (showPump) {
|
||||||
element.classList.remove("plantHidden_" + this.plantId)
|
// element.classList.remove("plantHidden_" + this.plantId)
|
||||||
} else {
|
// } else {
|
||||||
element.classList.add("plantHidden_" + this.plantId)
|
// element.classList.add("plantHidden_" + this.plantId)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for (const element of Array.from(targetOnly)) {
|
// for (const element of Array.from(targetOnly)) {
|
||||||
if (showTarget) {
|
// if (showTarget) {
|
||||||
element.classList.remove("plantHidden_" + this.plantId)
|
// element.classList.remove("plantHidden_" + this.plantId)
|
||||||
} else {
|
// } else {
|
||||||
element.classList.add("plantHidden_" + this.plantId)
|
// element.classList.add("plantHidden_" + this.plantId)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
for (const element of Array.from(minOnly)) {
|
// for (const element of Array.from(minOnly)) {
|
||||||
if (showMin) {
|
// if (showMin) {
|
||||||
element.classList.remove("plantHidden_" + this.plantId)
|
// element.classList.remove("plantHidden_" + this.plantId)
|
||||||
} else {
|
// } else {
|
||||||
element.classList.add("plantHidden_" + this.plantId)
|
// element.classList.add("plantHidden_" + this.plantId)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
setTestResult(result: PumpTestResult) {
|
setTestResult(result: PumpTestResult) {
|
||||||
@@ -335,8 +335,9 @@ export class PlantView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDetectionResult(plantResult: DetectionPlant) {
|
setDetectionResult(plantResult: DetectionPlant) {
|
||||||
|
console.log("setDetectionResult plantResult: " + plantResult.sensor_a + " " + plantResult.sensor_b)
|
||||||
var changed = false;
|
var changed = false;
|
||||||
if (this.sensorAInstalled.checked != plantResult.sensor_b){
|
if (this.sensorAInstalled.checked != plantResult.sensor_a){
|
||||||
changed = true;
|
changed = true;
|
||||||
this.sensorAInstalled.checked = plantResult.sensor_a;
|
this.sensorAInstalled.checked = plantResult.sensor_a;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user