From de54afce5259257b0957559c450116411023b3c4 Mon Sep 17 00:00:00 2001 From: Empire Date: Thu, 19 Jun 2025 22:57:54 +0200 Subject: [PATCH] webfix for sensora enable, ina start --- rust/Cargo.toml | 1 + rust/src/hal/v4_hal.rs | 14 ++++++++++++++ rust/src_webpack/src/plant.html | 4 ++++ rust/src_webpack/src/plant.ts | 10 ++++++++-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 233be1e..0fc0d3d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -85,6 +85,7 @@ strum_macros = "0.27.0" esp-ota = { version = "0.2.2", features = ["log"] } unit-enum = "1.4.1" pca9535 = { version = "2.0.0", features = ["std"] } +ina219 = { version = "0.2.0", features = ["std"] } [patch.crates-io] diff --git a/rust/src/hal/v4_hal.rs b/rust/src/hal/v4_hal.rs index 11b81da..f4e1cc6 100644 --- a/rust/src/hal/v4_hal.rs +++ b/rust/src/hal/v4_hal.rs @@ -26,6 +26,9 @@ use esp_idf_sys::{gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError}; use one_wire_bus::OneWire; use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface}; use std::result::Result::Ok as OkStd; +use ina219::address::Address; +use ina219::calibration::{Calibration, UnCalibrated}; +use ina219::SyncIna219; const MS0: u8 = 1_u8; const MS1: u8 = 0_u8; @@ -35,6 +38,7 @@ const MS4: u8 = 2_u8; const SENSOR_ON: u8 = 5_u8; pub struct V4<'a> { + mppt_ina: SyncIna219>, UnCalibrated>, esp: ESP<'a>, battery_monitor: Box, config: PlantControllerConfig, @@ -169,7 +173,17 @@ pub(crate) fn create_v4( let _ = sensor_expander.pin_set_low(GPIOBank::Bank1, pin); } + let mut mppt_ina = SyncIna219::new(MutexDevice::new(&I2C_DRIVER), Address::from_byte(68)?)?; + esp.delay.delay_ms(mppt_ina.configuration()?.conversion_time().unwrap().as_millis() as u32); + println!("Bus Voltage: {}", mppt_ina.bus_voltage()?); + println!("Shunt Voltage: {}", mppt_ina.shunt_voltage()?); + let volt = (mppt_ina.shunt_voltage()?.shunt_voltage_mv()) as f32 / 1000_f32; + let current = volt /0.05; + println!("Shunt Current: {}", current); + + let v = V4 { + mppt_ina, esp, awake, tank_channel, diff --git a/rust/src_webpack/src/plant.html b/rust/src_webpack/src/plant.html index b653193..94d9f24 100644 --- a/rust/src_webpack/src/plant.html +++ b/rust/src_webpack/src/plant.html @@ -71,6 +71,10 @@ +
+
Sensor A installed:
+ +
Sensor B installed:
diff --git a/rust/src_webpack/src/plant.ts b/rust/src_webpack/src/plant.ts index d80a120..cf58210 100644 --- a/rust/src_webpack/src/plant.ts +++ b/rust/src_webpack/src/plant.ts @@ -55,6 +55,7 @@ export class PlantView { private readonly pumpCooldown: HTMLInputElement; private readonly pumpHourStart: HTMLSelectElement; private readonly pumpHourEnd: HTMLSelectElement; + private readonly sensorAInstalled: HTMLInputElement; private readonly sensorBInstalled: HTMLInputElement; private readonly mode: HTMLSelectElement; private readonly moistureA: HTMLElement; @@ -128,6 +129,11 @@ export class PlantView { this.pumpHourEnd.appendChild(option); } + this.sensorAInstalled = document.getElementById("plant_"+plantId+"_sensor_a") as HTMLInputElement; + this.sensorAInstalled.onchange = function(){ + controller.configChanged() + } + this.sensorBInstalled = document.getElementById("plant_"+plantId+"_sensor_b") as HTMLInputElement; this.sensorBInstalled.onchange = function(){ controller.configChanged() @@ -165,6 +171,7 @@ export class PlantView { this.pumpHourStart.value = plantConfig.pump_hour_start.toString(); this.pumpHourEnd.value = plantConfig.pump_hour_end.toString(); this.sensorBInstalled.checked = plantConfig.sensor_b; + this.sensorAInstalled.checked = plantConfig.sensor_a; this.maxConsecutivePumpCount.value = plantConfig.max_consecutive_pump_count.toString(); // Set new fields @@ -176,8 +183,6 @@ export class PlantView { getConfig(): PlantConfig { return { - // hardcoded for now - sensor_a: true, mode: this.mode.value, target_moisture: this.targetMoisture.valueAsNumber, pump_time_s: this.pumpTimeS.valueAsNumber, @@ -185,6 +190,7 @@ export class PlantView { pump_hour_start: +this.pumpHourStart.value, pump_hour_end: +this.pumpHourEnd.value, sensor_b: this.sensorBInstalled.checked, + sensor_a: this.sensorAInstalled.checked, max_consecutive_pump_count: this.maxConsecutivePumpCount.valueAsNumber, moisture_sensor_min_frequency: this.moistureSensorMinFrequency.valueAsNumber || null, moisture_sensor_max_frequency: this.moistureSensorMaxFrequency.valueAsNumber || null