Refactor flow meter handling: switch get_flow_meter_value to get_full_flow_count, update related structs and logic to use u32 for flow values.
This commit is contained in:
@@ -94,7 +94,7 @@ impl<'a> TankSensor<'a> {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_flow_meter_value(&mut self) -> i16 {
|
||||
fn get_flow_meter_value(&mut self) -> i16 {
|
||||
FLOW_UNIT.lock(|refcell| {
|
||||
refcell.borrow_mut().as_mut().map_or(0, |unit| unit.value())
|
||||
})
|
||||
|
||||
@@ -123,6 +123,8 @@ struct PumpInfo {
|
||||
max_current_ma: u16,
|
||||
min_current_ma: u16,
|
||||
error: String,
|
||||
flow_raw: u32,
|
||||
flow_ml: f32,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -132,7 +134,7 @@ pub struct PumpResult {
|
||||
min_current_ma: u16,
|
||||
error: String,
|
||||
flow_value_ml: f32,
|
||||
flow_value_count: i16,
|
||||
flow_value_count: u32,
|
||||
pump_time_s: u16,
|
||||
overcurrent_ma: Option<u16>,
|
||||
}
|
||||
@@ -456,6 +458,8 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
0,
|
||||
0,
|
||||
String::new(),
|
||||
0,
|
||||
0.0,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -472,6 +476,8 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
state.max_current_ma,
|
||||
state.min_current_ma,
|
||||
state.error,
|
||||
state.flow_value_count,
|
||||
state.flow_value_ml,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -485,6 +491,8 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
||||
0,
|
||||
0,
|
||||
format!("{err:?}"),
|
||||
0,
|
||||
0.0,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -722,7 +730,7 @@ pub async fn do_secure_pump(
|
||||
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 flow_collector = vec![0_u32; steps_in_50ms];
|
||||
let mut error = String::new();
|
||||
let mut first_error = true;
|
||||
let mut pump_time_ms: u32 = 0;
|
||||
@@ -773,7 +781,7 @@ pub async fn do_secure_pump(
|
||||
|
||||
for step in 0..steps_in_50ms {
|
||||
let step_start = Instant::now();
|
||||
let flow_value = board.board_hal.get_tank_sensor()?.get_flow_meter_value();
|
||||
let flow_value = board.board_hal.get_tank_sensor()?.get_full_flow_count();
|
||||
flow_collector[step] = flow_value;
|
||||
let flow_value_ml = flow_value as f32 * board.board_hal.get_config().tank.ml_per_pulse;
|
||||
|
||||
@@ -885,7 +893,7 @@ pub async fn do_secure_pump(
|
||||
pump_time_ms = 1337;
|
||||
}
|
||||
board.board_hal.get_tank_sensor()?.stop_flow_meter();
|
||||
let final_flow_value = board.board_hal.get_tank_sensor()?.get_flow_meter_value();
|
||||
let final_flow_value = board.board_hal.get_tank_sensor()?.get_full_flow_count();
|
||||
let flow_value_ml = final_flow_value as f32 * board.board_hal.get_config().tank.ml_per_pulse;
|
||||
info!("Final flow value is {final_flow_value} with {flow_value_ml} ml");
|
||||
current_collector.sort();
|
||||
@@ -1052,6 +1060,8 @@ async fn pump_info(
|
||||
max_current_ma: u16,
|
||||
min_current_ma: u16,
|
||||
error: String,
|
||||
flow_raw: u32,
|
||||
flow_ml: f32,
|
||||
) {
|
||||
let pump_info = PumpInfo {
|
||||
enabled: pump_active,
|
||||
@@ -1060,6 +1070,8 @@ async fn pump_info(
|
||||
max_current_ma,
|
||||
min_current_ma,
|
||||
error,
|
||||
flow_raw,
|
||||
flow_ml,
|
||||
};
|
||||
let pump_topic = format!("/pump{}", plant_id + 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user