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

Energy rate miscalculation #66

Open
akintomiwaopemipo opened this issue Jul 1, 2020 · 2 comments
Open

Energy rate miscalculation #66

akintomiwaopemipo opened this issue Jul 1, 2020 · 2 comments

Comments

@akintomiwaopemipo
Copy link

Operating system: windows
First of all, Thanks for always being there svartalf. Please help me with this one too.

extern crate uom;
extern crate math;

use math::round::half_to_even;

fn main() -> Result<(), battery::Error> {
    let manager = battery::Manager::new()?;

    for (_idx, maybe_battery) in manager.batteries()?.enumerate() {
        let battery = maybe_battery?;
        println!("Percentage charge: {:?}%",(half_to_even(f64::from(f32::from(battery.state_of_charge()))*100.0,0) as i32));
        println!("Time to full: {:?}", battery.time_to_full());
        println!("Time to empty: {:?}", battery.time_to_empty());
        println!("Energy rate: {:?}", battery.energy_rate());
        println!("State: {:?}", battery.state());
        println!("");
    }

    Ok(())
}

I got

Percentage charge: 88%
Time to full: None
Time to empty: None
Energy rate: 0.0 m^2 kg^1 s^-3
State: Discharging
@svartalf
Copy link
Owner

svartalf commented Jul 2, 2020

Hi, @mkoakintomiwa!

Without knowing current energy rate it is impossible to calculate time_to_full and time_to_empty values (and it goes to zero because of #63 fix).

It seems that you are hitting the following case from the BATTERY_STATUS structure documentation at MSDN and your battery driver can't report it:

Rate

If the rate is unavailable, this member is BATTERY_UNKNOWN_RATE. If the state of the battery or power source changes, the rate may become available.

I'm not actually sure if that's a case, because I can't reproduce your problem so far, so it is hard to say what the exact issue.
Yet, it seems that another option to fetch this information is to query the BatteryEstimatedTime value and use it instead.

Let me try to write a fix and maybe we will try to test it later then?

@akintomiwaopemipo
Copy link
Author

Okay @svartalf , that is fine by me. I will wait for the fix. Thanks alot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants