return 0;
} /* }}} int read_sysfs_capacity */
+static int read_sysfs_capacity_from_charge(char const *dir, /* {{{ */
+ char const *power_supply,
+ char const *plugin_instance) {
+ gauge_t capacity_charged = NAN;
+ gauge_t capacity_full = NAN;
+ gauge_t capacity_design = NAN;
+ gauge_t voltage_min_design = NAN;
+ int status;
+
+ status =
+ sysfs_file_to_gauge(dir, power_supply, "voltage_min_design", &voltage_min_design);
+ if (status != 0)
+ return status;
+ voltage_min_design *= SYSFS_FACTOR;
+
+ status =
+ sysfs_file_to_gauge(dir, power_supply, "charge_now", &capacity_charged);
+ if (status != 0)
+ return status;
+ capacity_charged *= voltage_min_design;
+
+ status =
+ sysfs_file_to_gauge(dir, power_supply, "charge_full", &capacity_full);
+ if (status != 0)
+ return status;
+ capacity_full *= voltage_min_design;
+
+ status = sysfs_file_to_gauge(dir, power_supply, "charge_full_design",
+ &capacity_design);
+ if (status != 0)
+ return status;
+ capacity_design *= voltage_min_design;
+
+ submit_capacity(plugin_instance, capacity_charged * SYSFS_FACTOR,
+ capacity_full * SYSFS_FACTOR, capacity_design * SYSFS_FACTOR);
+ return 0;
+} /* }}} int read_sysfs_capacity_from_charge */
+
+
static int read_sysfs_callback(char const *dir, /* {{{ */
char const *power_supply, void *user_data) {
int *battery_index = user_data;
plugin_instance = (*battery_index == 0) ? "0" : power_supply;
(*battery_index)++;
- read_sysfs_capacity(dir, power_supply, plugin_instance);
+ if (sysfs_file_to_gauge(dir, power_supply, "energy_now", &v) == 0)
+ read_sysfs_capacity(dir, power_supply, plugin_instance);
+ else
+ read_sysfs_capacity_from_charge(dir, power_supply, plugin_instance);
if (sysfs_file_to_gauge(dir, power_supply, "power_now", &v) == 0) {
if (discharging)