From: Timo Kokkonen Date: Thu, 10 Oct 2013 18:58:53 +0000 (+0300) Subject: data: Print fancy status line X-Git-Url: http://git.itanic.dy.fi/?p=log-plotter;a=commitdiff_plain;h=b004f9db9559d948603d5cc2316270aa04a71c9d data: Print fancy status line 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 --- diff --git a/data.c b/data.c index 89a1f33..99e03ae 100644 --- 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)