From c0e152f6c05de2591ad5488a46c7a14101e04bee Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 27 May 2020 08:22:24 +0200 Subject: [PATCH] Small UI improvements and additional units --- main.c | 5 +++-- nanovna.h | 3 ++- plot.c | 19 ++++++++--------- sa_core.c | 8 +++---- ui.c | 5 +++-- ui_sa.c | 64 ++++++++++++++++++++++++++++++++----------------------- 6 files changed, 58 insertions(+), 46 deletions(-) diff --git a/main.c b/main.c index f3c313e..7f413d6 100644 --- a/main.c +++ b/main.c @@ -717,12 +717,13 @@ VNA_SHELL_FUNCTION(cmd_data) if (argc == 1) sel = my_atoi(argv[0]); - if (sel >= 0 || sel <= MAX_DATA) { + + if (sel >= 0 && sel <= MAX_DATA) { for (i = 0; i < sweep_points; i++) shell_printf("%f\r\n", measured[sel][i]); return; } - shell_printf("usage: data [array]\r\n"); + shell_printf("usage: data [0-2]\r\n"); } #ifdef ENABLED_DUMP diff --git a/nanovna.h b/nanovna.h index bdc9689..d67e730 100644 --- a/nanovna.h +++ b/nanovna.h @@ -339,8 +339,9 @@ enum trace_type { // Phase enum unit_type { - U_DBM=0, U_DBMV, U_DBUV, U_VOLT, U_MWATT, + U_DBM=0, U_DBMV, U_DBUV, U_MVOLT, U_UVOLT, U_MWATT, U_UWATT }; +#define UNIT_IS_LINEAR(T) ( T >= U_MVOLT ? true : false) float value(float); diff --git a/plot.c b/plot.c index 19741b8..4c1d5e2 100644 --- a/plot.c +++ b/plot.c @@ -462,12 +462,18 @@ value(const float v) case U_DBUV: return v+ 90.0 + 20.0*log10(sqrt(50.0)); break; - case U_VOLT: - return pow(10, (v - 30.0)/20.0) * sqrt(50.0); + case U_MVOLT: + return pow(10, (v-30.0)/20.0) * sqrt(50.0) * 1000.0; + break; + case U_UVOLT: + return pow(10, (v-30.0)/20.0) * sqrt(50.0) * 1000000.0; break; case U_MWATT: return pow(10, v/10.0); break; + case U_UWATT: + return pow(10, (v)/10.0) * 1000.0; + break; } // case U_DBM: return v; // raw data is in logmag*10 format @@ -796,14 +802,7 @@ trace_get_value_string_delta(int t, char *buf, int len, float array[POINTS_COUNT } #endif -static const char *unit_string[] = -{ - "", - "dBmV", - "dBuV", - "V", - "mW" -}; +extern const char *unit_string[]; static void trace_get_value_string( int t, char *buf, int len, diff --git a/sa_core.c b/sa_core.c index 4f278e0..078a9ca 100644 --- a/sa_core.c +++ b/sa_core.c @@ -488,7 +488,7 @@ void set_trigger(int trigger) void set_scale(float s) { setting.scale = s; - if (setting.unit == U_VOLT || setting.unit == U_MWATT) { + if (UNIT_IS_LINEAR(setting.unit)) { // Bottom always at zero set_reflevel(NGRIDY * s); } set_trace_scale(0, s); @@ -1242,7 +1242,7 @@ again: } } if (!in_selftest && MODE_INPUT(setting.mode) && setting.auto_reflevel && max_index[0] > 0) { // Auto reflevel - if (setting.unit == U_VOLT || setting.unit == U_MWATT) { // Linear scales can not have negative values + if (UNIT_IS_LINEAR(setting.unit)) { // Linear scales can not have negative values float t = value(actual_t[max_index[0]]); if (t < setting.reflevel / 2 || t> setting.reflevel) { float m = 1; @@ -1508,7 +1508,7 @@ float my_round(float v) return v; } -const char *unit_string[] = { "dBmW", "dBmV", "dBuV", "V", "mW" }; +const char *unit_string[] = { "dBm", "dBmV", "dBuV", "mV", "uV", "mW", "uW" }; void draw_cal_status(void) { @@ -1519,7 +1519,7 @@ void draw_cal_status(void) int y = OFFSETY; unsigned int color; int rounding = false; - if (setting.unit != U_VOLT && setting.unit != U_MWATT) + if (!UNIT_IS_LINEAR(setting.unit)) rounding = true; const char *unit = unit_string[setting.unit]; diff --git a/ui.c b/ui.c index b2ba616..9bd2a80 100644 --- a/ui.c +++ b/ui.c @@ -301,7 +301,7 @@ void touch_wait_release(void) { while (touch_check() != EVT_TOUCH_RELEASED) - ; + chThdSleepMilliseconds(20); } static inline void @@ -785,7 +785,8 @@ menu_marker_search_cb(int item, uint8_t data) int i = -1; if (active_marker == -1) return; - + if (data < 4) + markers[active_marker].mtype &= ~M_TRACKING; switch (data) { case 0: /* search Left */ i = marker_search_left_min(markers[active_marker].index); diff --git a/ui_sa.c b/ui_sa.c index 8952808..8114b0e 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1158,7 +1158,16 @@ static const menuitem_t menu_reflevel[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; - +const menuitem_t menu_marker_search[] = { + //{ MT_CALLBACK, "OFF", menu_marker_search_cb }, + { MT_CALLBACK, 0, "\2MIN\0" S_LARROW" LEFT", menu_marker_search_cb }, + { MT_CALLBACK, 1, "\2MIN\0" S_RARROW" RIGHT", menu_marker_search_cb }, + { MT_CALLBACK, 2, "\2MAX\0" S_LARROW" LEFT", menu_marker_search_cb }, + { MT_CALLBACK, 3, "\2MAX\0" S_RARROW" RIGHT", menu_marker_search_cb }, + { MT_CALLBACK, 4, "TRACKING", menu_marker_search_cb }, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; const menuitem_t menu_marker_modify[] = { { MT_CALLBACK, M_REFERENCE, "REFERENCE", menu_marker_modify_cb}, @@ -1166,22 +1175,12 @@ const menuitem_t menu_marker_modify[] = { { MT_CALLBACK, M_NOISE, "NOISE", menu_marker_modify_cb}, { MT_CALLBACK, M_TRACKING, "TRACKING", menu_marker_modify_cb}, { MT_CALLBACK, M_NORMAL, "NORMAL", menu_marker_modify_cb}, + { MT_SUBMENU, 0, "SEARCH", menu_marker_search}, { MT_CALLBACK, M_DELETE, "DELETE", menu_marker_modify_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; -const menuitem_t menu_marker_search[] = { - //{ MT_CALLBACK, "OFF", menu_marker_search_cb }, - { MT_CALLBACK, 0, "\2MIN\0" S_LARROW" LEFT", menu_marker_search_cb }, - { MT_CALLBACK, 1, "\2MIN\0" S_RARROW" RIGHT", menu_marker_search_cb }, - { MT_CALLBACK, 2, "\2MAX\0" S_LARROW" LEFT", menu_marker_search_cb }, - { MT_CALLBACK, 3, "\2MAX\0" S_RARROW" RIGHT", menu_marker_search_cb }, - { MT_CALLBACK, 4, "TRACKING", menu_marker_search_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - const menuitem_t menu_marker_sel[] = { { MT_CALLBACK, 1, "MARKER 1", menu_marker_sel_cb }, { MT_CALLBACK, 2, "MARKER 2", menu_marker_sel_cb }, @@ -1217,7 +1216,7 @@ const menuitem_t menu_marker_ops[] = { static const menuitem_t menu_marker[] = { - { MT_SUBMENU, 0, "\2SELECT\0MARKER", menu_marker_sel}, +// { MT_SUBMENU, 0, "\2SELECT\0MARKER", menu_marker_sel}, { MT_SUBMENU, 0, "\2MODIFY\0MARKERS", menu_marker_select}, { MT_SUBMENU, 0, "\2MARKER\0OPS", menu_marker_ops}, { MT_SUBMENU, 0, "\2SEARCH\0MARKER", menu_marker_search}, @@ -1304,13 +1303,13 @@ static const menuitem_t menu_settingshigh[] = }; static const menuitem_t menu_measure[] = { - { MT_CALLBACK, M_OFF, "OFF", menu_measure_cb}, - { MT_CALLBACK, M_IMD, "MARMONICS", menu_measure_cb}, - { MT_CALLBACK, M_OIP3, "OIP3", menu_measure_cb}, - { MT_CALLBACK, M_PHASE_NOISE, "\2PHASE\0NOISE", menu_measure_cb}, - { MT_CALLBACK, M_STOP_BAND, "\2STOP\0BAND", menu_measure_cb}, - { MT_CALLBACK, M_PASS_BAND, "\2PASS\0BAND", menu_measure_cb}, - { MT_CALLBACK, M_LINEARITY, "LINEARITY", menu_measure_cb}, + { MT_CALLBACK, M_OFF, "OFF", menu_measure_cb}, + { MT_CALLBACK, M_IMD, "MARMONICS", menu_measure_cb}, + { MT_CALLBACK, M_OIP3, "OIP3", menu_measure_cb}, + { MT_CALLBACK, M_PHASE_NOISE,"\2PHASE\0NOISE", menu_measure_cb}, + { MT_CALLBACK, M_STOP_BAND, "\2STOP\0BAND", menu_measure_cb}, + { MT_CALLBACK, M_PASS_BAND, "\2PASS\0BAND", menu_measure_cb}, + { MT_CALLBACK | MT_LOW, M_LINEARITY, "LINEARITY", menu_measure_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1329,8 +1328,8 @@ static const menuitem_t menu_config[] = { { MT_CALLBACK, 0, "\2TOUCH\0TEST", menu_config_cb}, { MT_CALLBACK, 0, "\2SELF\0TEST", menu_config_cb}, { MT_SUBMENU, 0, "\2LEVEL\0CAL", menu_calibrate}, - { MT_CALLBACK, 0, "VERSION", menu_config_cb}, - { MT_SUBMENU, 0, "\2EXPERT\0CONF",menu_settings}, + { MT_CALLBACK, 0, "VERSION", menu_config_cb}, + { MT_SUBMENU, 0, "\2EXPERT\0CONFIG", menu_settings}, { MT_SUBMENU, 0, S_RARROW"DFU", menu_dfu}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel @@ -1346,6 +1345,7 @@ static const menuitem_t menu_display[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; +#if 0 static const menuitem_t menu_displayhigh[] = { { MT_CALLBACK,0, "\2PAUSE\0SWEEP", menu_pause_cb}, { MT_CALLBACK,0, "STORE", menu_storage_cb}, @@ -1355,15 +1355,17 @@ static const menuitem_t menu_displayhigh[] = { { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; - +#endif static const menuitem_t menu_unit[] = { - { MT_CALLBACK,U_DBM, "dBmW", menu_unit_cb}, + { MT_CALLBACK,U_DBM, "dBm", menu_unit_cb}, { MT_CALLBACK,U_DBMV, "dBmV", menu_unit_cb}, { MT_CALLBACK,U_DBUV, "dBuV", menu_unit_cb}, - { MT_CALLBACK,U_VOLT, "Volt", menu_unit_cb}, + { MT_CALLBACK,U_MVOLT, "mVolt", menu_unit_cb}, + { MT_CALLBACK,U_UVOLT, "uVolt", menu_unit_cb}, { MT_CALLBACK,U_MWATT, "mWatt", menu_unit_cb}, + { MT_CALLBACK,U_UWATT, "uWatt", menu_unit_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1377,7 +1379,7 @@ static const menuitem_t menu_trigger[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; - +#if 0 static const menuitem_t menu_levelhigh[] = { { MT_SUBMENU, 0, "\2REF\0LEVEL", menu_reflevel}, // { MT_SUBMENU, 0, "\2SCALE/\0DIV",menu_scale_per}, @@ -1389,6 +1391,7 @@ static const menuitem_t menu_levelhigh[] = { { MT_CANCEL, 0, S_LARROW" BACK",NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; +#endif static const menuitem_t menu_level[] = { { MT_SUBMENU, 0, "\2REF\0LEVEL", menu_reflevel}, @@ -1461,6 +1464,7 @@ const menuitem_t menu_top[] = { // MENUITEM_CLOSE, }; +#if 0 const menuitem_t menu_tophigh[] = { { MT_SUBMENU, 0, "PRESET", menu_load_preset_high}, { MT_SUBMENU, 0, "FREQ", menu_stimulus}, @@ -1473,6 +1477,8 @@ const menuitem_t menu_tophigh[] = { { MT_NONE, 0, NULL, NULL } // sentinel, // MENUITEM_CLOSE, }; +#endif + // ===[MENU DEFINITION END]====================================================== #define ACTIVE_COLOR RGBHEX(0x007FFF) @@ -1535,6 +1541,10 @@ static void menu_item_modify_attribute( mark = true; } + } else if (MT_MASK(menu[item].type) == MT_CALLBACK && menu == menu_unit) { + if (data == setting.unit){ + mark = true; + } } else if (MT_MASK(menu[item].type) == MT_CALLBACK && (menu == menu_drive || menu == menu_drive_wide || menu == menu_drive_wide2|| menu == menu_drive_wide3)) { if (data == setting.drive){ mark = true; @@ -1547,7 +1557,7 @@ static void menu_item_modify_attribute( if (data == setting.trigger){ mark = true; } - } else if (menu == menu_display || menu == menu_displayhigh) { + } else if (menu == menu_display /* || menu == menu_displayhigh */) { if (item ==0 && is_paused()){ mark = true; }