From: mstsxfx@gmail.com Subject: [PATCH] use charge_now when energy_now is not present Some batteries (like one in the Futjitsu Siemens Lifebook S71110) don't export energy_now attribute and exports only change_now in the power_supply sys directory. However, we can use this value when it is multiplied by current voltage. Signed-off-by: Michal Hocko --- a/powertop.c 2008-07-21 10:35:10.000000000 -0600 +++ b/powertop.c 2008-07-21 10:36:03.000000000 -0600 @@ -630,11 +630,19 @@ void print_battery_sysfs(void) sprintf(filename, "/sys/class/power_supply/%s/energy_now", dirent->d_name); file = fopen(filename, "r"); - if (!file) - continue; + watts_left = 1; + if (!file) { + sprintf(filename, "/sys/class/power_supply/%s/charge_now", dirent->d_name); + file = fopen(filename, "r"); + if (!file) + continue; + + /* W = A * V */ + watts_left = voltage; + } memset(line, 0, 1024); if (fgets(line, 1024, file) != NULL) { - watts_left = strtoull(line, NULL, 10) / 1000000.0; + watts_left *= strtoull(line, NULL, 10) / 1000000.0; } fclose(file);