From 0ca09ed4989a7783d1356b46aef8d5932bc813cb Mon Sep 17 00:00:00 2001 From: Empire Date: Thu, 30 Apr 2026 20:37:07 +0200 Subject: [PATCH] feat: add fertilizer pump test functionality with web integration and HAL support --- Software/MainBoard/rust/src/hal/mod.rs | 1 + Software/MainBoard/rust/src/hal/v4_hal.rs | 9 +++++++++ Software/MainBoard/rust/src/webserver/mod.rs | 5 +++-- Software/MainBoard/rust/src/webserver/post_json.rs | 13 +++++++++++++ .../MainBoard/rust/src_webpack/src/hardware.html | 5 +++++ Software/MainBoard/rust/src_webpack/src/hardware.ts | 6 ++++++ Software/MainBoard/rust/src_webpack/src/main.ts | 6 ++++++ 7 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Software/MainBoard/rust/src/hal/mod.rs b/Software/MainBoard/rust/src/hal/mod.rs index 20d533e..2123160 100644 --- a/Software/MainBoard/rust/src/hal/mod.rs +++ b/Software/MainBoard/rust/src/hal/mod.rs @@ -164,6 +164,7 @@ pub trait BoardInteraction<'a> { async fn get_mptt_voltage(&mut self) -> FatResult; async fn get_mptt_current(&mut self) -> FatResult; async fn can_power(&mut self, state: bool) -> FatResult<()>; + async fn extra2(&mut self, enable: bool) -> FatResult<()>; async fn backup_config(&mut self, config: &PlantControllerConfig) -> FatResult<()>; async fn read_backup(&mut self) -> FatResult; diff --git a/Software/MainBoard/rust/src/hal/v4_hal.rs b/Software/MainBoard/rust/src/hal/v4_hal.rs index b5ad4c1..d9e5362 100644 --- a/Software/MainBoard/rust/src/hal/v4_hal.rs +++ b/Software/MainBoard/rust/src/hal/v4_hal.rs @@ -484,6 +484,15 @@ impl<'a> BoardInteraction<'a> for V4<'a> { Ok(()) } + async fn extra2(&mut self, enable: bool) -> FatResult<()> { + if enable { + self.extra2.set_high(); + } else { + self.extra2.set_low(); + } + Ok(()) + } + async fn backup_config(&mut self, controller_config: &PlantControllerConfig) -> FatResult<()> { let mut buffer: [u8; 4096 - BACKUP_HEADER_MAX_SIZE] = [0; 4096 - BACKUP_HEADER_MAX_SIZE]; let length = postcard::to_slice(controller_config, &mut buffer)?.len(); diff --git a/Software/MainBoard/rust/src/webserver/mod.rs b/Software/MainBoard/rust/src/webserver/mod.rs index 2faa6bb..5a6f382 100644 --- a/Software/MainBoard/rust/src/webserver/mod.rs +++ b/Software/MainBoard/rust/src/webserver/mod.rs @@ -17,8 +17,8 @@ use crate::webserver::get_log::{get_live_log, get_log}; use crate::webserver::get_static::{serve_bundle, serve_favicon, serve_index}; use crate::webserver::ota::ota_operations; use crate::webserver::post_json::{ - board_test, can_power, detect_sensors, night_lamp_test, pump_test, set_config, wifi_scan, - write_time, + board_test, can_power, detect_sensors, fertilizer_pump_test, night_lamp_test, pump_test, + set_config, wifi_scan, write_time, }; use crate::{bail, BOARD_ACCESS}; use alloc::borrow::ToOwned; @@ -116,6 +116,7 @@ impl Handler for HTTPRequestRouter { "/pumptest" => Some(pump_test(conn).await), "/can_power" => Some(can_power(conn).await), "/lamptest" => Some(night_lamp_test(conn).await), + "/fertilizerpumptest" => Some(fertilizer_pump_test(conn).await), "/boardtest" => Some(board_test().await), "/detect_sensors" => Some(detect_sensors(conn).await), "/reboot" => { diff --git a/Software/MainBoard/rust/src/webserver/post_json.rs b/Software/MainBoard/rust/src/webserver/post_json.rs index 31b8493..2c133f7 100644 --- a/Software/MainBoard/rust/src/webserver/post_json.rs +++ b/Software/MainBoard/rust/src/webserver/post_json.rs @@ -102,6 +102,19 @@ where Ok(None) } +pub(crate) async fn fertilizer_pump_test( + _request: &mut Connection<'_, T, N>, +) -> FatResult> +where + T: Read + Write, +{ + let mut board = BOARD_ACCESS.get().await.lock().await; + board.board_hal.extra2(true).await?; + embassy_time::Timer::after_millis(1000).await; + board.board_hal.extra2(false).await?; + Ok(None) +} + pub(crate) async fn write_time( request: &mut Connection<'_, T, N>, ) -> FatResult> diff --git a/Software/MainBoard/rust/src_webpack/src/hardware.html b/Software/MainBoard/rust/src_webpack/src/hardware.html index 25e0e50..1722cdd 100644 --- a/Software/MainBoard/rust/src_webpack/src/hardware.html +++ b/Software/MainBoard/rust/src_webpack/src/hardware.html @@ -22,3 +22,8 @@
Pump corrosion protection (weekly)
+ +
Fertilizer Pump:
+
+ +
diff --git a/Software/MainBoard/rust/src_webpack/src/hardware.ts b/Software/MainBoard/rust/src_webpack/src/hardware.ts index 9123b76..64462a9 100644 --- a/Software/MainBoard/rust/src_webpack/src/hardware.ts +++ b/Software/MainBoard/rust/src_webpack/src/hardware.ts @@ -5,6 +5,7 @@ export class HardwareConfigView { private readonly hardware_board_value: HTMLSelectElement; private readonly hardware_battery_value: HTMLSelectElement; private readonly hardware_pump_corrosion_protection: HTMLInputElement; + private readonly fertilizer_pump_test: HTMLButtonElement; constructor(controller:Controller){ (document.getElementById("hardwareview") as HTMLElement).innerHTML = require('./hardware.html') as string; @@ -33,6 +34,11 @@ export class HardwareConfigView { this.hardware_pump_corrosion_protection = document.getElementById("hardware_pump_corrosion_protection") as HTMLInputElement; this.hardware_pump_corrosion_protection.onchange = controller.configChanged + + this.fertilizer_pump_test = document.getElementById("fertilizer_pump_test") as HTMLButtonElement; + this.fertilizer_pump_test.onclick = () => { + controller.testFertilizerPump(); + } } setConfig(hardware: BoardHardware) { diff --git a/Software/MainBoard/rust/src_webpack/src/main.ts b/Software/MainBoard/rust/src_webpack/src/main.ts index 7103d24..996ca2d 100644 --- a/Software/MainBoard/rust/src_webpack/src/main.ts +++ b/Software/MainBoard/rust/src_webpack/src/main.ts @@ -304,6 +304,12 @@ export class Controller { }) } + testFertilizerPump() { + fetch(PUBLIC_URL + "/fertilizerpumptest", { + method: "POST" + }) + } + testPlant(plantId: number) { let counter = 0 let limit = 30