From db133f2cb617ae1934dabc1246101034fb476767 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 31 Jan 2013 03:52:24 -0300 Subject: [PATCH] ubb-la/gui.c: display time of center (from start of buffer) --- ubb-la/gui.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ubb-la/gui.c b/ubb-la/gui.c index 6702f88..dc6e2a4 100644 --- a/ubb-la/gui.c +++ b/ubb-la/gui.c @@ -74,10 +74,15 @@ #define UNIT_GAP 2 /* space between number and unit */ +#define POS_X 168 +#define POS_Y (MEAS_DIV_Y-8-3) + +#define MEAS_DIV_Y (FREQ_Y-3-1) + #define FREQ_X 0 -#define FREQ_Y 220 +#define FREQ_Y 222 #define INTERVAL_X 0 -#define INTERVAL_Y 230 +#define INTERVAL_Y (FREQ_Y+8+2) #define DIV_SAMP_X (DIV_INT_X-8) #define DIV_SAMP_Y FREQ_Y #define DIV_INT_X 80 @@ -333,7 +338,7 @@ static void show_buffer(const uint8_t *buf, int skip, int nibbles, /* ----- Display the sample frequency -------------------------------------- */ -static void si_text(int x, int y, double v, const char *unit) +static void si_text(int x, int y, double v, const char *unit, int digits) { const char *pfx; @@ -355,11 +360,17 @@ static void si_text(int x, int y, double v, const char *unit) v *= 1e9; pfx = "n"; } - if (v >= 10) + if (v >= 10 && digits == 3) textf(x, y, TEXT_RGBA, "%3d", (int) (v+0.5)); + else if (v >= 100 && digits == 4) + textf(x, y, TEXT_RGBA, "%4d", (int) (v+0.5)); + else if (v >= 100) + textf(x, y, TEXT_RGBA, "%*.*f", digits, digits-4, v); + else if (v >= 10) + textf(x, y, TEXT_RGBA, "%*.*f", digits, digits-3, v); else - textf(x, y, TEXT_RGBA, "%3.1f", v); - textf(x+3*8+UNIT_GAP, y, UNIT_RGBA, "%s%s", pfx, unit); + textf(x, y, TEXT_RGBA, "%*.*f", digits, digits-2, v); + textf(x+digits*8+UNIT_GAP, y, UNIT_RGBA, "%s%s", pfx, unit); } @@ -367,12 +378,12 @@ static void show_freq(double freq, int zoom) { int div; - si_text(FREQ_X, FREQ_Y, freq, "Sa/s"); - si_text(INTERVAL_X, INTERVAL_Y, 1/freq, "s/Sa"); + si_text(FREQ_X, FREQ_Y, freq, "Sa/s", 3); + si_text(INTERVAL_X, INTERVAL_Y, 1/freq, "s/Sa", 3); div = (DIV_X >> MAX_ZOOM) << (MAX_ZOOM-zoom); textf(DIV_SAMP_X, DIV_SAMP_Y, TEXT_RGBA, "%4d", div); textf(DIV_SAMP_X+4*8+UNIT_GAP, DIV_SAMP_Y, UNIT_RGBA, "Sa/div", div); - si_text(DIV_INT_X, DIV_INT_Y, div/freq, "s/div"); + si_text(DIV_INT_X, DIV_INT_Y, div/freq, "s/div", 3); } @@ -421,6 +432,8 @@ void gui(const uint8_t *buf, int skip, int nibbles, double freq) XCENTER+CENTER_W/2, CENTER_Y0, CENTER_RGBA); show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos); show_freq(freq, zoom); + si_text(POS_X, POS_Y, pos/freq, "s", 7); + hlineColor(surf, 0, XRES-1, MEAS_DIV_Y, DIV_RGBA); update(); while (1) {