Added sysfs AC adapter support patch (thanks Byron); Small compilation error fix
authorBrenden Matthews <brenden1@rty.ca>
Sat, 28 Jun 2008 19:17:49 +0000 (19:17 +0000)
committerBrenden Matthews <brenden1@rty.ca>
Sat, 28 Jun 2008 19:17:49 +0000 (19:17 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1196 7f574dfc-610e-0410-a909-a81674777703

AUTHORS
ChangeLog
configure.ac.in
src/linux.c

diff --git a/AUTHORS b/AUTHORS
index f96e6ef..d416b16 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -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
 
index 48eba50..93a764c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index c7ea864..8da346f 100644 (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],
index 8652484..7f270d9 100644 (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/uevent", SYSFS_AC_ADAPTER_DIR);
+       fp = open_file(buf2, &rep);
+       if (fp) {
+               /* sysfs processing */
+               while (!feof(fp)) {
+                       if (fgets(buf, sizeof(buf), fp) == NULL)
+                               break;
 
-       snprintf(buf2, sizeof(buf2), "%s%s/state", ACPI_AC_ADAPTER_DIR, 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;
+               }
 
-       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(buf2, sizeof(buf2), "%s%s/state", ACPI_AC_ADAPTER_DIR, buf);
 
-       snprintf(p_client_buffer, client_buffer_size, "%s", 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);
+       }
 }
 
 /*