diff --git a/main.c b/main.c index 1312fbb..b73e16c 100644 --- a/main.c +++ b/main.c @@ -2462,7 +2462,7 @@ static const VNAShellCommand commands[] = { "ultra_start", cmd_ultra_start, CMD_WAIT_MUTEX }, #endif { "load", cmd_load, 0 }, - { "offset", cmd_offset, 0}, + { "ext_gain", cmd_ext_gain, 0}, { "output", cmd_output, 0 }, { "deviceid", cmd_deviceid, 0 }, { "selftest", cmd_selftest, 0 }, diff --git a/nanovna.h b/nanovna.h index 5841763..8b15090 100644 --- a/nanovna.h +++ b/nanovna.h @@ -69,9 +69,9 @@ #define __QUASI_PEAK__ // Add quasi peak average option #define __REMOTE_DESKTOP__ // Add remote desktop option #define __LISTEN__ -#ifdef TINYSA4 #define __CHANNEL_POWER__ #define __LIMITS__ +#ifdef TINYSA4 #define __HARMONIC__ #else #endif @@ -917,7 +917,7 @@ typedef struct setting uint8_t measurement; // enum uint8_t spur_removal; // enum - int8_t tracking; // -1...1 !!! need convert to bool + int8_t tracking; // -1...1 Can NOT convert to bool!!!!!! uint8_t atten_step; // 0...1 !!! need convert to bool int8_t _active_marker; // -1...MARKER_MAX uint8_t unit_scale_index; // table index @@ -956,7 +956,7 @@ typedef struct setting float reflevel; float scale; - float offset; + float external_gain; float trigger_level; float level; float level_sweep; @@ -1287,7 +1287,7 @@ void toggle_tracking(void); void toggle_hambands(void); void reset_calibration(void); void set_reflevel(float); -void set_offset(float); +void set_external_gain(float); void set_unit(int); void set_switches(int); void set_gridlines(int); diff --git a/plot.c b/plot.c index 8d0af5f..7fc5b1c 100644 --- a/plot.c +++ b/plot.c @@ -1300,16 +1300,16 @@ static void cell_draw_marker_info(int x0, int y0) } #ifdef __CHANNEL_POWER__ if (setting.measurement==M_CP) { - char *p_label[3] = { "Left", "Mid", "Right" }; for (int c=0; c<3;c++) { - if (c == 1) - plot_printf(buf, sizeof buf, "%s: %4.1fdB %4.1f%%", p_label[c], channel_power[1], 100.0 * (channel_power_watt[1] - channel_power_watt[0] - channel_power_watt[2]) /channel_power_watt[1] ); - else - plot_printf(buf, sizeof buf, "%s: %4.1fdB", p_label[c], channel_power[c]); + plot_printf(buf, sizeof buf, "%4.1fdB", channel_power[c]); int xpos = 10 + (c)*(WIDTH/3) + CELLOFFSETX - x0; int ypos = 1 - y0; ili9341_set_foreground(LCD_FG_COLOR); cell_drawstring_7x13(buf, xpos, ypos); + plot_printf(buf, sizeof buf, "%4.1f%%", 100.0 * channel_power_watt[c] /(channel_power_watt[0] + channel_power_watt[1] + channel_power_watt[2]) ); + ypos = 14 - y0; + ili9341_set_foreground(LCD_FG_COLOR); + cell_drawstring_7x13(buf, xpos, ypos); } return; } @@ -1449,8 +1449,8 @@ static void cell_draw_marker_info(int x0, int y0) ili9341_set_background(LCD_BG_COLOR); uint16_t color; if ((!setting.subtract_stored) && // Disabled when normalized - ((setting.mode == M_LOW && temppeakLevel - get_attenuation() + setting.offset > -10) || - (setting.mode == M_HIGH && temppeakLevel - get_attenuation()+ setting.offset > -29) )) + ((setting.mode == M_LOW && temppeakLevel - get_attenuation() > -10) || // Ignore external_gain in overload detection + (setting.mode == M_HIGH && temppeakLevel - get_attenuation() > -29) )) color = LCD_BRIGHT_COLOR_RED; else color = marker_color(markers[i].mtype); diff --git a/sa_cmd.c b/sa_cmd.c index 59c775e..b08b05d 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -267,14 +267,14 @@ VNA_SHELL_FUNCTION(cmd_sweeptime) -VNA_SHELL_FUNCTION(cmd_offset) +VNA_SHELL_FUNCTION(cmd_ext_gain) { if (argc != 1) { - shell_printf("usage: offset -100.0..+100.0\r\n"); + shell_printf("usage: ext_gain -100.0..+100.0\r\n"); return; } float o = my_atof(argv[0]); - set_offset(o); + set_external_gain(o); } diff --git a/sa_core.c b/sa_core.c index 34bf7dd..fcf5214 100644 --- a/sa_core.c +++ b/sa_core.c @@ -225,8 +225,8 @@ void reset_settings(int m) setting.frequency_IF = DEFAULT_IF; #endif setting.auto_IF = true; - set_offset(0.0); // This also updates the help text!!!!! - //setting.offset = 0.0; + set_external_gain(0.0); // This also updates the help text!!!!! + //setting.external_gain = 0.0; setting.trigger = T_AUTO; setting.trigger_direction = T_UP; setting.trigger_mode = T_MID; @@ -1212,13 +1212,13 @@ void set_scale(float t) { extern char low_level_help_text[12]; -void set_offset(float offset) +void set_external_gain(float external_gain) { - setting.offset = offset; + setting.external_gain = external_gain; int min,max; min = level_min; max = min + level_range; - plot_printf(low_level_help_text, sizeof low_level_help_text, "%+d..%+d", min + (int)offset, max + (int)offset); + plot_printf(low_level_help_text, sizeof low_level_help_text, "%+d..%+d", min + (int)external_gain, max + (int)external_gain); redraw_request|=REDRAW_AREA; dirty = true; // No HW update required, only status panel refresh but need to ensure the cached value is updated in the calculation of the RSSI } @@ -2242,7 +2242,7 @@ static void calculate_static_correction(void) // Calculate the - (S_STATE(setting.lna)? 0 : 0) + (setting.extra_lna ? -23.0 : 0) // TODO <------------------------- set correct value #endif - - setting.offset); + - setting.external_gain); } int hsical = -1; @@ -3454,7 +3454,7 @@ sweep_again: // stay in sweep loop when output mo setting.atten_step = false; // No step attenuate in low mode auto attenuate int changed = false; int delta = 0; - int actual_max_level = (max_index[0] == 0 ? -100 :(int) (actual_t[max_index[0]] - get_attenuation()) ); // If no max found reduce attenuation + int actual_max_level = (max_index[0] == 0 ? -100 :(int) (actual_t[max_index[0]] - get_attenuation()) ) - setting.external_gain; // If no max found reduce attenuation if (actual_max_level < AUTO_TARGET_LEVEL && setting.attenuate_x2 > 0) { delta = - (AUTO_TARGET_LEVEL - actual_max_level); } else if (actual_max_level > AUTO_TARGET_LEVEL && setting.attenuate_x2 < 60) { @@ -3497,7 +3497,7 @@ sweep_again: // stay in sweep loop when output mo #ifdef __SI4432__ if (!in_selftest && MODE_INPUT(setting.mode)) { if (S_IS_AUTO(setting.agc)) { - int actual_max_level = actual_t[max_index[0]] - get_attenuation(); // No need to use float + int actual_max_level = actual_t[max_index[0]] - get_attenuation() - setting.external_gain; // No need to use float if (UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode if (actual_max_level > - 45) auto_set_AGC_LNA(false, 0); // Strong signal, no AGC and no LNA @@ -3693,7 +3693,7 @@ sweep_again: // stay in sweep loop when output mo } else if (setting.measurement == M_AM) { // ----------------AM measurement if (S_IS_AUTO(setting.agc )) { #ifdef __SI4432__ - int actual_level = actual_t[max_index[0]] - get_attenuation(); // no need for float + int actual_level = actual_t[max_index[0]] - get_attenuation() - setting.external_gain; // no need for float if (actual_level > -20 ) { setting.agc = S_AUTO_OFF; setting.lna = S_AUTO_OFF; diff --git a/ui.c b/ui.c index 3e75cc7..a2e5eee 100644 --- a/ui.c +++ b/ui.c @@ -2072,7 +2072,7 @@ menu_select_touch(int i, int pos) check_frequency_slider(slider_freq); } } else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_LOWOUTLEVEL) { - uistat.value = setting.offset + ((touch_x - OFFSETX+4) * level_range ) / (MENU_FORM_WIDTH-8) + level_min ; + uistat.value = setting.external_gain + ((touch_x - OFFSETX+4) * level_range ) / (MENU_FORM_WIDTH-8) + level_min ; apply_step: set_keypad_value(keypad); apply: @@ -2112,7 +2112,7 @@ menu_select_touch(int i, int pos) step = +10; break; } - uistat.value = setting.offset + get_level() + step; + uistat.value = setting.external_gain + get_level() + step; do_exit = true; goto apply_step; } else if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_CENTER) { diff --git a/ui_sa.c b/ui_sa.c index edaeaa4..56d8987 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -411,7 +411,7 @@ enum { KM_10MHZ, #endif // #15 - KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, + KM_REPEAT, KM_EXT_GAIN, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, // #20 KM_OFFSET_DELAY, KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION, // #25 @@ -453,7 +453,7 @@ static const struct { {keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE {keypads_freq , "FREQ"}, // KM_30MHz | KM_10MHz {keypads_positive , "SAMPLE\nREPEAT"}, // KM_REPEA #15 - {keypads_plusmin , "OFFSET"}, // KM_OFFSET + {keypads_plusmin , "EXT\nGAIN"}, // KM_EXT_GAIN {keypads_plusmin_unit, "TRIGGER\nLEVEL"}, // KM_TRIGGER {keypads_plusmin , "LEVEL\nSWEEP"}, // KM_LEVELSWEEP {keypads_time , "SWEEP\nSECONDS"}, // KM_SWEEP_TIME @@ -818,7 +818,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_sdrive_acb){ #ifdef TINYSA4 b->param_1.i = setting.lo_drive; #else - b->param_1.i = drive_dBm[setting.lo_drive] + (setting.mode==M_GENHIGH ? setting.offset : 0); + b->param_1.i = drive_dBm[setting.lo_drive] + (setting.mode==M_GENHIGH ? setting.external_gain : 0); #endif return; } @@ -1677,7 +1677,7 @@ static const menuitem_t menu_lowoutputmode[] = { // { MT_FORM | MT_KEYPAD, KM_SPAN, "SPAN: %s", "0..350MHz"}, // { MT_FORM | MT_KEYPAD | MT_LOW, KM_LEVELSWEEP,"LEVEL CHANGE: %s", "-70..70"}, // { MT_FORM | MT_KEYPAD, KM_SWEEP_TIME, "SWEEP TIME: %s", "0..600 seconds"}, - { MT_FORM | MT_KEYPAD, KM_OFFSET, "EXTERNAL AMP: %s", "-100..+100"}, + { MT_FORM | MT_KEYPAD, KM_EXT_GAIN, "EXTERNAL AMP: %s", "-100..+100"}, { MT_FORM | MT_CANCEL, 0, "MODE", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1697,7 +1697,7 @@ static const menuitem_t menu_highoutputmode[] = { { MT_FORM | MT_KEYPAD, KM_SPAN, "SPAN: %s", NULL}, { MT_FORM | MT_KEYPAD, KM_SWEEP_TIME,"SWEEP TIME: %s", "0..600 seconds"}, #endif - { MT_FORM | MT_KEYPAD, KM_OFFSET, "EXTERNAL AMP: %s", "-100..+100"}, + { MT_FORM | MT_KEYPAD, KM_EXT_GAIN, "EXTERNAL AMP: %s", "-100..+100"}, { MT_FORM | MT_CANCEL, 0, "MODE", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; @@ -2200,7 +2200,7 @@ static const menuitem_t menu_level[] = { { MT_SUBMENU, 0, "ATTENUATE", menu_atten}, // { MT_SUBMENU,0, "CALC", menu_average}, { MT_SUBMENU, 0, "UNIT", menu_unit}, - { MT_KEYPAD, KM_OFFSET, "EXTERNAL\nAMP",NULL}, + { MT_KEYPAD, KM_EXT_GAIN, "EXTERNAL\nAMP",NULL}, #ifdef TINYSA4 { MT_ADV_CALLBACK | MT_LOW ,0,"LNA", menu_extra_lna_acb}, #endif @@ -2367,8 +2367,8 @@ static void fetch_numeric_target(void) end_level = level_min; if (end_level > level_max) end_level = level_max; - uistat.value += setting.offset; - end_level += setting.offset; + uistat.value += setting.external_gain; + end_level += setting.external_gain; if (setting.level_sweep != 0) plot_printf(uistat.text, sizeof uistat.text, "%.1f to %.1fdBm", uistat.value, end_level); else @@ -2376,7 +2376,7 @@ static void fetch_numeric_target(void) break; case KM_HIGHOUTLEVEL: uistat.value = get_level(); // compensation for dB offset during low output mode - uistat.value += setting.offset; + uistat.value += setting.external_gain; plot_printf(uistat.text, sizeof uistat.text, "%.1fdBm", uistat.value); break; case KM_DECAY: @@ -2420,8 +2420,8 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0); break; #endif - case KM_OFFSET: - uistat.value = setting.offset; + case KM_EXT_GAIN: + uistat.value = setting.external_gain; plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); break; case KM_LEVELSWEEP: @@ -2533,10 +2533,10 @@ set_numeric_value(void) set_repeat(uistat.value); break; case KM_LOWOUTLEVEL: - set_level(uistat.value - setting.offset); + set_level(uistat.value - setting.external_gain); break; case KM_HIGHOUTLEVEL: - set_level(uistat.value - setting.offset); + set_level(uistat.value - setting.external_gain); break; case KM_DECAY: set_decay(uistat.value); @@ -2574,8 +2574,8 @@ set_numeric_value(void) set_10mhz(uistat.value); break; #endif - case KM_OFFSET: - set_offset(uistat.value); + case KM_EXT_GAIN: + set_external_gain(uistat.value); break; case KM_LEVELSWEEP: setting.modulation = MO_NONE; @@ -2925,12 +2925,12 @@ redraw_cal_status: } // Offset - if (setting.offset != 0.0) { + 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.offset); - y = add_quick_menu(buf, x, y,(menuitem_t *)KM_OFFSET); + plot_printf(buf, BLEN, "%.1fdB",setting.external_gain); + y = add_quick_menu(buf, x, y,(menuitem_t *)KM_EXT_GAIN); } // Repeat