Implemented better loop-timing using `nanosleep(2)'.
[collectd.git] / src / battery.c
index 123a05a..201280c 100644 (file)
@@ -41,27 +41,29 @@ static char *battery_charge_file  = "battery-%s/charge.rrd";
 
 static char *ds_def_current[] =
 {
-       "DS:current:GAUGE:25:U:U",
+       "DS:current:GAUGE:"COLLECTD_HEARTBEAT":U:U",
        NULL
 };
 static int ds_num_current = 1;
 
 static char *ds_def_voltage[] =
 {
-       "DS:voltage:GAUGE:25:U:U",
+       "DS:voltage:GAUGE:"COLLECTD_HEARTBEAT":U:U",
        NULL
 };
 static int ds_num_voltage = 1;
 
 static char *ds_def_charge[] =
 {
-       "DS:charge:GAUGE:25:0:U",
+       "DS:charge:GAUGE:"COLLECTD_HEARTBEAT":0:U",
        NULL
 };
 static int ds_num_charge = 1;
 
+#if BATTERY_HAVE_READ
 static int   battery_pmu_num = 0;
 static char *battery_pmu_file = "/proc/pmu/battery_%i";
+#endif
 
 static void battery_init (void)
 {
@@ -256,6 +258,9 @@ static void battery_read (void)
 
                while ((ent = readdir (dh)) != NULL)
                {
+                       if (ent->d_name[0] == '.')
+                               continue;
+
                        len = snprintf (filename, BUFSIZE, "/proc/acpi/battery/%s/state", ent->d_name);
                        if ((len >= BUFSIZE) || (len < 0))
                                continue;
@@ -275,29 +280,29 @@ static void battery_read (void)
                         * [11:00] <@tokkee> remaining capacity:      4136 mAh
                         * [11:00] <@tokkee> present voltage:         12428 mV
                         */
-                       while (fgets (buffer, BUFSIZE, fh) == NULL)
+                       while (fgets (buffer, BUFSIZE, fh) != NULL)
                        {
                                numfields = strsplit (buffer, fields, 8);
 
                                if (numfields < 3)
                                        continue;
 
-                               if ((strcmp (fields[0], "present"))
-                                               && (strcmp (fields[1], "rate:")))
+                               if ((strcmp (fields[0], "present") == 0)
+                                               && (strcmp (fields[1], "rate:") == 0))
                                        valptr = &current;
-                               else if ((strcmp (fields[0], "remaining"))
-                                               && (strcmp (fields[1], "capacity:")))
+                               else if ((strcmp (fields[0], "remaining") == 0)
+                                               && (strcmp (fields[1], "capacity:") == 0))
                                        valptr = &charge;
-                               else if ((strcmp (fields[0], "present"))
-                                               && (strcmp (fields[1], "voltage:")))
+                               else if ((strcmp (fields[0], "present") == 0)
+                                               && (strcmp (fields[1], "voltage:") == 0))
                                        valptr = &voltage;
                                else
                                        valptr = NULL;
 
-                               if ((strcmp (fields[0], "charging"))
-                                               && (strcmp (fields[1], "state:")))
+                               if ((strcmp (fields[0], "charging") == 0)
+                                               && (strcmp (fields[1], "state:") == 0))
                                {
-                                       if (strcmp (fields[2], "charging"))
+                                       if (strcmp (fields[2], "charging") == 0)
                                                charging = 1;
                                        else
                                                charging = 0;