diff --git a/.project b/.project index f5b7df6..7363c6a 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - nanoVNA-Erik + tinySA diff --git a/chprintf.c b/chprintf.c index 0b24e38..ecb6179 100644 --- a/chprintf.c +++ b/chprintf.c @@ -88,12 +88,12 @@ static char *long_to_string_with_divisor(char *p, #define FREQ_PREFIX_SPACE 4 static char * -ulong_freq(char *p, ulong_t freq, uint32_t precision) +ulong_freq(char *p, ulong_t freq, uint32_t width, uint32_t precision) { uint8_t flag = FREQ_PSET; flag|= precision == 0 ? FREQ_PREFIX_SPACE : FREQ_NO_SPACE; - if (precision == 0 || precision > MAX_FREQ_PRESCISION) + if (/* precision == 0 || */ precision > MAX_FREQ_PRESCISION) precision = MAX_FREQ_PRESCISION; char *q = p + MAX_FREQ_PRESCISION; char *b = q; @@ -136,6 +136,8 @@ ulong_freq(char *p, ulong_t freq, uint32_t precision) // Get string size uint32_t i = (b - q); + if (width > 0 && i>width) + i=width; // copy string // Replace first ' ' by '.', remove ' ' if size too big do { @@ -152,6 +154,8 @@ ulong_freq(char *p, ulong_t freq, uint32_t precision) if (!(flag & FREQ_PSET) && precision-- == 0) break; } while (--i); + if (p[-1] == '.') // No '.' at end + p--; // Put pref (amd space before it if need) if (flag & FREQ_PREFIX_SPACE && s != ' ') *p++ = ' '; @@ -393,7 +397,9 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { else #endif value.ux = va_arg(ap, uint32_t); - p=ulong_freq(p, value.ux, precision); + if (state&DEFAULT_PRESCISION) + precision = MAX_FREQ_PRESCISION; + p=ulong_freq(p, value.ux, width, precision); break; #if CHPRINTF_USE_FLOAT case 'F': diff --git a/main.c b/main.c index 2f7911e..d228c74 100644 --- a/main.c +++ b/main.c @@ -106,7 +106,7 @@ const char *info_about[]={ }; bool dirty = true; -bool completed = false; +uint8_t completed = false; uint8_t enable_after_complete = 0; #ifdef TINYSA4 @@ -926,10 +926,10 @@ config_t config = { static const marker_t def_markers[MARKERS_MAX] = { - { M_ENABLED, M_REFERENCE | M_TRACKING, 30, 0 }, - { M_DISABLED, M_NORMAL, 40, 0 }, - { M_DISABLED, M_NORMAL, 60, 0 }, - { M_DISABLED, M_NORMAL, 80, 0 } + { M_ENABLED, M_TRACKING, 0, 30, 0 }, + { M_DISABLED, M_NORMAL, 0, 40, 0 }, + { M_DISABLED, M_NORMAL, 0, 60, 0 }, + { M_DISABLED, M_NORMAL, 0, 80, 0 } }; // Load propeties default settings diff --git a/nanovna.h b/nanovna.h index 2514cf3..328cb8a 100644 --- a/nanovna.h +++ b/nanovna.h @@ -300,7 +300,7 @@ enum { #endif extern uint8_t sweep_mode; -extern bool completed; +extern uint8_t completed; extern const char *info_about[]; #ifdef TINYSA4 @@ -737,7 +737,7 @@ enum { }; enum { - M_DISABLED = false, M_ENABLED = true + M_DISABLED = 0, M_ENABLED = 1 }; @@ -757,8 +757,9 @@ enum { void enableTracesAtComplete(uint8_t mask); typedef struct { - uint8_t enabled; uint8_t mtype; + uint8_t enabled; + uint8_t ref; int16_t index; freq_t frequency; } marker_t; @@ -806,6 +807,7 @@ int marker_search_left_max(int m); int marker_search_right_max(int m); int marker_search_left_min(int m); int marker_search_right_min(int m); +void markers_reset(void); // _request flag for update screen #define REDRAW_CELLS (1<<0) @@ -1439,7 +1441,7 @@ void interpolate_maximum(int m); void calibrate_modulation(int modulation, int8_t *correction); enum { - M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_DECONV + M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_DECONV }; enum { diff --git a/plot.c b/plot.c index 18594ba..a6b5f72 100644 --- a/plot.c +++ b/plot.c @@ -90,30 +90,17 @@ static index_y_t trace_index_y[TRACES_MAX][POINTS_COUNT]; uint16_t marker_color(int mtype) { - if (mtype & M_REFERENCE) - return LCD_M_REFERENCE; +// if (mtype & M_REFERENCE) +// return LCD_M_REFERENCE; if (mtype & M_STORED) return LCD_M_DELTA; // if (mtype & M_DELTA) // return LCD_BRIGHT_COLOR_RED; - if (mtype & M_NOISE) - return LCD_M_NOISE; +// if (mtype & M_NOISE) +// return LCD_M_NOISE; return LCD_M_DEFAULT; } -//#if 4 != M_TRACKING -//#error "Wrong marker numbers" -//#endif - -char marker_letter[5] = -{ - 'R', - ' ', - 'D', - 'N', - 'T' -}; - #if 1 #define float2int(v) ((int)(v)) #else @@ -1042,7 +1029,7 @@ draw_cell(int m, int n) } #endif #ifdef __CHANNEL_POWER__ - if (setting.measurement == M_CP) { + if (setting.measurement == M_CP||setting.measurement == M_SNR) { c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR); for (x = 0; x < w; x++) if (x+x0 == WIDTH/3 || x+x0 == 2*WIDTH/3 ) { @@ -1423,11 +1410,6 @@ static void trace_print_value_string( // Only used at one place { (void) bold; int ref_marker=-1; - for (int i = 0; i < MARKER_COUNT; i++) { - if (markers[i].enabled && markers[i].mtype & M_REFERENCE && ((markers[i].mtype & M_STORED) == (markers[mi].mtype & M_STORED))) { - ref_marker = i; - } - } int mtype = markers[mi].mtype; int idx = markers[mi].index; float v = marker_to_value(mi); @@ -1436,14 +1418,16 @@ static void trace_print_value_string( // Only used at one place // Prepare marker type string *ptr2++ = mi == active_marker ? S_SARROW[0] : ' '; *ptr2++ = mi+'1'; - if (mtype & M_REFERENCE) - *ptr2++ = 'R'; +// if (mtype & M_REFERENCE) +// *ptr2++ = 'R'; if (mtype & M_TRACKING) *ptr2++ = 'T'; - if (mtype & M_DELTA) - *ptr2++ = 'D'; - if (mtype & M_NOISE) - *ptr2++ = 'N'; + if (mtype & M_DELTA) { + *ptr2++ = S_DELTA[0]; + *ptr2++ = markers[mi].ref+'1'; + } +// if (mtype & M_NOISE) +// *ptr2++ = 'N'; *ptr2++ = ' '; if (mtype & M_NOISE){ // v-= log10f(actual_rbw_x10*100.0) * 10.0; @@ -1458,8 +1442,9 @@ static void trace_print_value_string( // Only used at one place freq_t freq = markers[mi].frequency; int unit_index = setting.unit; // Setup delta values - if (mtype & M_DELTA && ref_marker>=0) { - *ptr2++ = S_DELTA[0]; + if (mtype & M_DELTA) { + ref_marker = markers[mi].ref; +// *ptr2++ = S_DELTA[0]; unit_index+= 5; freq_t ref_freq = markers[ref_marker].frequency; int ridx = markers[ref_marker].index; @@ -1504,14 +1489,19 @@ static void cell_draw_marker_info(int x0, int y0) } } #ifdef __CHANNEL_POWER__ - if (setting.measurement==M_CP) { + if (setting.measurement==M_CP || setting.measurement==M_SNR) { ili9341_set_foreground(LCD_FG_COLOR); + freq_t bw = get_sweep_frequency(ST_SPAN)/3; for (int c=0; c<3;c++) { int xpos = 10 + (c)*(WIDTH/3) + CELLOFFSETX - x0; int ypos = 1 - y0; - cell_printf(xpos, ypos, FONT_b"%4.1fdBm", channel_power[c]); + cell_printf(xpos, ypos, FONT_b"%4.1fdBm/%3QHz", channel_power[c], bw); ypos = 14 - y0; - cell_printf(xpos, ypos, FONT_b"%4.1f%%", 100.0 * channel_power_watt[c] /(channel_power_watt[0] + channel_power_watt[1] + channel_power_watt[2]) ); + if (setting.measurement==M_CP ) + cell_printf(xpos, ypos, FONT_b"%4.1f%%", 100.0 * channel_power_watt[c] /(channel_power_watt[0] + channel_power_watt[1] + channel_power_watt[2]) ); + else if (c == 1) + cell_printf(xpos, ypos, FONT_b"SNR: %4.1fdB", channel_power[1] - (channel_power[0] + channel_power[2])/2 ); + } return; } diff --git a/sa_core.c b/sa_core.c index cbd2f6f..452cfc0 100644 --- a/sa_core.c +++ b/sa_core.c @@ -357,12 +357,7 @@ void reset_settings(int m) break; } setting.level = level_max(); // This is the level with above settings. - for (uint8_t i = 0; i< MARKERS_MAX; i++) { - markers[i].enabled = M_DISABLED; - markers[i].mtype = M_NORMAL; - } - markers[0].mtype = M_REFERENCE | M_TRACKING; - markers[0].enabled = M_ENABLED; + markers_reset(); setting._active_marker = 0; set_external_gain(0.0); // This also updates the help text!!!!! Must be below level_min and level_max being set set_sweep_points(POINTS_COUNT); @@ -4443,13 +4438,6 @@ static volatile int dummy; } else if (setting.measurement == M_PHASE_NOISE && markers[0].index > 10) { // ------------Phase noise measurement markers[1].index = markers[0].index + (setting.mode == M_LOW ? WIDTH/4 : -WIDTH/4); // Position phase noise marker at requested offset markers[1].frequency = frequencies[markers[1].index]; - } else if (setting.measurement == M_STOP_BAND && markers[0].index > 10) { // -------------Stop band measurement - markers[1].index = marker_search_left_min(0); - if (markers[1].index < 0) markers[1].index = 0; - markers[1].frequency = frequencies[markers[1].index]; - markers[2].index = marker_search_right_min(0); - if (markers[2].index < 0) markers[1].index = setting._sweep_points - 1; - markers[2].frequency = frequencies[markers[2].index]; } else if ((setting.measurement == M_PASS_BAND || setting.measurement == M_FM) && markers[0].index > 10) { // ----------------Pass band measurement int t = 0; float v = actual_t[markers[0].index] - (in_selftest ? 6.0 : 3.0); @@ -4484,7 +4472,8 @@ static volatile int dummy; #endif } #ifdef __CHANNEL_POWER__ - } else if (setting.measurement == M_CP) { // ----------------CHANNEL_POWER measurement + } else if (setting.measurement == M_CP || setting.measurement == M_SNR) { // ----------------CHANNEL_POWER measurement + freq_t bw = get_sweep_frequency(ST_SPAN)/3; int old_unit = setting.unit; setting.unit = U_WATT; for (int c = 0; c < 3 ;c++) { @@ -4493,7 +4482,7 @@ static volatile int dummy; for (int i =0; i < sp_div3; i++) { channel_power_watt[c] += value(actual_t[i + c*sp_div3]); } - float rbw_cor = (float)(get_sweep_frequency(ST_SPAN)/3) / ((float)actual_rbw_x10 * 100.0); + float rbw_cor = ((float)bw) / ((float)actual_rbw_x10 * 100.0); channel_power_watt[c] = channel_power_watt[c] * rbw_cor /(float)sp_div3; channel_power[c] = to_dBm(channel_power_watt[c]); } @@ -4643,6 +4632,18 @@ marker_search_right_max(int m) return found; } +void markers_reset() +{ + for (uint8_t i = 0; i< MARKERS_MAX; i++) { + markers[i].enabled = M_DISABLED; + markers[i].mtype = M_DELTA; + markers[i].ref = 0; + } + markers[0].mtype = M_TRACKING; + markers[0].enabled = M_ENABLED; + active_marker = 0; +} + int marker_search_max(int m) { int i = 0; diff --git a/ui.c b/ui.c index c4c7978..bd16950 100644 --- a/ui.c +++ b/ui.c @@ -726,6 +726,12 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb) //redraw_all(); } +static UI_FUNCTION_CALLBACK(menu_markers_reset_cb) +{ + (void)item; + markers_reset(); +} + static UI_FUNCTION_CALLBACK(menu_marker_search_cb) { (void)item; diff --git a/ui_sa.c b/ui_sa.c index a95c37d..3de8cb1 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -507,6 +507,7 @@ static const menuitem_t menu_sweep_points[]; static const menuitem_t menu_sweep_points_form[]; static const menuitem_t menu_modulation[]; static const menuitem_t menu_limit_modify[]; +static const menuitem_t menu_marker_ref_select[]; #ifdef __USE_SERIAL_CONSOLE__ static const menuitem_t menu_connection[]; #endif @@ -780,13 +781,7 @@ UI_FUNCTION_CALLBACK(menu_autosettings_cb) (void)data; reset_settings(setting.mode); - active_marker = 0; - for (int i = 1; iicon = BUTTON_ICON_CHECK; else if (data==markers[active_marker].mtype) // This catches the M_NORMAL case b->icon = BUTTON_ICON_CHECK; + if ((markers[active_marker].mtype & M_DELTA)) + uistat.text[0] = markers[active_marker].ref+'1'; + else + uistat.text[0] = 0; + uistat.text[1] = 0; + b->param_1.text = uistat.text; } return; } @@ -1512,8 +1492,11 @@ static UI_FUNCTION_ADV_CALLBACK(menu_marker_modify_acb) } markers[active_marker].mtype &= ~M_DELTA; } - if (data == M_DELTA) - markers[active_marker].mtype &= ~M_REFERENCE; + if (data == M_DELTA) { + if (!(markers[active_marker].mtype & M_DELTA)) // Not yet set + menu_push_submenu(menu_marker_ref_select); + markers[active_marker].mtype &= ~M_REFERENCE; + } #if 1 markers[active_marker].mtype ^= data; #else @@ -1528,11 +1511,32 @@ static UI_FUNCTION_ADV_CALLBACK(menu_marker_modify_acb) // menu_move_back(false); } +static UI_FUNCTION_ADV_CALLBACK(menu_marker_ref_select_acb) +{ + (void)item; + if(b){ +// b->icon = markers[data-1].enabled ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK; + b->icon = (markers[active_marker].ref == data-1 ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP ); + b->param_1.i = data; + return; + } + markers[data-1].enabled = true; +// interpolate_maximum(data-1); // possibly not a maximum + markers[data-1].frequency = frequencies[markers[data-1].index]; + markers[active_marker].ref = data-1; + redraw_marker(active_marker); + menu_move_back(false); +} + static UI_FUNCTION_CALLBACK(menu_marker_delete_cb) { (void)item; (void)data; if (active_marker>=0){ + for (int i = 0; i= 5 + { MT_ADV_CALLBACK, 5, "MARKER %d", menu_marker_ref_select_acb }, +#endif +#if MARKER_COUNT >= 6 + { MT_ADV_CALLBACK, 6, "MARKER %d", menu_marker_ref_select_acb }, +#endif +#if MARKER_COUNT >= 7 + { MT_ADV_CALLBACK, 7, "MARKER %d", menu_marker_ref_select_acb }, +#endif +#if MARKER_COUNT >= 8 + { MT_ADV_CALLBACK, 8, "MARKER %d", menu_marker_ref_select_acb }, +#endif + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + const menuitem_t menu_marker_ops[] = { { MT_CALLBACK, ST_START, S_RARROW" START", menu_marker_op_cb }, { MT_CALLBACK, ST_STOP, S_RARROW" STOP", menu_marker_op_cb }, @@ -2299,6 +2324,7 @@ static const menuitem_t menu_marker[] = { { MT_SUBMENU, 0, "MODIFY\nMARKERS", menu_marker_select}, { MT_SUBMENU, 0, "MARKER\nOPS", menu_marker_ops}, { MT_SUBMENU, 0, "SEARCH\nMARKER", menu_marker_search}, + { MT_CALLBACK, 0, "RESET\nMARKERS", menu_markers_reset_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -2452,7 +2478,7 @@ static const menuitem_t menu_settings2[] = { MT_KEYPAD, KM_NOISE, "NOISE\nLEVEL", "2..20 dB"}, #endif #ifdef TINYSA4 - { MT_KEYPAD, KM_30MHZ, "ACTUAL\n30MHz", "Enter actual 30MHz frequency"}, + { MT_KEYPAD, KM_30MHZ, "ACTUAL\n30MHz*100", "Enter actual 30MHz * 100"}, #endif { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, @@ -2564,7 +2590,7 @@ static const menuitem_t menu_measure[] = { { MT_ADV_CALLBACK, M_IMD, "HARMONIC", menu_measure_acb}, { MT_ADV_CALLBACK, M_OIP3, "OIP3", menu_measure_acb}, { MT_ADV_CALLBACK, M_PHASE_NOISE,"PHASE\nNOISE", menu_measure_acb}, - { MT_ADV_CALLBACK, M_STOP_BAND, "SNR", menu_measure_acb}, + { MT_ADV_CALLBACK, M_SNR, "SNR", menu_measure_acb}, { MT_ADV_CALLBACK, M_PASS_BAND, "-3dB\nWIDTH", menu_measure_acb}, { MT_SUBMENU, 0, S_RARROW" MORE", menu_measure2}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, @@ -3308,7 +3334,7 @@ redraw_cal_status: // if (setting.mode == M_LOW) { // Attenuation - ili9341_set_foreground(setting.auto_attenuation ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); + ili9341_set_foreground(setting.auto_attenuation ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN); lcd_printf(x, y, "Atten:\n%4.2FdB", get_attenuation()); y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_atten); // } @@ -3402,7 +3428,7 @@ redraw_cal_status: // Offset if (setting.external_gain != 0.0) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - lcd_printf(x, y, "Amp:\n%4.1fdB",setting.external_gain); + lcd_printf(x, y, "Gain:\n%4.1fdB",setting.external_gain); y = add_quick_menu(y+=YSTEP, (menuitem_t *)KM_EXT_GAIN); }