How does Windows calculate the remaining battery time?

I am testing the application so that users know when to connect and disconnect their laptop in order to get the most out of their laptop battery. Also, I'm trying to play a tooltip using a Windows power meter.

So far, he is quite successful with a few differences.

  • Windows timeout notification, for example. β€œX hr XX min (XX%) left” is not displayed after about a minute.
  • Windows latency seems more stable when the load on the battery changes.

This made me think that the algorithm remaining in Windows averaged over the last minute or so, but I could not find the documentation about it. Does anyone know what he is doing to reproduce it?

Here is my implementation (in Python, but the question is the agnostic language). I think that I will need to average the most recent discharge rates x from polling every y seconds, but you need to know the values ​​for x and y .

 t = wmi.WMI(moniker = "//./root/wmi") batts = t.ExecQuery('Select * from BatteryStatus where Voltage > 0') time_left = 0 for _i, b in enumerate(batts): time_left += float(b.RemainingCapacity) / float(b.DischargeRate) hours = int(time_left) mins = 60 * (time_left % 1.0) return '%i hr %i min' % (hours, mins) 
+6
source share
1 answer

Windows follows the ACPI specification , and given the specification, gives a method of calculating the remaining battery life, I would suggest that it will be the way they do it.

Edit: Several confirmatory sources were found .

I am referring, in particular, to chapter 3.9.3 "Gas Battery Charge Sensor".

Remaining Battery Percentage[%] = Battery Remaining Capacity [mAh/mWh] / Last Full Charged Capacity [mAh/mWh]* 100

if you need it in hours:

Remaining Battery Life [h]= Battery Remaining Capacity [mAh/mWh] / Battery Present Drain Rate [mA/mW]

This essentially represents the current rate of change in charge capacity per unit time, you need to look at the ACPI specification to see how Windows implements it.

The variables that I would say should have been requested from the battery controller, and I would have allowed Windows to handle all compatibility issues. To do this, there is the Win32_Battery Windows Management Tool and (probably more appropriate) Win32_PortableBattery . After some further digging, it seems that these classes calculate the remaining time for you and do not expose the current battery charge (perhaps in order to encourage people to calculate only one problem / rounding, etc.). The closest cool thing you can do is evaluate / calculate battery drain at FullChargeCapacity / DesignCapacity . The next best thing I could find looks like a lower-level API, opened through IOCTL_BATTERY_QUERY_INFORMATION , but it also seems to not give the current charge capacity in millivolts. tl; dr Use the remaining times and percentages calculated for you by the above classes, if possible: /


Aside, some laptop manufacturers are linking their own tools to calculate the remaining time and request specific microcontroller implementations in their own batteries and can make a more informed / impersonal question about the remaining battery.
+5
source

All Articles