Skip to content

Commit

Permalink
Fix charge_rate when discharging
Browse files Browse the repository at this point in the history
MAX17048 & MAX17049 report negative `CRATE` values when discharging, so interpret them as i16
instead of u16 before converting to f32.

Resolves eldruin#1
  • Loading branch information
bencochran committed Dec 9, 2023
1 parent 90c923a commit 96ca091
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/max170x8_x9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro_rules! impl_common_48_49 {
/// Get the approximate charge or discharge rate of the battery
/// in percentage / hour
pub fn charge_rate(&mut self) -> Result<f32, Error<E>> {
let rate = self.read_register(Register::CRATE)?;
let rate = self.read_register(Register::CRATE)? as i16;
Ok(f32::from(rate) * 0.208)
}
}
Expand Down

0 comments on commit 96ca091

Please sign in to comment.