]> git.itanic.dy.fi Git - log-plotter/blobdiff - data.c
Move random utility macros into utils.h
[log-plotter] / data.c
diff --git a/data.c b/data.c
index 89a1f33f5c1dedc3bdcff2bafa3315277c81b0fb..fa370729b0c8a242b4efa053cc569a9dcfa4f632 100644 (file)
--- a/data.c
+++ b/data.c
@@ -10,9 +10,9 @@
 #include <math.h>
 
 #include "data.h"
-#include "debug.h"
+#include "trace.h"
+#include "utils.h"
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 static int separate_entries(char *buf, char *entries[], int max_entries)
 {
@@ -150,6 +150,40 @@ static void dump_data(struct charger_data *data)
        pr_debug("ext_temp %.1f\n", data->ext_temp);
 }
 
+static void print_status_line(struct charger_data *data)
+{
+       int i, active_cells = 0;
+       double cell_avg = 0;
+       char time_str[16];
+
+       if (data->timestamp > 3600) {
+               snprintf(time_str, sizeof(time_str), "%d:%02d:%02d",
+                       (int)(data->timestamp / 3600),
+                       (int)((int)data->timestamp % 3600) / 60,
+                       (int)data->timestamp % 60);
+       } else {
+               snprintf(time_str, sizeof(time_str), "%2d:%02d",
+                       ((int)data->timestamp % 3600) / 60,
+                       (int)data->timestamp % 60);
+       }
+
+       for (i = 0; i < MAX_CELLS; i++) {
+               if (!isnan(data->cell_voltage[i])) {
+                       cell_avg += data->cell_voltage[i];
+                       active_cells++;
+               }
+       }
+       cell_avg /= (double)active_cells;
+
+       pr_info("\r\033[K%8s Ubat: %.3fV Ucell avg: %.3fV "
+               "Current: %.2fA Charge %.0fmAh ",
+               time_str, data->charging_voltage, cell_avg,
+               data->charging_current, data->total_charge);
+
+       fflush(stdout);
+
+}
+
 /**
  * Read data from a slow device
  *
@@ -258,14 +292,14 @@ int read_data(int infd, int outfd)
 
                cur_time = time(NULL);
 
-               pr_info("%s\n", buf);
-
                parse_logline(buf, &data);
 
                /* Fill in possibly missing timestamp */
                if (isnan(data.timestamp) || data.timestamp == 0);
                        data.timestamp = cur_time - start_time;
 
+               print_status_line(&data);
+
                dump_data(&data);
 
                if (!outfd)