-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_unk, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) {
- time_t empty_time;
- struct tm *empty_tm;
+static void add_battery_info(struct battery_info *acc, const struct battery_info *batt_info) {
+ if (acc->remaining < 0) {
+ /* initialize accumulator so we can add to it */
+ acc->full_design = 0;
+ acc->full_last = 0;
+ acc->remaining = 0;
+ acc->present_rate = 0;
+ }
+
+ acc->full_design += batt_info->full_design;
+ acc->full_last += batt_info->full_last;
+ acc->remaining += batt_info->remaining;
+
+ /* make present_rate negative for discharging and positive for charging */
+ int present_rate = (acc->status == CS_DISCHARGING ? -1 : 1) * acc->present_rate;
+ present_rate += (batt_info->status == CS_DISCHARGING ? -1 : 1) * batt_info->present_rate;
+
+ /* merge status */
+ switch (acc->status) {
+ case CS_UNKNOWN:
+ acc->status = batt_info->status;
+ break;
+
+ case CS_DISCHARGING:
+ if (present_rate > 0)
+ acc->status = CS_CHARGING;
+ /* else if batt_info is DISCHARGING: no conflict
+ * else if batt_info is CHARGING: present_rate should indicate that
+ * else if batt_info is FULL: but something else is discharging */
+ break;
+
+ case CS_CHARGING:
+ if (present_rate < 0)
+ acc->status = CS_DISCHARGING;
+ /* else if batt_info is DISCHARGING: present_rate should indicate that
+ * else if batt_info is CHARGING: no conflict
+ * else if batt_info is FULL: but something else is charging */
+ break;
+
+ case CS_FULL:
+ if (batt_info->status != CS_UNKNOWN)
+ acc->status = batt_info->status;
+ /* else: retain FULL, since it is more specific than UNKNOWN */
+ break;
+ }
+
+ acc->present_rate = abs(present_rate);
+}
+#endif
+
+static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen, char *buffer, int number, const char *path, const char *format_down) {
+ char *outwalk = buffer;
+
+#if defined(LINUX)