summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f2af3c2)
raw | patch | inline | side by side (parent: f2af3c2)
author | Florian Forster <octo@collectd.org> | |
Wed, 10 Sep 2014 15:26:16 +0000 (17:26 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 11 Sep 2014 05:19:10 +0000 (07:19 +0200) |
I think the commend in the file sums it up pretty good, read that ;)
src/battery.c | patch | blob | history |
diff --git a/src/battery.c b/src/battery.c
index 1d0757d3796accc53845a6d433188114b30ac7bd..87f20437824d9fb10487b3d45b31493ffa3560ad 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
{
int *battery_index = user_data;
- gauge_t current = NAN;
+ gauge_t power = NAN;
gauge_t voltage = NAN;
gauge_t charge = NAN;
_Bool charging = 0;
+ _Bool is_current = 0;
char const *plugin_instance;
char filename[PATH_MAX];
continue;
}
- /* FIXME: The unit of "present rate" depends on the battery.
- * Modern batteries export watts, not amperes, i.e. it's not a
- * current anymore. We should check if the fourth column
- * contains "mA" and only use a current then. Otherwise, export
- * a power. */
+ /* The unit of "present rate" depends on the battery. Modern
+ * batteries export power (watts), older batteries (used to)
+ * export current (amperes). We check the fourth column and try
+ * to find old batteries this way. */
if ((strcmp (fields[0], "present") == 0)
&& (strcmp (fields[1], "rate:") == 0))
- strtogauge (fields[2], ¤t);
+ {
+ strtogauge (fields[2], &power);
+
+ if ((numfields >= 4) && (strcmp ("mA", fields[3]) == 0))
+ is_current = 1;
+ }
else if ((strcmp (fields[0], "remaining") == 0)
&& (strcmp (fields[1], "capacity:") == 0))
strtogauge (fields[2], &charge);
fclose (fh);
if (!charging)
- current *= -1.0;
+ power *= -1.0;
/* FIXME: This is a dirty hack for backwards compatibility: The battery
* plugin, for a very long time, has had the plugin_instance
(*battery_index)++;
battery_submit (plugin_instance, "charge", charge / 1000.0);
- battery_submit (plugin_instance, "current", current / 1000.0);
+ battery_submit (plugin_instance,
+ is_current ? "current" : "power",
+ power / 1000.0);
battery_submit (plugin_instance, "voltage", voltage / 1000.0);
return 0;