1
1
Index: conky-1.4.9/src/linux.c
2
2
===================================================================
3
--- conky-1.4.9.orig/src/linux.c 2008-02-18 08:44:23.000000000 +0530
4
+++ conky-1.4.9/src/linux.c 2008-02-18 08:52:47.000000000 +0530
5
@@ -1257,10 +1257,35 @@
3
--- conky-1.4.9.orig/src/linux.c 2008-02-22 08:21:43.000000000 +0000
4
+++ conky-1.4.9/src/linux.c 2008-02-22 08:26:07.000000000 +0000
5
@@ -1257,10 +1257,36 @@
6
6
2241<@jupet�kellari��> 1.16 1.2 0x03 0x00 0x00 0x01 99% -1 ? monitori p��ll� mutta ilman verkkovirtaa
27
27
+ POWER_SUPPLY_ENERGY_NOW=11810000
28
28
+ POWER_SUPPLY_MODEL_NAME=IBM-92P1060
29
29
+ POWER_SUPPLY_MANUFACTURER=Panasonic
30
+ On some systems POWER_SUPPLY_ENERGY_* is replaced by POWER_SUPPLY_CHARGE_*
32
33
+#define SYSFS_BATTERY_BASE_PATH "/sys/class/power_supply"
38
39
static FILE *acpi_bat_fp[MAX_BATTERY_COUNT];
39
40
static FILE *apm_bat_fp[MAX_BATTERY_COUNT];
42
43
static int idx, rep = 0, rep2 = 0;
43
44
char acpi_path[128];
44
45
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
50
@@ -1322,12 +1349,112 @@
51
@@ -1322,12 +1350,117 @@
51
52
memset (last_battery_str[idx], 0, sizeof (last_battery_str[idx]));
52
53
memset (last_battery_time_str[idx], 0, sizeof (last_battery_time_str[idx]));
54
55
- /* first try ACPI */
55
56
+ /* first try SYSFS if that fails try ACPI */
58
+ if (sysfs_bat_fp[idx] == NULL && acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
59
+ sysfs_bat_fp[idx] = open_file(sysfs_path, &rep);
57
61
- if (acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
58
62
+ if (sysfs_bat_fp[idx] == NULL && acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
59
+ sysfs_bat_fp[idx] = open_file(sysfs_path, &rep);
61
+ if (sysfs_bat_fp[idx] == NULL && acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
62
63
acpi_bat_fp[idx] = open_file(acpi_path, &rep);
64
65
- if (acpi_bat_fp[idx] != NULL) {
69
70
+ char charging_state[64];
72
+ fseek(sysfs_bat_fp[idx], 0, SEEK_SET);
74
73
+ strcpy(charging_state, "Unknown");
76
75
+ while (!feof(sysfs_bat_fp[idx])) {
95
94
+ sscanf(buf, "POWER_SUPPLY_ENERGY_NOW=%d", &remaining_capacity);
96
95
+ else if (strncmp(buf, "POWER_SUPPLY_ENERGY_FULL=", 25) == 0)
97
96
+ sscanf(buf, "POWER_SUPPLY_ENERGY_FULL=%d", &acpi_last_full[idx]);
97
+ else if (strncmp(buf, "POWER_SUPPLY_CHARGE_NOW=", 24) == 0)
98
+ sscanf(buf, "POWER_SUPPLY_CHARGE_NOW=%d", &remaining_capacity);
99
+ else if (strncmp(buf, "POWER_SUPPLY_CHARGE_FULL=", 25) == 0)
100
+ sscanf(buf, "POWER_SUPPLY_CHARGE_FULL=%d", &acpi_last_full[idx]);
103
+ fclose(sysfs_bat_fp[idx]);
104
+ sysfs_bat_fp[idx] = NULL;
100
106
+ /* Hellf[i]re notes that remaining capacity can exceed acpi_last_full */
101
107
+ if (remaining_capacity > acpi_last_full[idx])
102
108
+ acpi_last_full[idx] = remaining_capacity; /* normalize to 100% */
173
179
init_batteries();
175
@@ -1502,13 +1631,32 @@
181
@@ -1502,13 +1637,38 @@
177
183
last_battery_perct_time[idx] = current_update_time;
179
185
- /* Only check for ACPI */
180
186
+ /* Only check for SYSFS or ACPI */
188
- if (acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
189
+ if (sysfs_bat_fp[idx] == NULL && acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
190
+ sysfs_bat_fp[idx] = open_file(sysfs_path, &rep);
182
192
+ if (sysfs_bat_fp[idx] == NULL && acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
183
+ sysfs_bat_fp[idx] = open_file(sysfs_path, &rep);
185
- if (acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
186
+ if (sysfs_bat_fp[idx] == NULL && acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
187
193
acpi_bat_fp[idx] = open_file(acpi_path, &rep);
189
195
int remaining_capacity = -1;
192
198
+ if (sysfs_bat_fp[idx] != NULL) {
194
+ fseek(sysfs_bat_fp[idx], 0, SEEK_SET);
196
200
+ while (!feof(sysfs_bat_fp[idx])) {
198
202
+ if (fgets(buf, 256, sysfs_bat_fp[idx]) == NULL)
201
+ if (strncmp(buf, "POWER_SUPPLY_ENERGY_NOW=", 24) == 0)
205
+ if (strncmp(buf, "POWER_SUPPLY_CHARGE_NOW=", 24) == 0)
206
+ sscanf(buf, "POWER_SUPPLY_CHARGE_NOW=%d", &remaining_capacity);
207
+ else if (strncmp(buf, "POWER_SUPPLY_CHARGE_FULL=",25) != 0)
208
+ sscanf(buf, "POWER_SUPPLY_CHARGE_FULL=%d", &acpi_last_full[idx]);
209
+ else if (strncmp(buf, "POWER_SUPPLY_ENERGY_NOW=", 24) == 0)
202
210
+ sscanf(buf, "POWER_SUPPLY_ENERGY_NOW=%d", &remaining_capacity);
203
211
+ else if (strncmp(buf, "POWER_SUPPLY_ENERGY_FULL=",25) != 0)
204
212
+ sscanf(buf, "POWER_SUPPLY_ENERGY_FULL=%d", &acpi_last_full[idx]);
215
+ fclose(sysfs_bat_fp[idx]);
216
+ sysfs_bat_fp[idx] = NULL;
206
218
+ } else if (acpi_bat_fp[idx] != NULL) {
208
220
/* read last full capacity if it's zero */