remove: eliminate MoistureSensorState::Disabled, simplify moisture sensor processing, refactor pump logic, and clean up redundant/unnecessary code
This commit is contained in:
@@ -323,13 +323,12 @@ impl From<sntpc::Error> for FatError {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl From<BmsProtocolError> for FatError{
|
||||
impl From<BmsProtocolError> for FatError {
|
||||
fn from(value: BmsProtocolError) -> Self {
|
||||
match value {
|
||||
BmsProtocolError::I2cCommunicationError => {
|
||||
FatError::String{error: "I2C communication error".to_string()}
|
||||
}
|
||||
BmsProtocolError::I2cCommunicationError => FatError::String {
|
||||
error: "I2C communication error".to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
use crate::hal::Box;
|
||||
use crate::fat_error::{FatError, FatResult};
|
||||
use crate::hal::Box;
|
||||
use async_trait::async_trait;
|
||||
use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use esp_hal::i2c::master::I2c;
|
||||
use esp_hal::Blocking;
|
||||
use lib_bms_protocol::{BatteryState as bstate, BmsReadable, Config, FirmwareVersion, ProtocolVersion};
|
||||
use lib_bms_protocol::{
|
||||
BatteryState as bstate, BmsReadable, Config, FirmwareVersion, ProtocolVersion,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
#[async_trait(?Send)]
|
||||
@@ -59,18 +61,17 @@ impl BatteryInteraction for NoBatteryMonitor {
|
||||
pub struct WchI2cSlave {}
|
||||
|
||||
pub struct WCHI2CSlave<'a> {
|
||||
pub(crate) i2c: I2cDevice<'a, CriticalSectionRawMutex, I2c<'a, Blocking>>
|
||||
pub(crate) i2c: I2cDevice<'a, CriticalSectionRawMutex, I2c<'a, Blocking>>,
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl BatteryInteraction for WCHI2CSlave<'_> {
|
||||
|
||||
|
||||
async fn get_state(&mut self) -> FatResult<BatteryState> {
|
||||
let state = bstate::read_from_i2c(&mut self.i2c)?;
|
||||
let config = Config::read_from_i2c(&mut self.i2c)?;
|
||||
|
||||
let state_of_charge = (state.remaining_capacity_mah * 100 / state.lifetime_capacity_mah) as u8;
|
||||
let state_of_charge =
|
||||
(state.remaining_capacity_mah * 100 / state.lifetime_capacity_mah) as u8;
|
||||
let state_of_health = state.lifetime_capacity_mah / config.capacity_mah * 100;
|
||||
|
||||
Ok(BatteryState::Info(BatteryInfo {
|
||||
|
||||
@@ -25,7 +25,6 @@ use embedded_storage::nor_flash::{check_erase, NorFlash, ReadNorFlash};
|
||||
use esp_bootloader_esp_idf::ota::OtaImageState::Valid;
|
||||
use esp_bootloader_esp_idf::ota::{Ota, OtaImageState};
|
||||
use esp_bootloader_esp_idf::partitions::{AppPartitionSubType, FlashRegion};
|
||||
use esp_hal::Blocking;
|
||||
use esp_hal::gpio::{Input, RtcPinWithResistors};
|
||||
use esp_hal::rng::Rng;
|
||||
use esp_hal::rtc_cntl::{
|
||||
@@ -34,6 +33,7 @@ use esp_hal::rtc_cntl::{
|
||||
};
|
||||
use esp_hal::system::software_reset;
|
||||
use esp_hal::uart::Uart;
|
||||
use esp_hal::Blocking;
|
||||
use esp_println::println;
|
||||
use esp_radio::wifi::{
|
||||
AccessPointConfig, AccessPointInfo, AuthMethod, ClientConfig, ModeConfig, ScanConfig,
|
||||
@@ -155,7 +155,6 @@ macro_rules! mk_static {
|
||||
}
|
||||
|
||||
impl Esp<'_> {
|
||||
|
||||
pub(crate) async fn read_serial_line(&mut self) -> FatResult<Option<alloc::string::String>> {
|
||||
let mut buf = [0u8; 1];
|
||||
let mut line = String::new();
|
||||
@@ -171,7 +170,7 @@ impl Esp<'_> {
|
||||
}
|
||||
line.push(c);
|
||||
}
|
||||
Err(error ) => {
|
||||
Err(error) => {
|
||||
if line.is_empty() {
|
||||
return Ok(None);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use esp_hal::uart::Config as UartConfig;
|
||||
use lib_bms_protocol::BmsReadable;
|
||||
use esp_hal::uart::{Config as UartConfig};
|
||||
pub(crate) mod battery;
|
||||
// mod can_api; // replaced by external canapi crate
|
||||
pub mod esp;
|
||||
@@ -9,7 +9,6 @@ mod shared_flash;
|
||||
mod v4_hal;
|
||||
mod water;
|
||||
|
||||
use lib_bms_protocol::ProtocolVersion;
|
||||
use crate::alloc::string::ToString;
|
||||
use crate::hal::rtc::{DS3231Module, RTCModuleInteraction};
|
||||
use esp_hal::peripherals::Peripherals;
|
||||
@@ -36,6 +35,7 @@ use esp_hal::peripherals::GPIO6;
|
||||
use esp_hal::peripherals::GPIO7;
|
||||
use esp_hal::peripherals::GPIO8;
|
||||
use esp_hal::peripherals::TWAI0;
|
||||
use lib_bms_protocol::ProtocolVersion;
|
||||
|
||||
use crate::{
|
||||
bail,
|
||||
@@ -73,7 +73,7 @@ use esp_hal::gpio::{Input, InputConfig, Pull};
|
||||
use measurements::{Current, Voltage};
|
||||
|
||||
use crate::fat_error::{ContextExt, FatError, FatResult};
|
||||
use crate::hal::battery::{WCHI2CSlave};
|
||||
use crate::hal::battery::WCHI2CSlave;
|
||||
use crate::hal::little_fs2storage_adapter::LittleFs2Filesystem;
|
||||
use crate::hal::water::TankSensor;
|
||||
use crate::log::LOG_ACCESS;
|
||||
@@ -93,8 +93,8 @@ use esp_hal::rtc_cntl::{Rtc, SocResetReason};
|
||||
use esp_hal::system::reset_reason;
|
||||
use esp_hal::time::Rate;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use esp_hal::Blocking;
|
||||
use esp_hal::uart::Uart;
|
||||
use esp_hal::Blocking;
|
||||
use esp_radio::{init, Controller};
|
||||
use esp_storage::FlashStorage;
|
||||
use littlefs2::fs::{Allocation, Filesystem as lfs2Filesystem};
|
||||
@@ -141,7 +141,6 @@ pub struct HAL<'a> {
|
||||
pub struct DetectionRequest {
|
||||
pub sensorsa: [Sensor; PLANT_COUNT],
|
||||
pub sensorsb: [Sensor; PLANT_COUNT],
|
||||
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
@@ -169,9 +168,7 @@ pub trait BoardInteraction<'a> {
|
||||
async fn can_power(&mut self, state: bool) -> FatResult<()>;
|
||||
|
||||
// Return JSON string with autodetected sensors per plant. Default: not supported.
|
||||
async fn detect_sensors(&mut self, request: Detection) -> FatResult<Detection> {
|
||||
bail!("Autodetection is only available on v4 HAL with CAN bus");
|
||||
}
|
||||
async fn detect_sensors(&mut self, request: Detection) -> FatResult<Detection>;
|
||||
|
||||
async fn progress(&mut self, counter: u32) {
|
||||
// Indicate progress is active to suppress default wait_infinity blinking
|
||||
@@ -401,8 +398,8 @@ impl PlantHal {
|
||||
lfs2Filesystem::mount(alloc, lfs2filesystem).expect("Could not mount lfs2 filesystem"),
|
||||
));
|
||||
|
||||
let uart0 = Uart::new(peripherals.UART0, UartConfig::default())
|
||||
.map_err(|_| FatError::String {
|
||||
let uart0 =
|
||||
Uart::new(peripherals.UART0, UartConfig::default()).map_err(|_| FatError::String {
|
||||
error: "Uart creation failed".to_string(),
|
||||
})?;
|
||||
|
||||
@@ -421,7 +418,7 @@ impl PlantHal {
|
||||
current: running,
|
||||
slot0_state: state_0,
|
||||
slot1_state: state_1,
|
||||
uart0
|
||||
uart0,
|
||||
};
|
||||
|
||||
//init,reset rtc memory depending on cause
|
||||
@@ -571,9 +568,14 @@ impl PlantHal {
|
||||
)
|
||||
.await;
|
||||
HAL {
|
||||
board_hal: v4_hal::create_v4(free_pins, esp, PlantControllerConfig::default(),
|
||||
Box::new(NoBatteryMonitor {}), rtc_module)
|
||||
.await?
|
||||
board_hal: v4_hal::create_v4(
|
||||
free_pins,
|
||||
esp,
|
||||
PlantControllerConfig::default(),
|
||||
Box::new(NoBatteryMonitor {}),
|
||||
rtc_module,
|
||||
)
|
||||
.await?,
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -699,4 +701,3 @@ pub struct DetectionSensorResult {
|
||||
sensor_a: bool,
|
||||
sensor_b: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::hal::{
|
||||
};
|
||||
use crate::log::{LogMessage, LOG_ACCESS};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{ToString};
|
||||
use alloc::string::ToString;
|
||||
use async_trait::async_trait;
|
||||
use canapi::id::{classify, plant_id, MessageKind, IDENTIFY_CMD_OFFSET};
|
||||
use canapi::SensorSlot;
|
||||
@@ -133,10 +133,9 @@ pub struct V4<'a> {
|
||||
|
||||
extra1: Output<'a>,
|
||||
extra2: Output<'a>,
|
||||
twai_config: Option<TwaiConfiguration<'static, Blocking>>
|
||||
twai_config: Option<TwaiConfiguration<'static, Blocking>>,
|
||||
}
|
||||
|
||||
|
||||
pub(crate) async fn create_v4(
|
||||
peripherals: FreePeripherals<'static>,
|
||||
esp: Esp<'static>,
|
||||
@@ -263,12 +262,11 @@ pub(crate) async fn create_v4(
|
||||
extra1,
|
||||
extra2,
|
||||
can_power,
|
||||
twai_config
|
||||
twai_config,
|
||||
};
|
||||
Ok(Box::new(v))
|
||||
}
|
||||
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
fn get_tank_sensor(&mut self) -> Result<&mut TankSensor<'a>, FatError> {
|
||||
@@ -395,11 +393,18 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
if !detect {
|
||||
continue;
|
||||
}
|
||||
let target =
|
||||
StandardId::new(plant_id(IDENTIFY_CMD_OFFSET, sensor.into(), (plant +1) as u16))
|
||||
let target = 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());
|
||||
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
|
||||
@@ -407,11 +412,11 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
.with_timeout(Duration::from_millis(3000))
|
||||
.await;
|
||||
match resu {
|
||||
Ok(_) => {
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
info!(
|
||||
"Error sending test message to plant {} sensor {sensor:?}: {err:?}", plant +1
|
||||
"Error sending test message to plant {} sensor {sensor:?}: {err:?}",
|
||||
plant + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -426,20 +431,17 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
.with_timeout(Duration::from_millis(3000))
|
||||
.await;
|
||||
|
||||
|
||||
let config = twai.stop().into_blocking();
|
||||
self.twai_config.replace(config);
|
||||
|
||||
self.can_power.set_low();
|
||||
|
||||
|
||||
let result = moistures.into();
|
||||
|
||||
info!("Autodetection result: {result:?}");
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
||||
async fn general_fault(&mut self, enable: bool) {
|
||||
hold_disable(23);
|
||||
self.general_fault.set_level(enable.into());
|
||||
@@ -482,7 +484,7 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
LOG_ACCESS
|
||||
.lock()
|
||||
.await
|
||||
.log(LogMessage::TestSensor, a, b, &(plant+1).to_string(), "")
|
||||
.log(LogMessage::TestSensor, a, b, &(plant + 1).to_string(), "")
|
||||
.await;
|
||||
}
|
||||
Timer::after_millis(10).await;
|
||||
@@ -511,7 +513,6 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async fn wait_for_can_measurements(
|
||||
as_async: &mut Twai<'_, Async>,
|
||||
moistures: &mut Moistures,
|
||||
@@ -538,10 +539,12 @@ async fn wait_for_can_measurements(
|
||||
let frequency = u32::from_be_bytes(bytes);
|
||||
match sensor {
|
||||
SensorSlot::A => {
|
||||
moistures.sensor_a_hz[plant-1] = Some(frequency as f32);
|
||||
moistures.sensor_a_hz[plant - 1] =
|
||||
Some(frequency as f32);
|
||||
}
|
||||
SensorSlot::B => {
|
||||
moistures.sensor_b_hz[plant-1] = Some(frequency as f32);
|
||||
moistures.sensor_b_hz[plant - 1] =
|
||||
Some(frequency as f32);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -29,8 +29,8 @@ use ::log::{error, info, warn};
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::sync::Arc;
|
||||
use alloc::{format, vec};
|
||||
use alloc::vec::Vec;
|
||||
use alloc::{format, vec};
|
||||
use chrono::{DateTime, Datelike, Timelike, Utc};
|
||||
use chrono_tz::Tz::{self, UTC};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
@@ -501,16 +501,17 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
|
||||
info!("state of charg");
|
||||
let is_day = board.board_hal.is_day();
|
||||
let battery_state = board.board_hal.get_battery_monitor().get_state().await.unwrap_or(BatteryState::Unknown);
|
||||
let battery_state = board
|
||||
.board_hal
|
||||
.get_battery_monitor()
|
||||
.get_state()
|
||||
.await
|
||||
.unwrap_or(BatteryState::Unknown);
|
||||
info!("Battery state is {battery_state:?}");
|
||||
|
||||
let state_of_charge = match &battery_state {
|
||||
BatteryState::Unknown => {
|
||||
0
|
||||
}
|
||||
BatteryState::Info(data) => {
|
||||
data.state_of_charge
|
||||
}
|
||||
BatteryState::Unknown => 0,
|
||||
BatteryState::Info(data) => data.state_of_charge,
|
||||
};
|
||||
|
||||
let mut light_state = LightState {
|
||||
@@ -529,22 +530,10 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
board.board_hal.get_config().night_lamp.night_lamp_hour_end,
|
||||
);
|
||||
|
||||
if state_of_charge
|
||||
< board
|
||||
.board_hal
|
||||
.get_config()
|
||||
.night_lamp
|
||||
.low_soc_cutoff
|
||||
{
|
||||
if state_of_charge < board.board_hal.get_config().night_lamp.low_soc_cutoff {
|
||||
board.board_hal.get_esp().set_low_voltage_in_cycle();
|
||||
info!("Set low voltage in cycle");
|
||||
} else if state_of_charge
|
||||
> board
|
||||
.board_hal
|
||||
.get_config()
|
||||
.night_lamp
|
||||
.low_soc_restore
|
||||
{
|
||||
} else if state_of_charge > board.board_hal.get_config().night_lamp.low_soc_restore {
|
||||
board.board_hal.get_esp().clear_low_voltage_in_cycle();
|
||||
info!("Clear low voltage in cycle");
|
||||
}
|
||||
@@ -652,17 +641,23 @@ pub async fn do_secure_pump(
|
||||
plant_config: &PlantConfig,
|
||||
dry_run: bool,
|
||||
) -> FatResult<PumpResult> {
|
||||
let mut current_collector = vec![0_u16; plant_config.pump_time_s.into()];
|
||||
let mut flow_collector = vec![0_i16; plant_config.pump_time_s.into()];
|
||||
const STARTUP_IGNORE_MS: u32 = 500;
|
||||
const STARTUP_ABORT_CURRENT_MA: u16 = 1500;
|
||||
|
||||
let steps_in_50ms = plant_config.pump_time_s as usize * 20;
|
||||
|
||||
let mut current_collector = vec![0_u16; steps_in_50ms];
|
||||
let mut flow_collector = vec![0_i16; steps_in_50ms];
|
||||
let mut error = false;
|
||||
let mut first_error = true;
|
||||
let mut pump_time_s = 0;
|
||||
let mut pump_time_ms: u32 = 0;
|
||||
|
||||
if !dry_run {
|
||||
board.board_hal.get_tank_sensor()?.reset_flow_meter();
|
||||
board.board_hal.get_tank_sensor()?.start_flow_meter();
|
||||
board.board_hal.pump(plant_id, true).await?;
|
||||
Timer::after_millis(10).await;
|
||||
for step in 0..plant_config.pump_time_s as usize {
|
||||
|
||||
for step in 0..steps_in_50ms {
|
||||
let flow_value = board.board_hal.get_tank_sensor()?.get_flow_meter_value();
|
||||
flow_collector[step] = flow_value;
|
||||
let flow_value_ml = flow_value as f32 * board.board_hal.get_config().tank.ml_per_pulse;
|
||||
@@ -682,7 +677,20 @@ pub async fn do_secure_pump(
|
||||
let current_ma = current.as_milliamperes() as u16;
|
||||
current_collector[step] = current_ma;
|
||||
let high_current = current_ma > plant_config.max_pump_current_ma;
|
||||
if high_current && first_error {
|
||||
if pump_time_ms < STARTUP_IGNORE_MS
|
||||
&& high_current
|
||||
&& current_ma > STARTUP_ABORT_CURRENT_MA
|
||||
{
|
||||
log(
|
||||
LogMessage::PumpOverCurrent,
|
||||
plant_id as u32 + 1,
|
||||
current_ma as u32,
|
||||
plant_config.max_pump_current_ma.to_string().as_str(),
|
||||
step.to_string().as_str(),
|
||||
)
|
||||
.await;
|
||||
error = true;
|
||||
} else if high_current && first_error {
|
||||
log(
|
||||
LogMessage::PumpOverCurrent,
|
||||
plant_id as u32 + 1,
|
||||
@@ -732,12 +740,14 @@ pub async fn do_secure_pump(
|
||||
error = true;
|
||||
break;
|
||||
} else {
|
||||
//e.g., v3 without a sensor ends here, do not spam
|
||||
error!("Error getting pump current: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Timer::after_millis(1000).await;
|
||||
pump_time_s += 1;
|
||||
|
||||
//todo calcualte dynamically to offset time for stuff
|
||||
Timer::after_millis(50).await;
|
||||
pump_time_ms += 50;
|
||||
}
|
||||
}
|
||||
board.board_hal.get_tank_sensor()?.stop_flow_meter();
|
||||
@@ -751,14 +761,14 @@ pub async fn do_secure_pump(
|
||||
min_current_ma: current_collector[0],
|
||||
flow_value_ml,
|
||||
flow_value_count: final_flow_value,
|
||||
pump_time_s,
|
||||
pump_time_s: (pump_time_ms / 1000) as u16,
|
||||
error,
|
||||
})
|
||||
}
|
||||
|
||||
async fn update_charge_indicator(
|
||||
board: &mut MutexGuard<'static, CriticalSectionRawMutex, HAL<'static>>,
|
||||
) -> FatResult<()>{
|
||||
) -> FatResult<()> {
|
||||
//FIXME add config and code to allow power supply mode, in this case this is a nop
|
||||
//we have mppt controller, ask it for charging current
|
||||
let current = board.board_hal.get_mptt_current().await?;
|
||||
@@ -769,7 +779,6 @@ async fn update_charge_indicator(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
async fn publish_tank_state(
|
||||
board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'static>>,
|
||||
tank_state: &TankState,
|
||||
@@ -949,11 +958,7 @@ async fn publish_mppt_state(
|
||||
async fn publish_battery_state(
|
||||
board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'static>>,
|
||||
) -> () {
|
||||
let state = board
|
||||
.board_hal
|
||||
.get_battery_monitor()
|
||||
.get_state()
|
||||
.await;
|
||||
let state = board.board_hal.get_battery_monitor().get_state().await;
|
||||
let value = match state {
|
||||
Ok(state) => {
|
||||
let json = serde_json::to_string(&state).unwrap().to_owned();
|
||||
@@ -986,7 +991,7 @@ async fn wait_infinity(
|
||||
loop {
|
||||
{
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
match update_charge_indicator(&mut board).await{
|
||||
match update_charge_indicator(&mut board).await {
|
||||
Ok(_) => {}
|
||||
Err(error) => {
|
||||
if !suppress_further_mppt_error {
|
||||
@@ -1069,18 +1074,23 @@ async fn wait_infinity(
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_serial_config(board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'_>>, serial_config_receive: &AtomicBool, reboot_now: &AtomicBool) -> FatResult<()> {
|
||||
async fn handle_serial_config(
|
||||
board: &mut MutexGuard<'_, CriticalSectionRawMutex, HAL<'_>>,
|
||||
serial_config_receive: &AtomicBool,
|
||||
reboot_now: &AtomicBool,
|
||||
) -> FatResult<()> {
|
||||
match board.board_hal.get_esp().read_serial_line().await {
|
||||
Ok(serial_line) => {
|
||||
match serial_line {
|
||||
None => {
|
||||
Ok(())
|
||||
}
|
||||
Ok(serial_line) => match serial_line {
|
||||
None => Ok(()),
|
||||
Some(line) => {
|
||||
if serial_config_receive.load(Ordering::Relaxed) {
|
||||
let ll = line.as_str();
|
||||
let config: PlantControllerConfig = serde_json::from_str(ll)?;
|
||||
board.board_hal.get_esp().save_config(Vec::from(ll.as_bytes())).await?;
|
||||
board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.save_config(Vec::from(ll.as_bytes()))
|
||||
.await?;
|
||||
board.board_hal.set_config(config);
|
||||
serial_config_receive.store(false, Ordering::Relaxed);
|
||||
info!("Config received, rebooting");
|
||||
@@ -1094,10 +1104,8 @@ async fn handle_serial_config(board: &mut MutexGuard<'_, CriticalSectionRawMutex
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
error!("Error reading serial line");
|
||||
Ok(())
|
||||
|
||||
@@ -16,7 +16,6 @@ pub enum MoistureSensorError {
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
pub enum MoistureSensorState {
|
||||
Disabled,
|
||||
MoistureValue { raw_hz: f32, moisture_percent: f32 },
|
||||
SensorError(MoistureSensorError),
|
||||
}
|
||||
@@ -117,12 +116,11 @@ impl PlantState {
|
||||
plant_id: usize,
|
||||
board: &mut HAL<'_>,
|
||||
) -> Self {
|
||||
let sensor_a = { //if board.board_hal.get_config().plants[plant_id].sensor_a {
|
||||
let sensor_a = {
|
||||
//if board.board_hal.get_config().plants[plant_id].sensor_a {
|
||||
let raw = moistures.sensor_a_hz[plant_id];
|
||||
match raw {
|
||||
None => {
|
||||
MoistureSensorState::SensorError(MoistureSensorError::NoMessage)
|
||||
}
|
||||
None => MoistureSensorState::SensorError(MoistureSensorError::NoMessage),
|
||||
Some(raw) => {
|
||||
match map_range_moisture(
|
||||
raw,
|
||||
@@ -141,17 +139,15 @@ impl PlantState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}; // else {
|
||||
// MoistureSensorState::Disabled
|
||||
//};
|
||||
|
||||
let sensor_b = { //if board.board_hal.get_config().plants[plant_id].sensor_b {
|
||||
let sensor_b = {
|
||||
//if board.board_hal.get_config().plants[plant_id].sensor_b {
|
||||
let raw = moistures.sensor_b_hz[plant_id];
|
||||
match raw {
|
||||
None => {
|
||||
MoistureSensorState::SensorError(MoistureSensorError::NoMessage)
|
||||
}
|
||||
None => MoistureSensorState::SensorError(MoistureSensorError::NoMessage),
|
||||
Some(raw) => {
|
||||
match map_range_moisture(
|
||||
raw,
|
||||
|
||||
@@ -43,7 +43,6 @@ where
|
||||
plant_state.push(PlantState::read_hardware_state(moistures, i, &mut board).await);
|
||||
}
|
||||
let a = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_a {
|
||||
MoistureSensorState::Disabled => "disabled".to_string(),
|
||||
MoistureSensorState::MoistureValue {
|
||||
raw_hz,
|
||||
moisture_percent,
|
||||
@@ -53,7 +52,6 @@ where
|
||||
MoistureSensorState::SensorError(err) => format!("{err:?}"),
|
||||
}));
|
||||
let b = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_b {
|
||||
MoistureSensorState::Disabled => "disabled".to_string(),
|
||||
MoistureSensorState::MoistureValue {
|
||||
raw_hz,
|
||||
moisture_percent,
|
||||
@@ -128,11 +126,7 @@ pub(crate) async fn get_battery_state<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
) -> FatResult<Option<String>> {
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let battery_state = board
|
||||
.board_hal
|
||||
.get_battery_monitor()
|
||||
.get_state()
|
||||
.await?;
|
||||
let battery_state = board.board_hal.get_battery_monitor().get_state().await?;
|
||||
Ok(Some(serde_json::to_string(&battery_state)?))
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@ use crate::webserver::get_json::{
|
||||
use crate::webserver::get_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};
|
||||
use crate::webserver::post_json::{
|
||||
board_test, can_power, detect_sensors, night_lamp_test, pump_test, set_config, wifi_scan,
|
||||
write_time,
|
||||
};
|
||||
use crate::{bail, BOARD_ACCESS};
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::{String, ToString};
|
||||
|
||||
@@ -142,9 +142,6 @@ where
|
||||
|
||||
board.board_hal.can_power(can_power_request.state).await?;
|
||||
let enable = can_power_request.state;
|
||||
info!(
|
||||
"set can power to {enable}"
|
||||
);
|
||||
info!("set can power to {enable}");
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user