1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-12 19:06:36 +00:00

Added sysfs AC adapter support patch (thanks Byron); Small compilation error fix

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1196 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2008-06-28 19:17:49 +00:00
parent 7f09a767f0
commit 66079c5585
4 changed files with 57 additions and 19 deletions

View File

@ -32,6 +32,9 @@ Blondak <blondak_nesercz at users dot sourceforge dot net>
Bobby Beckmann <bbeckmann at users dot sourceforge dot net>
Interface IP and Wireless Quality patch
Byron Clark <byron_clark at users dot sourceforge dot net>
sysfs AC adapter support patch
David Carter <boojit at pundo dot com>
CPU usage being reported incorrectly by top

View File

@ -1,5 +1,8 @@
# $Id$
2008-06-28
* Added sysfs AC adapter support patch (thanks Byron)
2008-06-25
* new variables smapi_bat_temp and smapi_bat_power
* improved docs for freq_dyn* variables

View File

@ -2,8 +2,8 @@ dnl $Id$
dnl major, minor and micro version macros.
m4_define([conky_version_major], [1])
m4_define([conky_version_minor], [5])
m4_define([conky_version_micro], [2])
m4_define([conky_version_minor], [6])
m4_define([conky_version_micro], [0])
m4_define([conky_version_tag], [pre]) dnl [] for releases
m4_define([conky_version_revision],[_pre@REVISION@])
m4_define([conky_version],

View File

@ -1314,11 +1314,24 @@ void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
snprintf(p_client_buffer, client_buffer_size, "%s", buf);
}
#define SYSFS_AC_ADAPTER_DIR "/sys/class/power_supply/AC"
#define ACPI_AC_ADAPTER_DIR "/proc/acpi/ac_adapter/"
/* Linux 2.6.25 onwards ac adapter info is in
/sys/class/power_supply/AC/
On my system I get the following.
/sys/class/power_supply/AC/uevent:
PHYSDEVPATH=/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:01/PNP0C09:00/ACPI0003:00
PHYSDEVBUS=acpi
PHYSDEVDRIVER=ac
POWER_SUPPLY_NAME=AC
POWER_SUPPLY_TYPE=Mains
POWER_SUPPLY_ONLINE=1
*/
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
{
static int rep = 0;
char buf[256];
char buf2[256];
FILE *fp;
@ -1327,25 +1340,44 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
return;
}
/* yeah, slow... :/ */
if (!get_first_file_in_a_directory(ACPI_AC_ADAPTER_DIR, buf, &rep)) {
snprintf(p_client_buffer, client_buffer_size, "no ac_adapters?");
return;
}
snprintf(buf2, sizeof(buf2), "%s%s/state", ACPI_AC_ADAPTER_DIR, buf);
snprintf(buf2, sizeof(buf2), "%s/uevent", SYSFS_AC_ADAPTER_DIR);
fp = open_file(buf2, &rep);
if (!fp) {
snprintf(p_client_buffer, client_buffer_size,
"No ac adapter found.... where is it?");
return;
}
memset(buf, 0, sizeof(buf));
fscanf(fp, "%*s %99s", buf);
fclose(fp);
if (fp) {
/* sysfs processing */
while (!feof(fp)) {
if (fgets(buf, sizeof(buf), fp) == NULL)
break;
snprintf(p_client_buffer, client_buffer_size, "%s", buf);
if (strncmp(buf, "POWER_SUPPLY_ONLINE=", 20) == 0) {
int online = 0;
sscanf(buf, "POWER_SUPPLY_ONLINE=%d", &online);
snprintf(p_client_buffer, client_buffer_size,
"%s-line", (online ? "on" : "off"));
break;
}
}
fclose(fp);
} else {
/* yeah, slow... :/ */
if (!get_first_file_in_a_directory(ACPI_AC_ADAPTER_DIR, buf, &rep)) {
snprintf(p_client_buffer, client_buffer_size, "no ac_adapters?");
return;
}
snprintf(buf2, sizeof(buf2), "%s%s/state", ACPI_AC_ADAPTER_DIR, buf);
fp = open_file(buf2, &rep);
if (!fp) {
snprintf(p_client_buffer, client_buffer_size,
"No ac adapter found.... where is it?");
return;
}
memset(buf, 0, sizeof(buf));
fscanf(fp, "%*s %99s", buf);
fclose(fp);
snprintf(p_client_buffer, client_buffer_size, "%s", buf);
}
}
/*