Skip to content

Commit

Permalink
feat: add marker delta mode
Browse files Browse the repository at this point in the history
  • Loading branch information
edy555 committed Nov 29, 2019
1 parent 852c807 commit a534a89
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 14 deletions.
1 change: 1 addition & 0 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
85 changes: 76 additions & 9 deletions plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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++;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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++ = '-';
Expand All @@ -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");
}
}

Expand Down
21 changes: 16 additions & 5 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
uistat_t uistat = {
digit: 6,
current_trace: 0,
lever_mode: LM_MARKER
lever_mode: LM_MARKER,
marker_delta: FALSE
};


Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a534a89

Please sign in to comment.