Add flowsensor prototype, add canbus to backplane
This commit is contained in:
@@ -88,6 +88,9 @@ pub struct PumpResult {
|
||||
max_current_ma: u16,
|
||||
min_current_ma: u16,
|
||||
error: bool,
|
||||
flow_value_ml: f32,
|
||||
flow_value_count: i16,
|
||||
pump_time_s: u16,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
@@ -583,12 +586,26 @@ pub fn do_secure_pump(
|
||||
dry_run: bool,
|
||||
) -> anyhow::Result<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()];
|
||||
let mut error = false;
|
||||
let mut first_error = true;
|
||||
let mut pump_time_s = 0;
|
||||
if !dry_run {
|
||||
board.board_hal.get_tank_sensor().unwrap().reset_flow_meter();
|
||||
board.board_hal.get_tank_sensor().unwrap().start_flow_meter();
|
||||
board.board_hal.pump(plant_id, true)?;
|
||||
Delay::new_default().delay_ms(2);
|
||||
Delay::new_default().delay_ms(10);
|
||||
for step in 0..plant_config.pump_time_s as usize {
|
||||
let flow_value = board.board_hal.get_tank_sensor().unwrap().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;
|
||||
|
||||
println!("Flow value is {} ml, limit is {} ml raw sensor {}", flow_value_ml, plant_config.pump_limit_ml, flow_value);
|
||||
if flow_value_ml > plant_config.pump_limit_ml as f32 {
|
||||
println!("Flow value is reached, stopping");
|
||||
break;
|
||||
}
|
||||
|
||||
let current = board.board_hal.pump_current(plant_id);
|
||||
match current {
|
||||
Ok(current) => {
|
||||
@@ -651,13 +668,21 @@ pub fn do_secure_pump(
|
||||
}
|
||||
}
|
||||
Delay::new_default().delay_ms(1000);
|
||||
pump_time_s += 1;
|
||||
}
|
||||
}
|
||||
board.board_hal.get_tank_sensor().unwrap().stop_flow_meter();
|
||||
let final_flow_value = board.board_hal.get_tank_sensor().unwrap().get_flow_meter_value();
|
||||
let flow_value_ml = final_flow_value as f32 * board.board_hal.get_config().tank.ml_per_pulse;
|
||||
println!("Final flow value is {} with {} ml", final_flow_value, flow_value_ml);
|
||||
current_collector.sort();
|
||||
Ok(PumpResult {
|
||||
median_current_ma: current_collector[current_collector.len() / 2],
|
||||
max_current_ma: current_collector[current_collector.len() - 1],
|
||||
min_current_ma: current_collector[0],
|
||||
flow_value_ml,
|
||||
flow_value_count: final_flow_value,
|
||||
pump_time_s,
|
||||
error,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user