This commit is contained in:
DiSlord 2020-06-20 12:31:35 +03:00
commit 76223f5e25
4 changed files with 30 additions and 8 deletions

10
main.c
View file

@ -634,7 +634,8 @@ VNA_SHELL_FUNCTION(cmd_dump)
if (argc == 1) if (argc == 1)
dump_selection = my_atoi(argv[0]); dump_selection = my_atoi(argv[0]);
wait_dsp(3); dsp_start(3);
dsp_wait();
len = AUDIO_BUFFER_LEN; len = AUDIO_BUFFER_LEN;
if (dump_selection == 1 || dump_selection == 2) if (dump_selection == 1 || dump_selection == 2)
@ -1670,7 +1671,8 @@ static const struct {
{ "REAL", NGRIDY/2, 0.25 }, { "REAL", NGRIDY/2, 0.25 },
{ "IMAG", NGRIDY/2, 0.25 }, { "IMAG", NGRIDY/2, 0.25 },
{ "R", NGRIDY/2, 100.0 }, { "R", NGRIDY/2, 100.0 },
{ "X", NGRIDY/2, 100.0 } { "X", NGRIDY/2, 100.0 },
{ "Q", 0, 10.0 }
}; };
static const char * const trc_channel_name[] = { static const char * const trc_channel_name[] = {
@ -1774,8 +1776,8 @@ VNA_SHELL_FUNCTION(cmd_trace)
#if MAX_TRACE_TYPE != 12 #if MAX_TRACE_TYPE != 12
#error "Trace type enum possibly changed, check cmd_trace function" #error "Trace type enum possibly changed, check cmd_trace function"
#endif #endif
// 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 // enum TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_Q, TRC_OFF
static const char cmd_type_list[] = "logmag|phase|delay|smith|polar|linear|swr|real|imag|r|x|off"; static const char cmd_type_list[] = "logmag|phase|delay|smith|polar|linear|swr|real|imag|r|x|q|off";
int type = get_str_index(argv[1], cmd_type_list); int type = get_str_index(argv[1], cmd_type_list);
if (type >= 0) { if (type >= 0) {
set_trace_type(t, type); set_trace_type(t, type);

View file

@ -230,10 +230,10 @@ extern const uint16_t numfont16x22[];
// trace // trace
#define MAX_TRACE_TYPE 12 #define MAX_TRACE_TYPE 12
enum trace_type { enum trace_type {
TRC_LOGMAG=0, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF TRC_LOGMAG=0, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_Q, TRC_OFF
}; };
// Mask for define rectangular plot // Mask for define rectangular plot
#define RECTANGULAR_GRID_MASK ((1<<TRC_LOGMAG)|(1<<TRC_PHASE)|(1<<TRC_DELAY)|(1<<TRC_LINEAR)|(1<<TRC_SWR)|(1<<TRC_REAL)|(1<<TRC_IMAG)|(1<<TRC_R)|(1<<TRC_X)) #define RECTANGULAR_GRID_MASK ((1<<TRC_LOGMAG)|(1<<TRC_PHASE)|(1<<TRC_DELAY)|(1<<TRC_LINEAR)|(1<<TRC_SWR)|(1<<TRC_REAL)|(1<<TRC_IMAG)|(1<<TRC_R)|(1<<TRC_X)|(1<<TRC_Q))
// LOGMAG: SCALE, REFPOS, REFVAL // LOGMAG: SCALE, REFPOS, REFVAL
// PHASE: SCALE, REFPOS, REFVAL // PHASE: SCALE, REFPOS, REFVAL

19
plot.c
View file

@ -491,6 +491,14 @@ reactance(const float *v)
return zi; return zi;
} }
static float
qualityfactor(const float *v)
{
float i = 2*v[1];
float r = (1+v[0])*(1-v[0]) - v[1]*v[1];
return fabs(i / r);
}
static void static void
cartesian_scale(float re, float im, int *xp, int *yp, float scale) cartesian_scale(float re, float im, int *xp, int *yp, float scale)
{ {
@ -551,6 +559,9 @@ trace_into_index(int t, int i, float array[POINTS_COUNT][2])
case TRC_X: case TRC_X:
v-= reactance(coeff) * scale; v-= reactance(coeff) * scale;
break; break;
case TRC_Q:
v-= qualityfactor(coeff) * scale;
break;
case TRC_SMITH: case TRC_SMITH:
//case TRC_ADMIT: //case TRC_ADMIT:
case TRC_POLAR: case TRC_POLAR:
@ -653,6 +664,10 @@ trace_get_value_string(int t, char *buf, int len, float array[POINTS_COUNT][2],
format = "%.2F"S_OHM; format = "%.2F"S_OHM;
v = reactance(coeff); v = reactance(coeff);
break; break;
case TRC_Q:
format = "%.1f";
v = qualityfactor(coeff);
break;
case TRC_SMITH: case TRC_SMITH:
format_smith_value(buf, len, coeff, frequencies[i]); format_smith_value(buf, len, coeff, frequencies[i]);
return; return;
@ -713,6 +728,10 @@ trace_get_value_string_delta(int t, char *buf, int len, float array[POINTS_COUNT
format = "%.2F"S_OHM; format = "%.2F"S_OHM;
v = reactance(coeff); v = reactance(coeff);
break; break;
case TRC_Q:
format = "%.1f";
v = qualityfactor(coeff);
break;
//case TRC_ADMIT: //case TRC_ADMIT:
case TRC_POLAR: case TRC_POLAR:
plot_printf(buf, len, "%.2f%+.2fj", coeff[0], coeff[1]); plot_printf(buf, len, "%.2f%+.2fj", coeff[0], coeff[1]);

5
ui.c
View file

@ -908,6 +908,7 @@ const menuitem_t menu_format2[] = {
{ MT_CALLBACK, TRC_IMAG, "IMAG", menu_format_cb }, { MT_CALLBACK, TRC_IMAG, "IMAG", menu_format_cb },
{ MT_CALLBACK, TRC_R, "RESISTANCE", menu_format_cb }, { MT_CALLBACK, TRC_R, "RESISTANCE", menu_format_cb },
{ MT_CALLBACK, TRC_X, "REACTANCE", menu_format_cb }, { MT_CALLBACK, TRC_X, "REACTANCE", menu_format_cb },
{ MT_CALLBACK, TRC_Q, "Q FACTOR", menu_format_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };
@ -1170,7 +1171,7 @@ menu_invoke(int item)
} }
// Maximum menu buttons count // Maximum menu buttons count
#define MENU_BUTTON_MAX 7 #define MENU_BUTTON_MAX 8
// Menu buttons size // Menu buttons size
#define MENU_BUTTON_WIDTH 60 #define MENU_BUTTON_WIDTH 60
#define MENU_BUTTON_HEIGHT 30 #define MENU_BUTTON_HEIGHT 30
@ -1540,8 +1541,8 @@ leave_ui_mode()
} else if (ui_mode == UI_NUMERIC) { } else if (ui_mode == UI_NUMERIC) {
request_to_draw_cells_behind_numeric_input(); request_to_draw_cells_behind_numeric_input();
erase_numeric_input(); erase_numeric_input();
draw_frequencies();
} }
draw_frequencies();
} }
static void static void