I've found examples on the web for this- none of which are for C. Can anyone provide an example of a C program that scans a laptop's battery charge and writes that to a float value? I'm not at all sure how to go about doing this.
Thanks in advance!
Printable View
I've found examples on the web for this- none of which are for C. Can anyone provide an example of a C program that scans a laptop's battery charge and writes that to a float value? I'm not at all sure how to go about doing this.
Thanks in advance!
That's C++, but beggars can't be picky. Thanks! I'll see what I can do with this. B-)
It is NOT C++... You can do that very easily in standard C....
What it is is a simple windows API call... Like most of them, you provide the requisite struct, call the function and then extract the data you need...
Here's what the GetSystemPowerStatusEx2 function returns...
In C.... #include <winbase.h> and link with coredll.lib....Code:typedef struct _SYSTEM_POWER_STATUS_EX2 {
BYTE ACLineStatus;
BYTE BatteryFlag;
BYTE BatteryLifePercent;
BYTE Reserved1;
DWORD BatteryLifeTime;
DWORD BatteryFullLifeTime;
BYTE Reserved2;
BYTE BackupBatteryFlag;
BYTE BackupBatteryLifePercent;
BYTE Reserved3;
DWORD BackupBatteryLifeTime;
DWORD BackupBatteryFullLifeTime;
DWORD BatteryVoltage;
DWORD BatteryCurrent;
DWORD BatteryAverageCurrent;
DWORD BatteryAverageInterval;
DWORD BatterymAHourConsumed;
DWORD BatteryTemperature;
DWORD BackupBatteryVoltage;
BYTE BatteryChemistry;
// Add any extra information after the BatteryChemistry member.
} SYSTEM_POWER_STATUS_EX2, *PSYSTEM_POWER_STATUS_EX2, *LPSYSTEM_POWER_STATUS_EX2;
Really... it's not that hard.Code:float GetBatteryTime(void)
{ SYSTEM_POWER_STATUS_EX2 Stat;
if (GetSystemPowerStatusEx2(&Stat,sizeof(Stat),TRUE))
return (float) Stat.BatteryLifeTime;
else
return -1; } // error message;
Ahh. I got confused because most of the sources on Microsoft.com are in non-C languages. Again, thanks! You did a good job breaking it all down.
GetSystemPowerStatus Function (Windows)
SYSTEM_POWER_STATUS Structure (Windows)
Assuming you're not using Windows Embedded CE...
gg