Compare commits

..

1 Commits

Author SHA1 Message Date
3a702cb84f
suggestion for logging location 2025-03-15 15:57:15 +01:00
2 changed files with 18 additions and 7 deletions

View File

@ -403,13 +403,6 @@ fn safe_main() -> anyhow::Result<()> {
let tank_state = determine_tank_state(&mut board, &config);
if let Some(_err) = tank_state.got_error(&config.tank) {
//TODO log error state to serial
//log(
//LogMessage::SensorTankRaw,
//raw_value_mv as u32,
//percent as u32,
//"",
//"",
//);
} else if tank_state.warn_level(&config.tank).is_ok_and(|warn| warn) {
//TODO(judge) enable logging again, might require returning level as well
//println!(

View File

@ -27,6 +27,14 @@ fn raw_volatge_to_divider_percent(raw_value_mv: f32) -> Result<f32, TankError> {
let r2 = raw_value_mv * 50.0 / (3.3 - raw_value_mv);
let mut percent = r2 / 190_f32 * 100_f32;
percent = percent.clamp(0.0, 100.0);
// TODO(judge) move this to a sensible place
//log(
//LogMessage::SensorTankRaw,
//raw_value_mv as u32,
//percent as u32,
//"",
//"",
//);
Ok(percent)
}
@ -54,6 +62,11 @@ impl TankState {
TankState::TankSensorError(err) => Err(err.clone()),
TankState::TankSensorPresent(raw_value_mv) => {
let tank_fill_percent = raw_voltage_to_tank_fill_percent(*raw_value_mv, config)?;
//TODO(judge) move logging to more sensible place
//println!(
//"Tank sensor returned mv {} as {}% leaving {} ml useable",
//rv.raw, percent as u8, rv.left_ml
//);
Ok(config.tank_useable_ml as f32 * tank_fill_percent / 100.)
}
}
@ -65,6 +78,11 @@ impl TankState {
TankState::TankSensorPresent(raw_value_mv) => {
let tank_fill_percent = raw_voltage_to_tank_fill_percent(*raw_value_mv, config)?;
if tank_fill_percent > config.tank_empty_percent.into() {
//TODO(judge) move logging to more sensible place
//println!(
//"Enough water, current percent is {}, minimum empty level is {}",
//percent as u8, config.tank.tank_empty_percent
//);
Ok(true)
} else {
Ok(false)