From 3eb8125086f80fcd5c4f0bd1add067d8fab300ea Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 29 Oct 2016 03:11:13 +0900 Subject: [PATCH] add marker command --- main.c | 41 ++++++++++++++++++++++++++++++++++++++++- nanovna.h | 8 ++++++++ plot.c | 15 +++++++-------- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 6c45959..3d722df 100644 --- a/main.c +++ b/main.c @@ -774,7 +774,6 @@ const char *trc_channel_name[] = { static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[]) { int t; - (void)chp; if (argc == 0) { for (t = 0; t < 4; t++) { if (trace[t].enabled) { @@ -842,6 +841,45 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[]) chprintf(chp, "trace [n] [logmag|phase|smith|swr] [src]\r\n"); } +static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[]) +{ + int t; + if (argc == 0) { + for (t = 0; t < 4; t++) { + if (markers[t].enabled) { + chprintf(chp, "%d %d\r\n", t+1, markers[t].index); + } + } + return; + } + t = atoi(argv[0])-1; + if (t < 0 || t >= 4) + goto usage; + if (argc == 1) { + chprintf(chp, "%d %d\r\n", t+1, markers[t].index); + return; + } + if (argc > 1) { + if (strcmp(argv[1], "off") == 0) { + markers[t].enabled = FALSE; + if (active_marker == t) + active_marker = -1; + } else if (strcmp(argv[1], "on") == 0) { + markers[t].enabled = TRUE; + active_marker = t; + } else { + markers[t].enabled = TRUE; + int index = atoi(argv[1]); + markers[t].index = index; + active_marker = t; + } + } + return; + usage: + chprintf(chp, "marker [n] [off|{index}]\r\n"); +} + + static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { int i; @@ -970,6 +1008,7 @@ static const ShellCommand commands[] = { "save", cmd_save }, { "recall", cmd_recall }, { "trace", cmd_trace }, + { "marker", cmd_marker }, { NULL, NULL } }; diff --git a/nanovna.h b/nanovna.h index c8bbc55..4fb999e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -82,6 +82,14 @@ extern float measured[2][101][2]; void trace_get_info(int t, char *buf, int len); +typedef struct { + int enabled; + //uint32_t frequency; + int index; +} marker_t; + +extern marker_t markers[4]; +extern int active_marker; #define CAL_LOAD 0 #define CAL_OPEN 1 diff --git a/plot.c b/plot.c index e6b8092..b7eb858 100644 --- a/plot.c +++ b/plot.c @@ -595,12 +595,6 @@ draw_marker(int w, int h, int x, int y, int c, int ch) } } -typedef struct { - int enabled; - //uint32_t frequency; - int index; -} marker_t; - marker_t markers[4] = { { 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 } }; @@ -623,7 +617,7 @@ cell_draw_markers(int m, int n, int w, int h) int x = CELL_X(index) - x0; int y = CELL_Y(index) - y0; if (x > -6 && x < w+6 && y >= 0 && y < h+12) - draw_marker(w, h, x, y, trace[t].color, '1'); + draw_marker(w, h, x, y, trace[t].color, '1' + i); } } } @@ -768,6 +762,8 @@ cell_draw_marker_info(int m, int n, int w, int h) { char buf[24]; int t; + if (active_marker < 0) + return; if (n != 0 || m > 8) return; int idx = markers[active_marker].index; @@ -787,10 +783,13 @@ cell_draw_marker_info(int m, int n, int w, int h) cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color); j++; } - int xpos = 208; + int xpos = 192; int ypos = 1 + (j/2)*7; xpos -= m * w; ypos -= n * h; + chsnprintf(buf, sizeof buf, "%d:", active_marker + 1); + cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); + xpos += 16; frequency_string(buf, sizeof buf, frequencies[idx]); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); #else