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