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. In addition, /sys/class/power_supply/*/current_* are in µA according to the linux-src/Documentation/power/power_supply_class.txt and not in µW as expected by the original code Signed-off-by: Michal Hocko Index: powertop/powertop.c =================================================================== --- powertop.orig/powertop.c 2008-09-01 14:19:21.000000000 -0600 +++ powertop/powertop.c 2008-09-01 14:27:07.000000000 -0600 @@ -630,12 +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; - memset(line, 0, 1024); - if (fgets(line, 1024, file) != NULL) { - watts_left = strtoull(line, NULL, 10) / 1000000.0; + 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; fclose(file); sprintf(filename, "/sys/class/power_supply/%s/current_now", dirent->d_name); @@ -644,7 +651,7 @@ void print_battery_sysfs(void) continue; memset(line, 0, 1024); if (fgets(line, 1024, file) != NULL) { - watts_drawn = strtoull(line, NULL, 10) / 1000000.0; + amperes_drawn = strtoull(line, NULL, 10) / 1000000.0; } fclose(file);