feat: add format quality factor

This commit is contained in:
TT 2020-06-16 09:23:10 +09:00
parent 64de4d5d87
commit bc1b57c3f0
4 changed files with 31 additions and 9 deletions

7
main.c
View file

@ -1550,7 +1550,8 @@ static const struct {
{ "REAL", NGRIDY/2, 0.25 },
{ "IMAG", NGRIDY/2, 0.25 },
{ "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[] = {
@ -1654,8 +1655,8 @@ VNA_SHELL_FUNCTION(cmd_trace)
#if MAX_TRACE_TYPE != 12
#error "Trace type enum possibly changed, check cmd_trace function"
#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
static const char cmd_type_list[] = "logmag|phase|delay|smith|polar|linear|swr|real|imag|r|x|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|q|off";
int type = get_str_index(argv[1], cmd_type_list);
if (type >= 0) {
set_trace_type(t, type);

View file

@ -194,10 +194,10 @@ extern const uint16_t numfont16x22[];
#define MAX_TRACE_TYPE 12
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
#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
// PHASE: SCALE, REFPOS, REFVAL

19
plot.c
View file

@ -491,6 +491,14 @@ reactance(const float *v)
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
cartesian_scale(float re, float im, int *xp, int *yp, float scale)
{
@ -567,6 +575,9 @@ trace_into_index(int t, int i, float array[POINTS_COUNT][2])
case TRC_X:
v-= reactance(coeff) * scale;
break;
case TRC_Q:
v-= qualityfactor(coeff) * scale;
break;
case TRC_SMITH:
//case TRC_ADMIT:
case TRC_POLAR:
@ -669,6 +680,10 @@ trace_get_value_string(int t, char *buf, int len, float array[POINTS_COUNT][2],
format = "%.2F"S_OHM;
v = gamma2reactance(coeff);
break;
case TRC_Q:
format = "%.1f";
v = qualityfactor(coeff);
break;
case TRC_SMITH:
format_smith_value(buf, len, coeff, frequencies[i]);
return;
@ -729,6 +744,10 @@ trace_get_value_string_delta(int t, char *buf, int len, float array[POINTS_COUNT
format = "%.2F"S_OHM;
v = gamma2reactance(coeff);
break;
case TRC_Q:
format = "%.1f";
v = qualityfactor(coeff);
break;
//case TRC_ADMIT:
case TRC_POLAR:
plot_printf(buf, len, "%.2f%+.2fj", coeff[0], coeff[1]);

10
ui.c
View file

@ -886,6 +886,7 @@ const menuitem_t menu_format2[] = {
{ MT_CALLBACK, TRC_IMAG, "IMAG", menu_format_cb },
{ MT_CALLBACK, TRC_R, "RESISTANCE", 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_NONE, 0, NULL, NULL } // sentinel
};
@ -1140,6 +1141,7 @@ menu_invoke(int item)
#define MENU_BUTTON_WIDTH 60
#define MENU_BUTTON_HEIGHT 30
#define MENU_BUTTON_MAX 8
#define NUM_INPUT_HEIGHT 30
#define KP_WIDTH 48
@ -1414,7 +1416,7 @@ static void
draw_menu_buttons(const menuitem_t *menu)
{
int i = 0;
for (i = 0; i < 7; i++) {
for (i = 0; i < MENU_BUTTON_MAX; i++) {
const char *l1, *l2;
if (menu[i].type == MT_NONE)
break;
@ -1460,7 +1462,7 @@ menu_apply_touch(void)
int i;
touch_position(&touch_x, &touch_y);
for (i = 0; i < 7; i++) {
for (i = 0; i < MENU_BUTTON_MAX; i++) {
if (menu[i].type == MT_NONE)
break;
if (menu[i].type == MT_BLANK)
@ -1485,7 +1487,7 @@ draw_menu(void)
static void
erase_menu_buttons(void)
{
ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*7, DEFAULT_BG_COLOR);
ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT * MENU_BUTTON_MAX, DEFAULT_BG_COLOR);
}
static void
@ -1503,8 +1505,8 @@ leave_ui_mode()
} else if (ui_mode == UI_NUMERIC) {
request_to_draw_cells_behind_numeric_input();
erase_numeric_input();
draw_frequencies();
}
draw_frequencies();
}
static void