fix tank calculation, update bq34 driver
This commit is contained in:
@@ -236,8 +236,10 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
};
|
||||
|
||||
println!("attempting to connect wifi");
|
||||
let mut ip_address: Option<String> = None;
|
||||
match board.wifi(wifi.ssid, wifi.password, 10000) {
|
||||
Ok(_) => {
|
||||
Ok(ip_info) => {
|
||||
ip_address = Some(ip_info.ip.to_string());
|
||||
online_mode = OnlineMode::Wifi;
|
||||
}
|
||||
Err(_) => {
|
||||
@@ -292,6 +294,14 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
if online_mode == OnlineMode::Online {
|
||||
match ip_address {
|
||||
Some(add_some) => {
|
||||
let _ = board.mqtt_publish(&config, "/firmware/address", add_some.as_bytes());
|
||||
},
|
||||
None => {
|
||||
let _ = board.mqtt_publish(&config, "/firmware/address", "N/A?".as_bytes());
|
||||
},
|
||||
}
|
||||
let _ = board.mqtt_publish(&config, "/firmware/githash", git_hash.as_bytes());
|
||||
let _ = board.mqtt_publish(&config, "/firmware/buildtime", build_timestamp.as_bytes());
|
||||
let _ = board.mqtt_publish(&config, "/firmware/last_online", europe_time.to_rfc3339().as_bytes());
|
||||
@@ -679,7 +689,7 @@ fn determine_tank_state(
|
||||
);
|
||||
})
|
||||
.and_then(|percent| {
|
||||
rv.left_ml = (percent * config.tank_useable_ml as f32) as u32;
|
||||
rv.left_ml = ((percent * config.tank_useable_ml as f32) / 100_f32) as u32;
|
||||
println!(
|
||||
"Tank sensor returned mv {} as {}% leaving {} ml useable",
|
||||
rv.raw, percent as u8, rv.left_ml
|
||||
@@ -691,12 +701,12 @@ fn determine_tank_state(
|
||||
percent as u8, config.tank_warn_percent
|
||||
);
|
||||
}
|
||||
if config.tank_empty_percent > percent as u8 {
|
||||
if config.tank_empty_percent < percent as u8 {
|
||||
println!(
|
||||
"Empty water, current percent is {}, minimum empty level is {}",
|
||||
"Enough water, current percent is {}, minimum empty level is {}",
|
||||
percent as u8, config.tank_empty_percent
|
||||
);
|
||||
rv.enough_water = false;
|
||||
rv.enough_water = true;
|
||||
}
|
||||
return Ok(());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user