mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
refactor: introduce trace_info
This commit is contained in:
parent
f2ab569e5a
commit
3e841920fb
57
main.c
57
main.c
|
|
@ -493,10 +493,10 @@ properties_t current_props = {
|
|||
/* electrical_delay */ 0,
|
||||
/* trace[4] */
|
||||
{/*enable, type, channel, polar, scale, refpos*/
|
||||
{ 1, TRC_LOGMAG, 0, 0, 10, 7.0 },
|
||||
{ 1, TRC_LOGMAG, 1, 0, 10, 7.0 },
|
||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
||||
{ 1, TRC_LOGMAG, 1, 0, 1.0, 7.0 },
|
||||
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
|
||||
{ 1, TRC_PHASE, 1, 0, 90, 4.0 }
|
||||
{ 1, TRC_PHASE, 1, 0, 1.0, 4.0 }
|
||||
},
|
||||
/* markers[4] */ {
|
||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||
|
|
@ -1271,27 +1271,34 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
chprintf(chp, "recall {id}\r\n");
|
||||
}
|
||||
|
||||
|
||||
const char *trc_type_name[] = {
|
||||
"LOGMAG", "PHASE", "DELAY",
|
||||
"SMITH", "POLAR", "LINEAR", "SWR",
|
||||
"REAL", "IMAG", "R", "X"
|
||||
};
|
||||
const uint8_t default_refpos[] = {
|
||||
7, 4, 4,
|
||||
0, 0, 0, 0,
|
||||
4, 4, 0, 4
|
||||
};
|
||||
const float default_scale[] = {
|
||||
10, 90, 1,
|
||||
0, 0, 0.125, 1,
|
||||
0.25, 0.25, 100, 100
|
||||
const struct {
|
||||
const char *name;
|
||||
uint16_t refpos;
|
||||
float scale_unit;
|
||||
} trace_info[] = {
|
||||
{ "LOGMAG", 7, 10 },
|
||||
{ "PHASE", 4, 90 },
|
||||
{ "DELAY", 4, 1 },
|
||||
{ "SMITH", 0, 1 },
|
||||
{ "POLAR", 0, 1 },
|
||||
{ "LINEAR", 0, 0.125 },
|
||||
{ "SWR", 0, 1 },
|
||||
{ "REAL", 4, 0.25 },
|
||||
{ "IMAG", 4, 0.25 },
|
||||
{ "R", 0, 100 },
|
||||
{ "X", 4, 100 }
|
||||
};
|
||||
|
||||
const char *trc_channel_name[] = {
|
||||
"CH0", "CH1"
|
||||
};
|
||||
|
||||
const char *
|
||||
get_trace_typename(int t)
|
||||
{
|
||||
return trace_info[trace[t].type].name;
|
||||
}
|
||||
|
||||
void set_trace_type(int t, int type)
|
||||
{
|
||||
int polar = type == TRC_SMITH || type == TRC_POLAR;
|
||||
|
|
@ -1308,8 +1315,7 @@ void set_trace_type(int t, int type)
|
|||
}
|
||||
if (trace[t].type != type) {
|
||||
trace[t].type = type;
|
||||
trace[t].refpos = default_refpos[type];
|
||||
trace[t].scale = default_scale[type];
|
||||
trace[t].refpos = trace_info[type].refpos;
|
||||
if (polar)
|
||||
force = TRUE;
|
||||
}
|
||||
|
|
@ -1329,6 +1335,7 @@ void set_trace_channel(int t, int channel)
|
|||
|
||||
void set_trace_scale(int t, float scale)
|
||||
{
|
||||
scale /= trace_info[trace[t].type].scale_unit;
|
||||
if (trace[t].scale != scale) {
|
||||
trace[t].scale = scale;
|
||||
force_set_markmap();
|
||||
|
|
@ -1337,7 +1344,7 @@ void set_trace_scale(int t, float scale)
|
|||
|
||||
float get_trace_scale(int t)
|
||||
{
|
||||
return trace[t].scale;
|
||||
return trace[t].scale * trace_info[trace[t].type].scale_unit;
|
||||
}
|
||||
|
||||
void set_trace_refpos(int t, float refpos)
|
||||
|
|
@ -1396,10 +1403,10 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
if (argc == 0) {
|
||||
for (t = 0; t < 4; t++) {
|
||||
if (trace[t].enabled) {
|
||||
const char *type = trc_type_name[trace[t].type];
|
||||
const char *type = trace_info[trace[t].type].name;
|
||||
const char *channel = trc_channel_name[trace[t].channel];
|
||||
float scale = trace[t].scale;
|
||||
float refpos = trace[t].refpos;
|
||||
float scale = get_trace_scale(t);
|
||||
float refpos = get_trace_refpos(t);
|
||||
chprintf(chp, "%d %s %s %f %f\r\n", t, type, channel, scale, refpos);
|
||||
}
|
||||
}
|
||||
|
|
@ -1419,7 +1426,7 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
if (t < 0 || t >= 4)
|
||||
goto usage;
|
||||
if (argc == 1) {
|
||||
const char *type = trc_type_name[trace[t].type];
|
||||
const char *type = get_trace_typename(t);
|
||||
const char *channel = trc_channel_name[trace[t].channel];
|
||||
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -152,8 +152,6 @@ enum {
|
|||
TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
|
||||
};
|
||||
|
||||
extern const char *trc_type_name[];
|
||||
|
||||
// LOGMAG: SCALE, REFPOS, REFVAL
|
||||
// PHASE: SCALE, REFPOS, REFVAL
|
||||
// DELAY: SCALE, REFPOS, REFVAL
|
||||
|
|
@ -195,6 +193,7 @@ void set_trace_scale(int t, float scale);
|
|||
void set_trace_refpos(int t, float refpos);
|
||||
float get_trace_scale(int t);
|
||||
float get_trace_refpos(int t);
|
||||
const char *get_trace_typename(int t);
|
||||
|
||||
void set_electrical_delay(float picoseconds);
|
||||
float get_electrical_delay(void);
|
||||
|
|
|
|||
20
plot.c
20
plot.c
|
|
@ -494,8 +494,8 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
|||
{
|
||||
int y = 0;
|
||||
float v = 0;
|
||||
float refpos = 8 - trace[t].refpos;
|
||||
float scale = 1 / trace[t].scale;
|
||||
float refpos = 8 - get_trace_refpos(t);
|
||||
float scale = 1 / get_trace_scale(t);
|
||||
switch (trace[t].type) {
|
||||
case TRC_LOGMAG:
|
||||
v = refpos - logmag(coeff) * scale;
|
||||
|
|
@ -510,10 +510,10 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
|||
v = refpos+ (1 - swr(coeff)) * scale;
|
||||
break;
|
||||
case TRC_REAL:
|
||||
v = refpos - coeff[0] * 8 * scale;
|
||||
v = refpos - coeff[0] * scale;
|
||||
break;
|
||||
case TRC_IMAG:
|
||||
v = refpos - coeff[1] * 8 * scale;
|
||||
v = refpos - coeff[1] * scale;
|
||||
break;
|
||||
case TRC_R:
|
||||
v = refpos - resitance(coeff) * scale;
|
||||
|
|
@ -680,21 +680,21 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequ
|
|||
void
|
||||
trace_get_info(int t, char *buf, int len)
|
||||
{
|
||||
const char *type = trc_type_name[trace[t].type];
|
||||
const char *type = get_trace_typename(t);
|
||||
switch (trace[t].type) {
|
||||
case TRC_LOGMAG:
|
||||
chsnprintf(buf, len, "%s %ddB/", type, (int)(trace[t].scale));
|
||||
chsnprintf(buf, len, "%s %ddB/", type, (int)get_trace_scale(t));
|
||||
break;
|
||||
case TRC_PHASE:
|
||||
chsnprintf(buf, len, "%s %d" S_DEGREE "/", type, (int)(trace[t].scale));
|
||||
chsnprintf(buf, len, "%s %d" S_DEGREE "/", type, (int)get_trace_scale(t));
|
||||
break;
|
||||
case TRC_SMITH:
|
||||
//case TRC_ADMIT:
|
||||
case TRC_POLAR:
|
||||
chsnprintf(buf, len, "%s %.1fFS", type, trace[t].scale);
|
||||
chsnprintf(buf, len, "%s %.1fFS", type, get_trace_scale(t));
|
||||
break;
|
||||
default:
|
||||
chsnprintf(buf, len, "%s %.1f/", type, trace[t].scale);
|
||||
chsnprintf(buf, len, "%s %.1f/", type, get_trace_scale(t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -962,7 +962,7 @@ cell_draw_refpos(int m, int n, int w, int h)
|
|||
if (trace[t].type == TRC_SMITH || trace[t].type == TRC_POLAR)
|
||||
continue;
|
||||
int x = 0 - x0 +CELLOFFSETX;
|
||||
int y = 8*GRIDY - (int)(trace[t].refpos * GRIDY) - y0;
|
||||
int y = 8*GRIDY - (int)(get_trace_refpos(t) * GRIDY) - y0;
|
||||
if (x > -5 && x < w && y >= -3 && y < h+3)
|
||||
draw_refpos(w, h, x, y, config.trace_color[t]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue