remove anyhow
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use crate::alloc::string::{String, ToString};
|
||||
use crate::config::TankConfig;
|
||||
use crate::hal::HAL;
|
||||
use crate::FatError::FatResult;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::mutex::MutexGuard;
|
||||
use serde::Serialize;
|
||||
|
||||
const OPEN_TANK_VOLTAGE: f32 = 3.0;
|
||||
@@ -113,7 +117,7 @@ impl TankState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_mqtt_info(&self, config: &TankConfig, water_temp: &anyhow::Result<f32>) -> TankInfo {
|
||||
pub fn as_mqtt_info(&self, config: &TankConfig, water_temp: &FatResult<f32>) -> TankInfo {
|
||||
let mut tank_err: Option<TankError> = None;
|
||||
let left_ml = match self.left_ml(config) {
|
||||
Err(err) => {
|
||||
@@ -150,40 +154,41 @@ impl TankState {
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn determine_tank_state(board: &mut std::sync::MutexGuard<'_, HAL<'_>>) -> TankState {
|
||||
// if board.board_hal.get_config().tank.tank_sensor_enabled {
|
||||
// match board
|
||||
// .board_hal
|
||||
// .get_tank_sensor()
|
||||
// .context("no sensor")
|
||||
// .and_then(|f| f.tank_sensor_voltage())
|
||||
// {
|
||||
// Ok(raw_sensor_value_mv) => TankState::Present(raw_sensor_value_mv),
|
||||
// Err(err) => TankState::Error(TankError::BoardError(err.to_string())),
|
||||
// }
|
||||
// } else {
|
||||
// TankState::Disabled
|
||||
// }
|
||||
// }
|
||||
pub async fn determine_tank_state(
|
||||
board: &mut MutexGuard<'static, CriticalSectionRawMutex, HAL<'static>>,
|
||||
) -> TankState {
|
||||
if board.board_hal.get_config().tank.tank_sensor_enabled {
|
||||
match board
|
||||
.board_hal
|
||||
.get_tank_sensor()
|
||||
.and_then(|f| core::prelude::v1::Ok(f.tank_sensor_voltage()))
|
||||
{
|
||||
Ok(raw_sensor_value_mv) => TankState::Present(raw_sensor_value_mv.await.unwrap()),
|
||||
Err(err) => TankState::Error(TankError::BoardError(err.to_string())),
|
||||
}
|
||||
} else {
|
||||
TankState::Disabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
/// Information structure send to mqtt for monitoring purposes
|
||||
pub struct TankInfo {
|
||||
/// there is enough water in the tank
|
||||
enough_water: bool,
|
||||
pub(crate) enough_water: bool,
|
||||
/// warning that water needs to be refilled soon
|
||||
warn_level: bool,
|
||||
pub(crate) warn_level: bool,
|
||||
/// estimation how many ml are still in the tank
|
||||
left_ml: Option<f32>,
|
||||
pub(crate) left_ml: Option<f32>,
|
||||
/// if there is an issue with the water level sensor
|
||||
sensor_error: Option<TankError>,
|
||||
pub(crate) sensor_error: Option<TankError>,
|
||||
/// raw water sensor value
|
||||
raw: Option<f32>,
|
||||
pub(crate) raw: Option<f32>,
|
||||
/// percent value
|
||||
percent: Option<f32>,
|
||||
pub(crate) percent: Option<f32>,
|
||||
/// water in the tank might be frozen
|
||||
water_frozen: bool,
|
||||
pub(crate) water_frozen: bool,
|
||||
/// water temperature
|
||||
water_temp: Option<f32>,
|
||||
temp_sensor_error: Option<String>,
|
||||
pub(crate) water_temp: Option<f32>,
|
||||
pub(crate) temp_sensor_error: Option<String>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user