From c136d588533581b9b1e407ef4bb1c85931cbb2d5 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 14 Jun 2020 10:33:25 +0200 Subject: [PATCH] output default off, help text improved, use %.3F format --- chprintf.c | 13 +-- nanovna.h | 4 +- plot.c | 7 +- sa_core.c | 111 +++--------------------- ui.c | 2 +- ui_sa.c | 248 +++++++++++++++++++---------------------------------- 6 files changed, 112 insertions(+), 273 deletions(-) diff --git a/chprintf.c b/chprintf.c index fbfd1cd..5e7c366 100644 --- a/chprintf.c +++ b/chprintf.c @@ -52,7 +52,7 @@ static const uint32_t pow10[FLOAT_PRECISION+1] = { static char bigPrefix[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 0}; // Prefixes for values less then 1.0 // 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-18, 1e-21, 1e-24 -static char smallPrefix[] = {'m', 0x1d, 'n', 'p', 'f', 'a', 'z', 'y', 0}; +static char smallPrefix[] = {'m', 'u', 'n', 'p', 'f', 'a', 'z', 'y', 0}; #pragma pack(pop) @@ -195,12 +195,15 @@ static char *ftoaS(char *p, float num, uint32_t precision) { ; prefix = num > 1e-3 ? ptr[-1] : 0; } + if (prefix) + precision--; + // Auto set prescision uint32_t l = num; - if (l < 10) - precision+=2; - else if (l < 100) - precision+=1; + if (l > 100) + precision-=2; + else if (l > 10) + precision-=1; p=ftoa(p, num, precision); if (prefix) *p++ = prefix; diff --git a/nanovna.h b/nanovna.h index f68e254..d0bbed3 100644 --- a/nanovna.h +++ b/nanovna.h @@ -820,9 +820,6 @@ void SI4432_SetReference(int freq); #define define_to_STR(x) STR1(x) // sa_core.c -int GetRBW(void); -int GetStorage(void); -int GetSubtractStorage(void); int get_waterfall(void); void toggle_tracking(void); void calibrate(void); @@ -841,6 +838,7 @@ void wait_user(void); void calibrate(void); float to_dBm(float); float calc_min_sweep_time(void); +extern float actual_rbw; enum { M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY diff --git a/plot.c b/plot.c index 11b7344..64fac6e 100644 --- a/plot.c +++ b/plot.c @@ -888,18 +888,17 @@ static void trace_get_value_string( // frequency_string(&buf2[1], sizeof(buf2) -1, dfreq); v = value(coeff[i]); if (mtype & M_NOISE) - v = v - 10*log10(get_actual_RBW()*1000.0); + v = v - 10*log10(actual_rbw*1000.0); if (v == -INFINITY) plot_printf(buf, len, "-INF"); else { v = v - rlevel; if (UNIT_IS_LINEAR(setting.unit)) { - plot_printf(buf3, sizeof(buf3), "%4f", v/setting.unit_scale); + plot_printf(buf3, sizeof(buf3), "%.3F", v); // 5 characters incl u,m,etc... } else { plot_printf(buf3, sizeof(buf3), "%.1f", v); } - buf3[5] = 0; - plot_printf(buf, len, "%s %s%s%s%s", buf2, buf3, unit_scale_text[setting.unit_scale_index], unit_string[setting.unit],(mtype & M_NOISE?"/Hz":"")); + plot_printf(buf, len, "%s %s%s%s", buf2, buf3, unit_string[setting.unit],(mtype & M_NOISE?"/Hz":"")); } } diff --git a/sa_core.c b/sa_core.c index 5a4743c..d655e53 100644 --- a/sa_core.c +++ b/sa_core.c @@ -59,7 +59,7 @@ void reset_settings(int m) trace[TRACE_STORED].enabled = false; trace[TRACE_TEMP].enabled = false; setting.refer = -1; - setting.mute = false; + setting.mute = true; #ifdef __SPUR__ setting.spur = 0; #endif @@ -142,11 +142,6 @@ void set_refer_output(int v) dirty = true; } -int get_refer_output(void) -{ - return(setting.refer); -} - void set_decay(int d) { if (d < 0 || d > 200) @@ -249,13 +244,6 @@ void set_IF(int f) dirty = true; } -int GetMode(void) -{ - return(setting.mode); - dirty = true; -} - - #define POWER_STEP 0 // Should be 5 dB but appearently it is lower #define POWER_OFFSET 15 #define SWITCH_ATTENUATION 30 @@ -339,11 +327,6 @@ void set_storage(void) dirty = true; } -int GetStorage(void) -{ - return(setting.show_stored); -} - void set_clear_storage(void) { setting.show_stored = false; @@ -364,11 +347,6 @@ void set_subtract_storage(void) dirty = true; } -int GetSubtractStorage(void) -{ - return(setting.subtract_stored); -} - extern float peakLevel; void set_actual_power(float o) { @@ -417,16 +395,6 @@ void set_RBW(int v) dirty = true; } -int GetRBW(void) -{ - return(setting.rbw); -} - -int get_actual_RBW(void) -{ - return((int) actual_rbw); -} - #ifdef __SPUR__ void SetSpur(int v) { @@ -466,11 +434,6 @@ void set_average(int v) dirty = true; } -int GetAverage(void) -{ - return(setting.average); -} - void toggle_LNA(void) { if (S_IS_AUTO(setting.lna )) @@ -495,16 +458,6 @@ void toggle_tracking(void) dirty = true; } -int GetExtraVFO(void) -{ - return(setting.tracking); -} - -int GetLNA(void) -{ - return(setting.lna); -} - void toggle_AGC(void) { if (S_IS_AUTO(setting.agc )) @@ -516,11 +469,6 @@ void toggle_AGC(void) dirty = true; } -int GetAGC(void) -{ - return(setting.agc); -} - void set_unit(int u) { if (setting.unit == u) @@ -579,13 +527,6 @@ void set_reflevel(float level) level = REFLEVEL_MIN; if (level > REFLEVEL_MAX) level = REFLEVEL_MAX; -#if 0 - float s = setting.scale; - if (level < NGRIDY * s) { // Never negative bottom - set_scale(level/NGRIDY); - level = setting.scale * NGRIDY; - } -#endif } setting.unit_scale_index = 0; @@ -660,20 +601,6 @@ void set_scale(float t) { set_trace_scale(1, t); set_trace_scale(2, t); round_reflevel_to_scale(); - -#if 0 - if (UNIT_IS_LINEAR(setting.unit)) { // Never negative bottom - float r = setting.reflevel; - t = NGRIDY * t; - if (t > r) { - setting.reflevel = t; - set_trace_refpos(0, t); - set_trace_refpos(1, t); - set_trace_refpos(2, t); - } - } -#endif - // set_reflevel(setting.reflevel); redraw_request |= REDRAW_AREA | REDRAW_CAL_STATUS; } @@ -739,12 +666,6 @@ void apply_settings(void) PE4302_Write_Byte(40); // Ensure defined input impedance of low port when using high input mode (power calibration) else PE4302_Write_Byte(setting.attenuate * 2); -#if 0 - if (setting.modulation == MO_NONE) { - SI4432_Write_Byte(0x73, 0); // Back to nominal offset - SI4432_Write_Byte(0x74, 0); - } -#endif SI4432_SetReference(setting.refer); update_rbw(); if (setting.frequency_step == 0.0) { @@ -1925,23 +1846,12 @@ void draw_cal_status(void) ili9341_set_background(DEFAULT_BG_COLOR); float yMax = setting.reflevel; // Determine unit scale letter ( ,m,u,n,p) -#if 0 // moved to set_reflevel - setting.unit_scale_index = 0; - setting.unit_scale = 1.0; - while (UNIT_IS_LINEAR(setting.unit) && setting.unit_scale_index < sizeof(unit_scale_value)/sizeof(float) - 1) { - if (yMax > unit_scale_value[setting.unit_scale_index]) - break; - setting.unit_scale_index++; - } - setting.unit_scale = unit_scale_value[setting.unit_scale_index]; -#endif - // Top level if (rounding) plot_printf(buf, BLEN, "%4d", (int)yMax); else - plot_printf(buf, BLEN, "%4f", (yMax/setting.unit_scale)+0.00005); - buf[5]=0; + plot_printf(buf, BLEN, "%.3F", (yMax/setting.unit_scale)); +// buf[5]=0; if (level_is_calibrated()) { if (setting.auto_reflevel) color = DEFAULT_FG_COLOR; @@ -1970,6 +1880,7 @@ void draw_cal_status(void) color = DEFAULT_FG_COLOR; ili9341_set_foreground(color); y += YSTEP + YSTEP/2; +#if 1 unsigned int i = 0; while (i < sizeof(scale_value)/sizeof(float)) { float t = (setting.scale/setting.unit_scale) / scale_value[i];; @@ -1979,11 +1890,8 @@ void draw_cal_status(void) } i++; } -#if 0 - if (rounding) - plot_printf(buf, BLEN, "%5d/",(int)setting.scale); - else - plot_printf(buf, BLEN, "%5f/",setting.scale); +#else + plot_printf(buf, BLEN, "%.2F/",setting.scale); #endif ili9341_drawstring(buf, x, y); @@ -2132,7 +2040,8 @@ void draw_cal_status(void) if (rounding) plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)); else - plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)/setting.unit_scale); + plot_printf(buf, BLEN, "%.4F", value(setting.trigger_level)); +// plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)/setting.unit_scale); buf[6]=0; ili9341_drawstring(buf, x, y); } @@ -2193,8 +2102,8 @@ void draw_cal_status(void) if (rounding) plot_printf(buf, BLEN, "%4d", (int)(yMax - setting.scale * NGRIDY)); else - plot_printf(buf, BLEN, "%4f", ((yMax - setting.scale * NGRIDY)/setting.unit_scale)+0.0005); - buf[5]=0; + plot_printf(buf, BLEN, "%.3F", ((yMax - setting.scale * NGRIDY)/setting.unit_scale)); +// buf[5]=0; if (level_is_calibrated()) if (setting.auto_reflevel) color = DEFAULT_FG_COLOR; diff --git a/ui.c b/ui.c index 5737e62..3002ba8 100644 --- a/ui.c +++ b/ui.c @@ -1240,6 +1240,7 @@ menu_invoke(int item) area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; redraw_frame(); // Remove form numbers } + kp_help_text = (char *)menu->reference; ui_mode_keypad(menu->data); ui_process_keypad(); } @@ -1877,7 +1878,6 @@ ui_mode_keypad(int _keypad_mode) draw_menu(); draw_keypad(); draw_numeric_area_frame(); - fetch_numeric_target(); draw_numeric_input(""); } diff --git a/ui_sa.c b/ui_sa.c index 9dc7584..d2fe6a7 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -588,7 +588,7 @@ void menu_autosettings_cb(int item, uint8_t data) { (void)item; (void)data; - reset_settings(GetMode()); + reset_settings(setting.mode); active_marker = 0; for (int i = 1; i