From fbf1a84e7df492b1724c6449f54b614311267e06 Mon Sep 17 00:00:00 2001 From: ju6ge Date: Sat, 15 Mar 2025 15:57:15 +0100 Subject: [PATCH] suggestion for logging location --- rust/src/main.rs | 31 +++++++++++++++++++++++++++++++ rust/src/tank.rs | 25 ------------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/rust/src/main.rs b/rust/src/main.rs index 3f4902c..cf04194 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -401,6 +401,37 @@ fn safe_main() -> anyhow::Result<()> { let dry_run = false; 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!( + //"Low water, current percent is {}, minimum warn level is {}", + //percent as u8, config.tank.tank_warn_percent + //); + board.general_fault(true); + } else if tank_state.enough_water(&config.tank).is_ok_and(|enough| enough) { + //TODO(judge) enable logging again, might require returning level as well + //println!( + //"Enough water, current percent is {}, minimum empty level is {}", + //percent as u8, config.tank.tank_empty_percent + //); + } else { + if let Ok(_left_ml) = tank_state.left_ml(&config.tank) { + //TODO(judge) enable logging again, might require returning level as well + //println!( + //"Tank sensor returned mv {} as {}% leaving {} ml useable", + //rv.raw, percent as u8, rv.left_ml + //); + } + } let mut water_frozen = false; let mut attempt = 1; diff --git a/rust/src/tank.rs b/rust/src/tank.rs index 29b9041..eb531a0 100644 --- a/rust/src/tank.rs +++ b/rust/src/tank.rs @@ -27,14 +27,6 @@ fn raw_volatge_to_divider_percent(raw_value_mv: f32) -> Result { 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) } @@ -62,11 +54,6 @@ 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.) } } @@ -78,11 +65,6 @@ 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) @@ -98,13 +80,6 @@ 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_warn_percent.into() { - //TODO(judge) move logging to more sensible place - //println!( - //"Low water, current percent is {}, minimum warn level is {}", - //percent as u8, config.tank.tank_warn_percent - //); - // TODO(judge) move board fault setting - // board.general_fault(true); Ok(true) } else { Ok(false)