From 27f85e84058ad48f96c74bfc333517b20a3c85f0 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 4 Jul 2020 18:44:13 +0300 Subject: [PATCH] Implement show grid values at right of screen --- chprintf.c | 2 +- nanovna.h | 2 ++ plot.c | 65 ++++++++++++++++++++++-------------------------------- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/chprintf.c b/chprintf.c index 14df9f2..5b3d24e 100644 --- a/chprintf.c +++ b/chprintf.c @@ -34,7 +34,7 @@ // Enable [flags], support: // ' ' Prepends a space for positive signed-numeric types. positive = ' ', negative = '-'. This flag is ignored if the + flag exists. -//#define CHPRINTF_USE_SPACE_FLAG +#define CHPRINTF_USE_SPACE_FLAG // Force putting trailing zeros on float value #define CHPRINTF_FORCE_TRAILING_ZEROS diff --git a/nanovna.h b/nanovna.h index 434cce7..31b6fb0 100644 --- a/nanovna.h +++ b/nanovna.h @@ -304,6 +304,8 @@ extern uint16_t _grid_y; #define AREA_WIDTH_NORMAL (CELLOFFSETX + WIDTH + 1) #define AREA_HEIGHT_NORMAL ( HEIGHT + 1) +#define GRID_X_TEXT (AREA_WIDTH_NORMAL - 25) + // Smith/polar chart #define P_CENTER_X (CELLOFFSETX + WIDTH/2) #define P_CENTER_Y (HEIGHT/2) diff --git a/plot.c b/plot.c index 241f3e1..ec40127 100644 --- a/plot.c +++ b/plot.c @@ -34,10 +34,10 @@ int waterfall = false; int fullscreen = true; #endif static void cell_draw_marker_info(int x0, int y0); +static void cell_grid_line_info(int x0, int y0); static void draw_battery_status(void); static void update_waterfall(void); void cell_draw_test_info(int x0, int y0); -void frequency_string(char *buf, size_t len, int32_t freq); static int16_t grid_offset; static int16_t grid_width; @@ -908,7 +908,6 @@ static void trace_get_value_string( plot_printf(&buf2[1], sizeof(buf2) -1, "%.8qHz" , dfreq); } #endif - // frequency_string(&buf2[1], sizeof(buf2) -1, dfreq); v = value(coeff[i]); if (mtype & M_NOISE) v = v - 10*log10(actual_rbw_x10*100.0); @@ -1503,6 +1502,12 @@ draw_cell(int m, int n) cell_buffer[tp * CELLWIDTH + x] = DEFAULT_TRIGGER_COLOR; } +#if 1 + // Only right cells + if (m >= (GRID_X_TEXT)/CELLWIDTH) + cell_grid_line_info(x0, y0); +#endif + // Draw traces (50-600 system ticks for all screen calls, depend from lines // count and size) #if 1 @@ -1939,6 +1944,25 @@ cell_draw_marker_info(int x0, int y0) extern float temppeakLevel; +static void cell_grid_line_info(int x0, int y0) +{ + char buf[32]; + int xpos = GRID_X_TEXT - x0; + int ypos = 0 - y0 + 2; + ili9341_set_foreground(DEFAULT_GRID_COLOR); + float ref = get_trace_refpos(TRACE_ACTUAL); + float scale = get_trace_scale(TRACE_ACTUAL);; + for (int i = 0; i < NGRIDY; i++){ + if (ypos >= CELLHEIGHT) break; + if (ypos >= -FONT_GET_HEIGHT){ + plot_printf(buf, sizeof buf, "% .2F", ref); + cell_drawstring(buf, xpos, ypos); + } + ypos+=GRIDY; + ref+=scale; + } +} + static void cell_draw_marker_info(int x0, int y0) { char buf[32]; @@ -2050,43 +2074,6 @@ static void cell_draw_marker_info(int x0, int y0) } } } -void frequency_string(char *buf, size_t len, int32_t freq) -{ - if (freq < 0) { - freq = -freq; - *buf++ = '-'; - len -= 1; - } -#ifdef __VNA__ - if (freq < 1000) { - plot_printf(buf, len, "%d Hz", (int)freq); - } else if (freq < 1000000) { - plot_printf(buf, len, "%d.%03d kHz", - (int)(freq / 1000), - (int)(freq % 1000)); - } else { - plot_printf(buf, len, "%d.%03d %03d MHz", - (int)(freq / 1000000), - (int)((freq / 1000) % 1000), - (int)(freq % 1000)); - } -#endif -#ifdef __SA__ -/* - if (freq < 1000) { - plot_printf(buf, len, "%dHz", (int)freq); - } else if (freq < 1000000) { - plot_printf(buf, len, "%d.%03dkHz", - (int)(freq / 1000), - (int)(freq % 1000)); - } else -*/ { - plot_printf(buf, len, "%d.%03", - (int)(freq / 1000000), - (int)((freq / 1000) % 1000)); - } -#endif -} void draw_frequencies(void)