coolbean4
coolbean4

Reputation: 1

How to accurately estimate the time remaining in a PC/Laptop battery?

I am making a C++ program on Windows in Visual Studio 2017. I want this program to calculate how long the battery will last on the laptop/PC the program is running on. I want to make this program because I have realized the estimated time remaining on my laptop battery (the battery icon in the Taskbar) is not accurate.

What factors do I need to take into account to estimate the time remaining of the battery? Or, is there code to show the discharge/charging rate of the battery?

One of these factors I have identified that changes the remaining charge in the battery is screen brightness. Is there a way to find what the user has set the brightness to?

If you have the answer, please explain each step thoroughly so I can easily understand it, because I am not very familiar with this part of C++.

Upvotes: 0

Views: 527

Answers (1)

Tofu
Tofu

Reputation: 3613

Since you mentioned Visual Studio, I'm going to assume you're on Windows. The API to retrieve power of a pc/laptop is GetSystemPowerStatus which takes a pointer to and fills the SYSTEM_POWER_STATUS structure.

Example:

#include <windows.h>

int main(){
 SYSTEM_POWER_STATUS sps = {0};
 if(GetSystemPowerStatus(&sps)){
    //check the structure
 }
 return 0;
}

Upvotes: 1

Related Questions