diff --git a/powertop.c b/powertop.c index 74eb328..387a887 100644 --- a/powertop.c +++ b/powertop.c @@ -547,95 +547,6 @@ void sort_lines(void) qsort (lines, linehead, sizeof (struct line), line_compare); } - - -int print_battery_proc_acpi(void) -{ - DIR *dir; - struct dirent *dirent; - FILE *file; - double rate = 0; - double cap = 0; - - char filename[256]; - - dir = opendir("/proc/acpi/battery"); - if (!dir) - return 0; - - while ((dirent = readdir(dir))) { - int dontcount = 0; - double voltage = 0.0; - double amperes_drawn = 0.0; - double watts_drawn = 0.0; - double amperes_left = 0.0; - double watts_left = 0.0; - char line[1024]; - - if (strlen(dirent->d_name) < 3) - continue; - - sprintf(filename, "/proc/acpi/battery/%s/state", dirent->d_name); - file = fopen(filename, "r"); - if (!file) - continue; - memset(line, 0, 1024); - while (fgets(line, 1024, file) != NULL) { - char *c; - if (strstr(line, "present:") && strstr(line, "no")) - break; - - if (strstr(line, "charging state:") - && !strstr(line, "discharging")) - dontcount = 1; - c = strchr(line, ':'); - if (!c) - continue; - c++; - - if (strstr(line, "present voltage")) - voltage = strtoull(c, NULL, 10) / 1000.0; - - if (strstr(line, "remaining capacity") && strstr(c, "mW")) - watts_left = strtoull(c, NULL, 10) / 1000.0; - - if (strstr(line, "remaining capacity") && strstr(c, "mAh")) - amperes_left = strtoull(c, NULL, 10) / 1000.0; - - if (strstr(line, "present rate") && strstr(c, "mW")) - watts_drawn = strtoull(c, NULL, 10) / 1000.0 ; - - if (strstr(line, "present rate") && strstr(c, "mA")) - amperes_drawn = strtoull(c, NULL, 10) / 1000.0; - - } - fclose(file); - - if (!dontcount) { - rate += watts_drawn + voltage * amperes_drawn; - } - cap += watts_left + voltage * amperes_left; - - - } - closedir(dir); - if (prev_bat_cap - cap < 0.001 && rate < 0.001) - last_bat_time = 0; - if (!last_bat_time) { - last_bat_time = prev_bat_time = time(NULL); - last_bat_cap = prev_bat_cap = cap; - } - if (time(NULL) - last_bat_time >= 400) { - prev_bat_cap = last_bat_cap; - prev_bat_time = last_bat_time; - last_bat_time = time(NULL); - last_bat_cap = cap; - } - - show_acpi_power_line(rate, cap, prev_bat_cap - cap, time(NULL) - prev_bat_time); - return 1; -} - int print_battery_proc_pmu(void) { char line[80]; @@ -719,9 +630,6 @@ void print_battery_sysfs(void) char filename[256]; - if (print_battery_proc_acpi()) - return; - if (print_battery_proc_pmu()) return; @@ -790,13 +698,17 @@ void print_battery_sysfs(void) watts_left *= strtoull(line, NULL, 10) / 1000000.0; fclose(file); - sprintf(filename, "/sys/class/power_supply/%s/current_now", dirent->d_name); + sprintf(filename, "/sys/class/power_supply/%s/power_now", dirent->d_name); file = fopen(filename, "r"); + if (!file) { + sprintf(filename, "/sys/class/power_supply/%s/current_now", dirent->d_name); + file = fopen(filename, "r"); + } if (!file) continue; memset(line, 0, 1024); if (fgets(line, 1024, file) != NULL) { - watts_drawn = strtoull(line, NULL, 10) / 1000000.0; + watts_drawn = voltage * strtoull(line, NULL, 10) / 1000000.0; } fclose(file);