]> git.itanic.dy.fi Git - log-plotter/commitdiff
data: Print fancy status line
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Thu, 10 Oct 2013 18:58:53 +0000 (21:58 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Thu, 10 Oct 2013 18:58:53 +0000 (21:58 +0300)
Replace the raw dump of the input data with a better status line. This
has got a human readable values of some relevant data inputs.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
data.c

diff --git a/data.c b/data.c
index 89a1f33f5c1dedc3bdcff2bafa3315277c81b0fb..99e03ae530f515bab0ba26fc90c49513dc56b4a2 100644 (file)
--- a/data.c
+++ b/data.c
@@ -150,6 +150,38 @@ 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 ",
+               time_str, data->charging_voltage, cell_avg);
+
+       fflush(stdout);
+
+}
+
 /**
  * Read data from a slow device
  *
@@ -258,14 +290,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)