Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix charge_rate when discharging #2

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- MSRV was raised to 1.62.0.

### Fixed

- MAX17048 & MAX17049 `charge_rate` correctly handles negative values (such as when discharging). See: [PR #2](https://github.com/eldruin/max170xx-rs/pull/2)

## 0.1.0 - 2020-07-19

Initial release of the driver to crates.io.
Expand Down
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
20 changes: 20 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ mod max17048 {
get_float!(get_soc, new_48, destroy_48, soc, SOC, 48, 126, 48.49);
get_float!(voltage, new_48, destroy_48, voltage, VCELL, 0xA4, 0x9F, 3.29);
get_float!(rate, new_48, destroy_48, charge_rate, CRATE, 1, 0x45, 67.6);
get_float!(
negative_rate,
new_48,
destroy_48,
charge_rate,
CRATE,
0xFE,
0xBB,
-67.6
);
cmd_test!(reset, new_48, destroy_48, reset, COMMAND, POR_X8_X9);
set_table_test!(set_table, new_48, destroy_48);
}
Expand All @@ -144,6 +154,16 @@ mod max17049 {
get_float!(get_soc, new_49, destroy_49, soc, SOC, 48, 126, 48.49);
get_float!(voltage, new_49, destroy_49, voltage, VCELL, 0xA4, 0x9F, 6.58);
get_float!(rate, new_49, destroy_49, charge_rate, CRATE, 1, 0x45, 67.6);
get_float!(
negative_rate,
new_49,
destroy_49,
charge_rate,
CRATE,
0xFE,
0xBB,
-67.6
);
cmd_test!(reset, new_49, destroy_49, reset, COMMAND, POR_X8_X9);
set_table_test!(set_table, new_49, destroy_49);
}
Expand Down