1 diff -N -r -u powertop-1.98/Makefile powertop-patched/Makefile
2 --- powertop-1.98/Makefile 2011-05-11 06:48:37.000000000 +0200
3 +++ powertop-patched/Makefile 2011-10-20 16:06:37.753900039 +0200
5 OBJS += process/process.o process/do_process.o process/interrupt.o process/timer.o process/work.o process/powerconsumer.o process/device.o
6 DEVS += devices/device.o devices/backlight.o devices/usb.o devices/ahci.o devices/alsa.o devices/rfkill.o devices/i915-gpu.o devices/thinkpad-fan.o devices/network.o devices/thinkpad-light.o
7 DEVS += devices/runtime_pm.o
8 -DEVS += measurement/measurement.o measurement/acpi.o measurement/extech.o
9 +DEVS += measurement/measurement.o measurement/acpi.o measurement/sysfs.o measurement/extech.o
11 OBJS += parameters/parameters.o parameters/learn.o parameters/persistent.o
12 OBJS += calibrate/calibrate.o
13 diff -N -r -u powertop-1.98/measurement/measurement.cpp powertop-patched/measurement/measurement.cpp
14 --- powertop-1.98/measurement/measurement.cpp 2011-05-11 06:48:37.000000000 +0200
15 +++ powertop-patched/measurement/measurement.cpp 2011-10-20 16:00:50.305782326 +0200
18 #include "measurement.h"
22 #include "../parameters/parameters.h"
28 -void power_meters_callback(const char *d_name)
29 +void power_meters_callback_acpi(const char *d_name)
31 class acpi_power_meter *meter;
32 meter = new(std::nothrow) class acpi_power_meter(d_name);
34 power_meters.push_back(meter);
37 +void power_meters_callback_sysfs(const char *d_name)
39 + if (strstr(d_name, "AC") ||
40 + strstr(d_name, ".")) {
44 + class sysfs_power_meter *meter;
45 + meter = new(std::nothrow) class sysfs_power_meter(d_name);
47 + power_meters.push_back(meter);
50 void detect_power_meters(void)
52 - process_directory("/proc/acpi/battery", power_meters_callback);
53 + process_directory("/proc/acpi/battery", power_meters_callback_acpi);
54 + process_directory("/sys/class/power_supply", power_meters_callback_sysfs);
57 void extech_power_meter(const char *devnode)
58 diff -N -r -u powertop-1.98/measurement/sysfs.cpp powertop-patched/measurement/sysfs.cpp
59 --- powertop-1.98/measurement/sysfs.cpp 1970-01-01 01:00:00.000000000 +0100
60 +++ powertop-patched/measurement/sysfs.cpp 2011-10-20 16:19:29.289720272 +0200
63 + * Copyright 2010, Intel Corporation
65 + * This file is part of PowerTOP
67 + * This program file is free software; you can redistribute it and/or modify it
68 + * under the terms of the GNU General Public License as published by the
69 + * Free Software Foundation; version 2 of the License.
71 + * This program is distributed in the hope that it will be useful, but WITHOUT
72 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
73 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
76 + * You should have received a copy of the GNU General Public License
77 + * along with this program in a file named COPYING; if not, write to the
78 + * Free Software Foundation, Inc,
79 + * 51 Franklin Street, Fifth Floor,
80 + * Boston, MA 02110-1301 USA
81 + * or just google for it.
84 + * Lukas Barth <mail@tinloaf.de>
86 +#include "measurement.h"
96 +sysfs_power_meter::sysfs_power_meter(const char *sysfs_name)
101 + strncpy(battery_name, sysfs_name, sizeof(battery_name));
104 +void sysfs_power_meter::measure(void)
106 + char filename[4096];
114 + sprintf(filename, "/sys/class/power_supply/%s/status", battery_name);
116 + file.open(filename, ios::in);
119 + memset(line, 0, 4096);
120 + file.getline(line, 4096);
121 + if (strstr(line, "Discharging") == NULL) {
122 + return; /* not discharging */
126 + sprintf(filename, "/sys/class/power_supply/%s/present", battery_name);
127 + file.open(filename, ios::in);
139 + sprintf(filename, "/sys/class/power_supply/%s/voltage_now", battery_name);
140 + file.open(filename, ios::in);
143 + memset(line, 0, 4096);
144 + file.getline(line, 4096);
145 + voltage = strtoull(line, NULL, 10) / 1000000.0;
148 + sprintf(filename, "/sys/class/power_supply/%s/power_now", battery_name);
149 + file.open(filename, ios::in);
151 + sprintf(filename, "/sys/class/power_supply/%s/current_now", battery_name);
152 + file.open(filename, ios::in);
156 + memset(line, 0, 4096);
157 + file.getline(line, 4096);
158 + rate = strtoull(line, NULL, 10) / 1000000.0;
161 + sprintf(filename, "/sys/class/power_supply/%s/energy_now", battery_name);
162 + file.open(filename, ios::in);
166 + sprintf(filename, "/sys/class/power_supply/%s/charge_now", battery_name);
167 + file.open(filename, ios::in);
172 + capacity = voltage;
174 + memset(line, 0, 4096);
175 + file.getline(line, 4096);
176 + capacity *= strtoull(line, NULL, 10) / 1000000.0;
181 +void sysfs_power_meter::end_measurement(void)
186 +void sysfs_power_meter::start_measurement(void)
188 + /* Sysfs battery state is a lagging indication, lets only measure at the end */
192 +double sysfs_power_meter::joules_consumed(void)
196 diff -N -r -u powertop-1.98/measurement/sysfs.h powertop-patched/measurement/sysfs.h
197 --- powertop-1.98/measurement/sysfs.h 1970-01-01 01:00:00.000000000 +0100
198 +++ powertop-patched/measurement/sysfs.h 2011-10-20 16:18:33.016691795 +0200
201 + * Copyright 2010, Intel Corporation
203 + * This file is part of PowerTOP
205 + * This program file is free software; you can redistribute it and/or modify it
206 + * under the terms of the GNU General Public License as published by the
207 + * Free Software Foundation; version 2 of the License.
209 + * This program is distributed in the hope that it will be useful, but WITHOUT
210 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
211 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
212 + * for more details.
214 + * You should have received a copy of the GNU General Public License
215 + * along with this program in a file named COPYING; if not, write to the
216 + * Free Software Foundation, Inc,
217 + * 51 Franklin Street, Fifth Floor,
218 + * Boston, MA 02110-1301 USA
219 + * or just google for it.
222 + * Lukas Barth <mail@tinloaf.de>
224 +#ifndef __INCLUDE_GUARD_SYSFS_H
225 +#define __INCLUDE_GUARD_SYSFS_H
227 +#include "measurement.h"
229 +class sysfs_power_meter: public power_meter {
230 + char battery_name[256];
235 + void measure(void);
237 + sysfs_power_meter(const char *_battery_name);
238 + virtual void start_measurement(void);
239 + virtual void end_measurement(void);
241 + virtual double joules_consumed(void);
242 + virtual double dev_capacity(void) { return capacity; };