void-packages/srcpkgs/powertop/patches/powertop-1.13-with-3.0.6.patch
2012-04-04 12:52:33 +02:00

138 lines
3.3 KiB
Diff

--- powertop.c.orig 2010-07-20 01:08:21.000000000 +0200
+++ powertop.c 2011-10-20 14:34:41.163951192 +0200
@@ -547,95 +547,6 @@
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 @@
char filename[256];
- if (print_battery_proc_acpi())
- return;
-
if (print_battery_proc_pmu())
return;
@@ -733,7 +641,6 @@
while ((dirent = readdir(dir))) {
int dontcount = 0;
double voltage = 0.0;
- double amperes_drawn = 0.0;
double watts_drawn = 0.0;
double watts_left = 0.0;
char line[1024];
@@ -790,8 +697,12 @@
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);
@@ -801,7 +712,7 @@
fclose(file);
if (!dontcount) {
- rate += watts_drawn + voltage * amperes_drawn;
+ rate += watts_drawn;
}
cap += watts_left;