From a534a89c89b7ba35d32917f422d057ef0f33c0b4 Mon Sep 17 00:00:00 2001 From: TT Date: Fri, 29 Nov 2019 21:53:07 +0900 Subject: [PATCH] feat: add marker delta mode --- nanovna.h | 1 + plot.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++------ ui.c | 21 ++++++++++---- 3 files changed, 93 insertions(+), 14 deletions(-) diff --git a/nanovna.h b/nanovna.h index ef293f90..ae02d977 100644 --- a/nanovna.h +++ b/nanovna.h @@ -357,6 +357,7 @@ typedef struct { uint32_t value; // for editing at numeric input area uint32_t previous_value; uint8_t lever_mode; + bool marker_delta; } uistat_t; extern uistat_t uistat; diff --git a/plot.c b/plot.c index 7aedf781..4996616c 100644 --- a/plot.c +++ b/plot.c @@ -9,7 +9,7 @@ static void cell_draw_marker_info(int m, int n, int w, int h); void frequency_string(char *buf, size_t len, int32_t freq); -void frequency_string_short(char *buf, size_t len, int32_t freq); +void frequency_string_short(char *buf, size_t len, int32_t freq, char prefix); void markmap_all_markers(void); //#define GRID_COLOR 0x0863 @@ -716,6 +716,58 @@ trace_get_value_string(int t, char *buf, int len, float array[101][2], int i) } } +static void +trace_get_value_string_delta(int t, char *buf, int len, float array[101][2], int index, int index_ref) +{ + float *coeff = array[index]; + float *coeff_ref = array[index_ref]; + float v; + switch (trace[t].type) { + case TRC_LOGMAG: + v = logmag(coeff) - logmag(coeff_ref); + if (v == -INFINITY) + chsnprintf(buf, len, "\004-INF dB"); + else + chsnprintf(buf, len, "\004%.2fdB", v); + break; + case TRC_PHASE: + v = phase(coeff) - phase(coeff_ref); + chsnprintf(buf, len, "\004%.2f" S_DEGREE, v); + break; + case TRC_DELAY: + v = groupdelay_from_array(index, array) - groupdelay_from_array(index_ref, array); + string_value_with_prefix(buf, len, v, 's'); + break; + case TRC_LINEAR: + v = linear(coeff) - linear(coeff_ref); + chsnprintf(buf, len, "\004%.2f", v); + break; + case TRC_SWR: + v = swr(coeff) - swr(coeff_ref); + chsnprintf(buf, len, "\004%.2f", v); + break; + case TRC_SMITH: + gamma2imp(buf, len, coeff, frequencies[index]); + break; + case TRC_REAL: + chsnprintf(buf, len, "\004%.2f", coeff[0] - coeff_ref[0]); + break; + case TRC_IMAG: + chsnprintf(buf, len, "\004%.2fj", coeff[1] - coeff_ref[1]); + break; + case TRC_R: + gamma2resistance(buf, len, coeff); + break; + case TRC_X: + gamma2reactance(buf, len, coeff); + break; + //case TRC_ADMIT: + case TRC_POLAR: + chsnprintf(buf, len, "%.2f %.2fj", coeff[0], coeff[1]); + break; + } +} + void trace_get_info(int t, char *buf, int len) { @@ -1509,10 +1561,19 @@ cell_draw_marker_info(int m, int n, int w, int h) cell_drawstring_invert_5x7(w, h, buf, xpos, ypos, config.trace_color[t], mk == active_marker); xpos += 20; //trace_get_info(t, buf, sizeof buf); - frequency_string_short(buf, sizeof buf, frequencies[markers[mk].index]); + int32_t freq = frequencies[markers[mk].index]; + if (uistat.marker_delta && mk != active_marker) { + freq -= frequencies[markers[active_marker].index]; + frequency_string_short(buf, sizeof buf, freq, '\004'); + } else { + frequency_string_short(buf, sizeof buf, freq, 0); + } cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]); xpos += 64; - trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index); + if (uistat.marker_delta && mk != active_marker) + trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index); + else + trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index); cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]); j++; } @@ -1526,7 +1587,7 @@ cell_draw_marker_info(int m, int n, int w, int h) ypos -= n * CELLHEIGHT; strcpy(buf, "CH0"); buf[2] += t; - chsnprintf(buf, sizeof buf, "CH%d", trace[t].channel); + //chsnprintf(buf, sizeof buf, "CH%d", trace[t].channel); cell_drawstring_invert_5x7(w, h, buf, xpos, ypos, config.trace_color[t], t == uistat.current_trace); xpos += 20; trace_get_info(t, buf, sizeof buf); @@ -1579,7 +1640,7 @@ cell_draw_marker_info(int m, int n, int w, int h) xpos = 192; xpos -= m * CELLWIDTH -CELLOFFSETX; ypos += 7; - chsnprintf(buf, sizeof buf, "\001%d:", previous_marker+1); + chsnprintf(buf, sizeof buf, "\004%d:", previous_marker+1); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); xpos += 19; if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { @@ -1618,8 +1679,13 @@ frequency_string(char *buf, size_t len, int32_t freq) } void -frequency_string_short(char *buf, size_t len, int32_t freq) +frequency_string_short(char *b, size_t len, int32_t freq, char prefix) { + char *buf = b; + if (prefix) { + *buf++ = prefix; + len -= 1; + } if (freq < 0) { freq = -freq; *buf++ = '-'; @@ -1628,13 +1694,14 @@ frequency_string_short(char *buf, size_t len, int32_t freq) if (freq < 1000) { chsnprintf(buf, len, "%d Hz", (int)freq); } else if (freq < 1000000) { - chsnprintf(buf, len, "%d.%03d kHz", + chsnprintf(buf, len, "%d.%03dkHz", (int)(freq / 1000), (int)(freq % 1000)); } else { - chsnprintf(buf, len, "%d.%04d MHz", + chsnprintf(buf, len, "%d.%06d", (int)(freq / 1000000), - (int)((freq / 100) % 10000)); + (int)(freq % 1000000)); + strcpy(b+9, "MHz"); } } diff --git a/ui.c b/ui.c index 030a2b3c..247d73f4 100644 --- a/ui.c +++ b/ui.c @@ -29,7 +29,8 @@ uistat_t uistat = { digit: 6, current_trace: 0, - lever_mode: LM_MARKER + lever_mode: LM_MARKER, + marker_delta: FALSE }; @@ -923,6 +924,8 @@ menu_marker_sel_cb(int item) markers[3].enabled = FALSE; previous_marker = -1; active_marker = -1; + } else if (item == 5) { /* marker delta */ + uistat.marker_delta = !uistat.marker_delta; } redraw_marker(active_marker, TRUE); draw_menu(); @@ -1054,6 +1057,7 @@ const menuitem_t menu_marker_sel[] = { { MT_CALLBACK, "MARKER 3", menu_marker_sel_cb }, { MT_CALLBACK, "MARKER 4", menu_marker_sel_cb }, { MT_CALLBACK, "ALL OFF", menu_marker_sel_cb }, + { MT_CALLBACK, "DELTA", menu_marker_sel_cb }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -1385,10 +1389,17 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, if (menu == menu_trace && item < 4) { if (trace[item].enabled) *bg = config.trace_color[item]; - } else if (menu == menu_marker_sel && item < 4) { - if (markers[item].enabled) { - *bg = 0x0000; - *fg = 0xffff; + } else if (menu == menu_marker_sel) { + if (item < 4) { + if (markers[item].enabled) { + *bg = 0x0000; + *fg = 0xffff; + } + } else if (item == 5) { + if (uistat.marker_delta) { + *bg = 0x0000; + *fg = 0xffff; + } } } else if (menu == menu_calop) { if ((item == 0 && (cal_status & CALSTAT_OPEN))