From ac33a335e371f03823d9f9df442b51d758fddd79 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 16 May 2021 17:13:38 +0200 Subject: [PATCH 1/4] Deactive FFT stuff --- nanovna.h | 1 + sa_core.c | 79 +++++++++++++++++++++++++++++++++++-------------------- ui.c | 1 + 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/nanovna.h b/nanovna.h index 3c746d6..7eb7507 100644 --- a/nanovna.h +++ b/nanovna.h @@ -88,6 +88,7 @@ #define DB_PER_DEGREE_ABOVE 0.069 #define CENTER_TEMPERATURE 34.0 #define __WAIT_CTS_WHILE_SLEEPING__ +//#define __FFT_VBW__ //#define __FFT_DECONV__ #else #endif diff --git a/sa_core.c b/sa_core.c index e761a7e..f0caeb1 100644 --- a/sa_core.c +++ b/sa_core.c @@ -35,6 +35,12 @@ float *real2 = (float *) &spi_buffer[1024]; float *imag2 = (float *) &spi_buffer[1536]; #endif +#ifdef __FFT_VBW__ +void FFT(float *real, float *imag, int length, bool inverse); +float *real = (float *) &spi_buffer[0]; +float *imag = (float *) &spi_buffer[512]; +#endif + //#define __DEBUG_AGC__ If set the AGC value will be shown in the stored trace and FAST_SWEEP rmmode will be disabled #ifdef __DEBUG_AGC__ #ifdef __FAST_SWEEP__ @@ -3813,6 +3819,36 @@ static bool sweep(bool break_on_operation) #ifdef __VBW__ +#ifdef __FFT_VBW__ + if (setting.vbw_x10 != 0 && sweep_points == 256) { + float m = 150; + for (int i=0;i temp_t[i]) + m = temp_t[i]; + real[i] = 0; + imag[i] = 0; + actual_t[i] = -150; + } + for (int i=0;i temp_t[i]) m = temp_t[i]; - real[i] = 0; + real[i] = 0.000000000001; imag[i] = 0; - real2[0] = 0; + real2[0] = 0.000000000001; imag2[i] = 0; actual_t[i] = -150; } - for (int i=0;i m+25) + real[i] = temp_t[i] - m; } - FFT(real, imag, 256, false); +#if 1 #if 0 for (int i = 128 - d_width*2; i<128+d_width*2; i++) { real[i] = 0; imag[i] = 0; } #endif -#if 0 +#if 1 for (int i=0;i0; i--) { - actual_t[i+d_width/2] = actual_t[i] + temp_t[0]; - } - for (int i = 0; i < d_width/2+2; i++) { - actual_t[i] = temp_t[0]; - actual_t[sweep_points - 1 - i] = temp_t[0]; - } -#endif - } diff --git a/ui.c b/ui.c index 1fb1527..2f3b054 100644 --- a/ui.c +++ b/ui.c @@ -1421,6 +1421,7 @@ draw_menu_buttons(const menuitem_t *menu, int only) text = button.text; } + int button_height = menu_button_height; if (menu[i].type & MT_FORM) { int button_width = MENU_FORM_WIDTH; int button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; // At center of screen From 90c50dc7761b1bc88edf881d60a830e5a4f0f55a Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 15:30:16 +0300 Subject: [PATCH 2/4] Skip %c char if input zero --- chprintf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chprintf.c b/chprintf.c index a149a86..0b24e38 100644 --- a/chprintf.c +++ b/chprintf.c @@ -350,7 +350,8 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { switch (c) { case 'c': state&=~PAD_ZERO; - *p++ = va_arg(ap, int); + c = va_arg(ap, int); + if (c) *p++ = c; break; case 's': state&=~PAD_ZERO; From 15ca2c7d5dda1916beaa078fdf4b9c162c47aa7f Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 16:32:20 +0300 Subject: [PATCH 3/4] Cleanup draw_cal_status code, use lcd_printf --- ui_sa.c | 189 +++++++++++++++++++------------------------------------- 1 file changed, 62 insertions(+), 127 deletions(-) diff --git a/ui_sa.c b/ui_sa.c index 26dfe9d..a95c37d 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -3201,9 +3201,8 @@ int invoke_quick_menu(int y) } #define YSTEP 8 -int add_quick_menu(char *buf, int x, int y, menuitem_t *menu) +int add_quick_menu(int y, menuitem_t *menu) { - ili9341_drawstring(buf, x, y); y += YSTEP*item_space/2 + YSTEP; if (max_quick_menu 0.9 && t < 1.1){ - plot_printf(buf, BLEN, "%s%c/",scale_vtext[i],unit_scale_text[setting.unit_scale_index]); + lcd_printf(x, y, "%s%c/",scale_vtext[i],unit_scale_text[setting.unit_scale_index]); break; } i++; } #else - plot_printf(buf, BLEN, "%.2F/",setting.scale); + lcd_printf(x, y, "%.2F/",setting.scale); #endif - y = add_quick_menu(buf, x, y, (menuitem_t *)KM_SCALE); + y = add_quick_menu(y, (menuitem_t *)KM_SCALE); // Trigger status if (is_paused()) { - color = LCD_BRIGHT_COLOR_GREEN; - ili9341_set_foreground(color); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_drawstring("PAUSED", x, y); y += YSTEP + YSTEP/2 ; } if (setting.trigger == T_SINGLE || setting.trigger == T_NORMAL ) { - color = LCD_BRIGHT_COLOR_GREEN; - ili9341_set_foreground(color); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_drawstring("ARMED", x, y); y += YSTEP + YSTEP/2 ; } // AM warning if (signal_is_AM) { - color = LCD_BRIGHT_COLOR_RED; - ili9341_set_foreground(color); + ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); ili9341_drawstring("AM", x, y); y += YSTEP + YSTEP/2 ; } @@ -3315,66 +3308,42 @@ redraw_cal_status: // if (setting.mode == M_LOW) { // Attenuation - if (setting.auto_attenuation) - color = LCD_FG_COLOR; - else - color = LCD_BRIGHT_COLOR_GREEN; - ili9341_set_foreground(color); - ili9341_drawstring("Atten:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.2FdB", get_attenuation()); - y = add_quick_menu(buf, x, y, (menuitem_t *)menu_atten); + ili9341_set_foreground(setting.auto_attenuation ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); + lcd_printf(x, y, "Atten:\n%4.2FdB", get_attenuation()); + y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_atten); // } // Calc if (setting.average>0) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Calc:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%s",averageText[setting.average]); - y = add_quick_menu(buf, x, y, (menuitem_t *)menu_average); + lcd_printf(x, y, "Calc:\n%s", averageText[setting.average]); + y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_average); } // Spur #ifdef __SPUR__ if (setting.spur_removal != S_OFF) { - if (setting.spur_removal == S_ON) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_FG_COLOR; - ili9341_set_foreground(color); - - ili9341_drawstring("Spur:", x, y); - y += YSTEP; - if (S_IS_AUTO(setting.spur_removal)) - y = add_quick_menu("AUTO", x, y, (menuitem_t *)menu_stimulus); - else - y = add_quick_menu("ON", x, y, (menuitem_t *)menu_stimulus); + ili9341_set_foreground(setting.spur_removal == S_ON ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); + lcd_printf(x, y, "Spur:\n%s", S_IS_AUTO(setting.spur_removal) ? "AUTO" : "ON"); + y = add_quick_menu(y += YSTEP, (menuitem_t *)menu_stimulus); } if (setting.mirror_masking) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Mask:", x, y); - - y += YSTEP; - y = add_quick_menu("ON", x, y, (menuitem_t *)menu_stimulus); + ili9341_drawstring("Mask:\nON", x, y); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_stimulus); } #endif if (setting.subtract_stored) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - y = add_quick_menu("Norm.", x, y, (menuitem_t *)menu_storage); + ili9341_drawstring("Norm.", x, y); + y = add_quick_menu(y, (menuitem_t *)menu_storage); } // RBW - if (setting.rbw_x10) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_FG_COLOR; - ili9341_set_foreground(color); + ili9341_set_foreground(setting.rbw_x10 ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); if (dirty) update_rbw(); - ili9341_drawstring("RBW:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.1FHz", actual_rbw_x10*100.0); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_rbw); + lcd_printf(x, y, "RBW:\n%.1FHz", actual_rbw_x10*100.0); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_rbw); #ifdef __VBW__ // VBW @@ -3387,41 +3356,22 @@ redraw_cal_status: vbw = 10; } ili9341_set_foreground(color); - ili9341_drawstring("VBW:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.1FHz", actual_rbw_x10*100.0 *vbw/10.0); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_vbw); + lcd_printf(x, y, "VBW:\n%.1FHz", actual_rbw_x10*100.0 *vbw/10.0); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_vbw); } #endif - // Sweep time - if (setting.step_delay != 0) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_FG_COLOR; - ili9341_set_foreground(color); - buf[0] = ' '; - strcpy(&buf[1],"Scan:"); - if (setting.step_delay_mode == SD_PRECISE) - buf[0] = 'P'; - else if (setting.step_delay_mode == SD_FAST) - buf[0] = 'F'; - else - strcpy(&buf[0],"Scan:"); - ili9341_drawstring(buf, x, y); - + // Sweep time: SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL + static const char fscan[]={0, 'P', 'F', 'M'}; if (dirty) { calculate_step_delay(); setting.actual_sweep_time_us = calc_min_sweep_time_us(); } - + ili9341_set_foreground(setting.step_delay ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); #if 0 // Activate for sweep time debugging - y += YSTEP; - plot_printf(buf, BLEN, "%5.3Fs", (float)setting.sweep_time_us/ONE_SECOND_TIME); - ili9341_drawstring(buf, x, y); + lcd_printf(x, y, "%cScan:\n%5.3Fs", fscan[setting.step_delay_mode&3], (float)setting.sweep_time_us/ONE_SECOND_TIME); #endif - y += YSTEP; - plot_printf(buf, BLEN, "%5.3Fs", (float)setting.actual_sweep_time_us/ONE_SECOND_TIME); - y = add_quick_menu(buf, x, y, (menuitem_t *)menu_sweep_speed); + lcd_printf(x, y, "%cScan:\n%5.3Fs", fscan[setting.step_delay_mode&3], (float)setting.actual_sweep_time_us/ONE_SECOND_TIME); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_sweep_speed); #if 0 // Activate for sweep time debugging @@ -3429,47 +3379,38 @@ redraw_cal_status: update_rbw(); // To ensure the calc_min_sweep time shown takes the latest delay into account calculate_step_delay(); uint32_t t = calc_min_sweep_time_us(); - plot_printf(buf, BLEN, "%5.3Fs", (float)t/ONE_SECOND_TIME); - ili9341_drawstring(buf, x, y); + lcd_printf(x, y, "%5.3Fs", (float)t/ONE_SECOND_TIME); y += YSTEP; - plot_printf(buf, BLEN, "%5.3Fs", (float)setting.additional_step_delay_us/ONE_SECOND_TIME); - ili9341_drawstring(buf, x, y); + lcd_printf(x, y, "%5.3Fs", (float)setting.additional_step_delay_us/ONE_SECOND_TIME); y += YSTEP + YSTEP/2 ; #endif #ifdef TINYSA4 if (setting.extra_lna){ ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - y = add_quick_menu("LNA:ON", x, y, (menuitem_t *)menu_level); + lcd_printf(x, y, "LNA:ON"); + y = add_quick_menu(y, (menuitem_t *)menu_level); y += YSTEP; } #endif // Cal output if (setting.refer >= 0) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Ref:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%dMHz",reffer_freq[setting.refer]/1000000); - buf[6]=0; - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_reffer); + lcd_printf(x, y, "Ref:\n%dMHz",reffer_freq[setting.refer]/1000000); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_reffer); } // Offset if (setting.external_gain != 0.0) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Amp:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.1fdB",setting.external_gain); - y = add_quick_menu(buf, x, y,(menuitem_t *)KM_EXT_GAIN); + lcd_printf(x, y, "Amp:\n%4.1fdB",setting.external_gain); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)KM_EXT_GAIN); } // Repeat if (setting.repeat != 1) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Repeat:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%d",setting.repeat); - buf[6]=0; - y = add_quick_menu(buf, x, y,(menuitem_t *)KM_REPEAT); + lcd_printf(x, y, "Repeat\n x%d", setting.repeat); + y = add_quick_menu(y+=YSTEP,( menuitem_t *)KM_REPEAT); } // Trigger @@ -3483,19 +3424,15 @@ redraw_cal_status: y += YSTEP; if (rounding) - plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)); + lcd_printf(x, y, "%6.3f", value(setting.trigger_level)); else - plot_printf(buf, BLEN, "%.4F", value(setting.trigger_level)); -// plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)/setting.unit_scale); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_trigger); + lcd_printf(x, y, "%6.4F", value(setting.trigger_level)); +// lcd_printf(x, y, "%4f", value(setting.trigger_level)/setting.unit_scale); + y = add_quick_menu(y,(menuitem_t *)menu_trigger); } // Mode - if (level_is_calibrated()) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_BRIGHT_COLOR_RED; - ili9341_set_foreground(color); + ili9341_set_foreground(level_is_calibrated() ? LCD_BRIGHT_COLOR_GREEN : LCD_BRIGHT_COLOR_RED); ili9341_drawstring_7x13(MODE_LOW(setting.mode) ? "LOW" : "HIGH", x, y); // Compact status string @@ -3557,11 +3494,6 @@ redraw_cal_status: if (!setting.waterfall) { // Do not draw bottom level if in waterfall mode // Bottom level y = area_height + OFFSETY; - if (rounding) - plot_printf(buf, BLEN, "%4d", (int)(yMax - setting.scale * NGRIDY)); - else - plot_printf(buf, BLEN, "%+4.3F", ((yMax - setting.scale * NGRIDY)/setting.unit_scale)); - // buf[5]=0; if (level_is_calibrated()) if (setting.auto_reflevel) color = LCD_FG_COLOR; @@ -3570,8 +3502,11 @@ redraw_cal_status: else color = LCD_BRIGHT_COLOR_RED; ili9341_set_foreground(color); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_average); -// ili9341_drawstring(buf, x, y); + if (rounding) + lcd_printf(x, y, "%4d", (int)(yMax - setting.scale * NGRIDY)); + else + lcd_printf(x, y, "%+4.3F", ((yMax - setting.scale * NGRIDY)/setting.unit_scale)); + y = add_quick_menu(y,(menuitem_t *)menu_average); } } From 6b730a9bea499e456a989f78cc5aa16bac883646 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 17:58:39 +0300 Subject: [PATCH 4/4] Cleanup --- ui.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ui.c b/ui.c index 2f3b054..3669a2d 100644 --- a/ui.c +++ b/ui.c @@ -1349,8 +1349,6 @@ static const uint8_t check_box[] = { _BMP16(0b0000100001000000), _BMP16(0b0000011110000000), }; -static const char *step_text[5] = {"-10dB", "-1dB", "set", "+1dB", "+10dB"}; -static char step_text_freq[5][10] = { "-100MHz", "-10MHz", "set", "+10MHz", "+100MHz" }; #ifndef MENU_USE_AUTOHEIGHT #ifdef TINYSA4 @@ -1443,19 +1441,19 @@ draw_menu_buttons(const menuitem_t *menu, int only) local_text_shift = 2; if (menu[i].data == KM_CENTER) { local_slider_positions = LCD_WIDTH/2+setting.slider_position; - plot_printf(step_text_freq[0], sizeof step_text_freq[0], "-%3.0FHz", (float)setting.slider_span); - plot_printf(step_text_freq[1], sizeof step_text_freq[1], "-%3.0FHz", (float)setting.slider_span/10); - plot_printf(step_text_freq[3], sizeof step_text_freq[3], "+%3.0FHz", (float)setting.slider_span/10); - plot_printf(step_text_freq[4], sizeof step_text_freq[4], "+%3.0FHz", (float)setting.slider_span); - for (int i=0; i <= 4; i++) { - ili9341_drawstring(step_text_freq[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9); - } + lcd_printf(button_start+12 + 0 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", -(float)setting.slider_span); + lcd_printf(button_start+12 + 1 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", -(float)setting.slider_span/10); + lcd_printf(button_start+12 + 2 * MENU_FORM_WIDTH/5, y+button_height-9, "Set"); + lcd_printf(button_start+12 + 3 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", (float)setting.slider_span/10); + lcd_printf(button_start+12 + 4 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", (float)setting.slider_span); goto draw_divider; } else if (menu[i].data == KM_LOWOUTLEVEL) { local_slider_positions = ((get_level() - level_min()) * (MENU_FORM_WIDTH-8)) / level_range() + OFFSETX+4; - for (int i=0; i <= 4; i++) { - ili9341_drawstring(step_text[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9); - } + lcd_printf(button_start+12 + 0 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", -10); + lcd_printf(button_start+12 + 1 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", -1); + lcd_printf(button_start+12 + 2 * MENU_FORM_WIDTH/5, y+button_height-9, "Set"); + lcd_printf(button_start+12 + 3 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", 1); + lcd_printf(button_start+12 + 4 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", 10); draw_divider: for (int i = 1; i <= 4; i++) { ili9341_line(button_start + i * MENU_FORM_WIDTH/5, y+button_height-9, button_start + i * MENU_FORM_WIDTH/5, y+button_height);