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 overflow and change time to minutes on MacOS #11

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 6 additions & 5 deletions battery/src/platform/macos/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ impl IoKitDevice {

let voltage = ps.get_u32(b"Voltage")
.expect("IOKit is not providing required data");
let amperage = ps.get_u32(b"Amperage")
.expect("IOKit is not providing required data");
let amperage = ps.get_isize(b"Amperage")
.expect("IOKit is not providing required data")
.abs() as u32;
let design_capacity = ps.get_u32(b"DesignCapacity")
.expect("IOKit is not providing required data");
let max_capacity = ps.get_u32(b"MaxCapacity")
Expand All @@ -69,15 +70,15 @@ impl IoKitDevice {
if val == 65535 {
None
} else {
Some(val)
Some(val * 60)
}
});
let instant_time_to_full = ps.get_isize(b"InstantTimeToFull")
.and_then(|val| {
if val == 65535 {
None
} else {
Some(val)
Some(val * 60)
}
});

Expand Down Expand Up @@ -125,7 +126,7 @@ impl BatteryDevice for IoKitDevice {
}

fn percentage(&self) -> f32 {
(100 * self.energy() / self.energy_full()) as f32
self.current_capacity as f32 / self.max_capacity as f32 * 100.0
}

fn state(&self) -> State {
Expand Down