[Goodies-commits] r5949 - xfce4-sensors-plugin/trunk/lib
Fabian Nowak
timystery at xfce.org
Tue Nov 4 01:10:14 CET 2008
Author: timystery
Date: 2008-11-04 00:10:14 +0000 (Tue, 04 Nov 2008)
New Revision: 5949
Modified:
xfce4-sensors-plugin/trunk/lib/acpi.c
Log:
extended acpi-reading by support for sys/class
Modified: xfce4-sensors-plugin/trunk/lib/acpi.c
===================================================================
--- xfce4-sensors-plugin/trunk/lib/acpi.c 2008-11-03 23:59:30 UTC (rev 5948)
+++ xfce4-sensors-plugin/trunk/lib/acpi.c 2008-11-04 00:10:14 UTC (rev 5949)
@@ -216,7 +216,11 @@
{
DIR *d;
FILE *file;
- char *filename, *tmp, buf[1024];
+ char *filename;
+#ifndef HAVE_SYSFS_ACPI
+ char *tmp;
+#endif
+ char buf[1024];
struct dirent *de;
t_chipfeature *chipfeature;
@@ -234,22 +238,57 @@
if (strncmp(de->d_name, "BAT", 3)==0)
{ /* have a battery subdirectory */
+#ifdef HAVE_SYSFS_ACPI
+ filename = g_strdup_printf ("/sys/class/power_supply/%s/model_name", de->d_name);
+#else
filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH,
ACPI_DIR_BATTERY, de->d_name,
ACPI_FILE_BATTERY_STATE);
+#endif
DBG ("filename=%s\n", filename);
file = fopen (filename, "r");
if (file) {
chipfeature = g_new0 (t_chipfeature, 1);
chipfeature->address = chip->chip_features->len;
chipfeature->devicename = g_strdup (de->d_name);
+
+#ifdef HAVE_SYSFS_ACPI
+ if (fgets (buf, 1024, file)!=NULL)
+ {
+ chipfeature->name = g_strdup (buf);
+ }
+#else
chipfeature->name = g_strdup (chipfeature->devicename);
+#endif
+
chipfeature->valid = TRUE;
chipfeature->min_value = 0.0;
chipfeature->raw_value = 0.0;
chipfeature->class = ENERGY;
chipfeature->formatted_value = NULL;
chipfeature->color = g_strdup("#0000B0");
+
+#ifdef HAVE_SYSFS_ACPI
+ fclose (file);
+ }
+ file = fopen (filename, "r");
+ if (file) {
+ filename = g_strdup_printf ("/sys/class/power_supply/%s/energy_now", de->d_name);
+
+ if (fgets (buf, 1024, file)!=NULL)
+ {
+ chipfeature->raw_value = strtod (buf, NULL);
+ }
+ fclose (file);
+ }
+ file = fopen (filename, "r");
+ if (file) {
+ filename = g_strdup_printf ("/sys/class/power_supply/%s/alarm", de->d_name);
+ if (fgets (buf, 1024, file)!=NULL)
+ {
+ chipfeature->min_value = strtod (buf, NULL);
+ }
+#else
while (fgets (buf, 1024, file)!=NULL)
{
if (strncmp (buf, "design capacity low:", 20)==0)
@@ -263,6 +302,8 @@
chipfeature->raw_value = strtod (tmp, NULL);
}
}
+#endif
+
/* g_free (tmp); */ /* points to inside of the buffer */
fclose (file);
More information about the Goodies-commits
mailing list