diff --git a/main.c b/main.c index 27f25d5..749f6c4 100644 --- a/main.c +++ b/main.c @@ -2305,6 +2305,7 @@ static const VNAShellCommand commands[] = { "mode", cmd_mode, 0 }, { "spur", cmd_spur, 0 }, { "load", cmd_load, 0 }, + { "output", cmd_output, 0 }, { "selftest", cmd_selftest, 0 }, { "correction", cmd_correction, 0 }, #ifdef ENABLE_THREADS_COMMAND @@ -2323,6 +2324,7 @@ static const VNAShellCommand commands[] = { "w", cmd_w, 0 }, { "o", cmd_o, 0 }, { "d", cmd_d, 0 }, + { "f", cmd_f, 0 }, #ifdef __ULTRA_SA__ { "x", cmd_x, 0 }, #endif @@ -2687,8 +2689,8 @@ int main(void) sweep(true); set_refer_output(-1); - ui_mode_menu(); // Show menu when autostarting mode - +// ui_mode_menu(); // Show menu when autostarting mode + ui_mode_normal(); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); diff --git a/nanovna.h b/nanovna.h index babf46d..121b3fd 100644 --- a/nanovna.h +++ b/nanovna.h @@ -158,6 +158,8 @@ enum { #define SWEEP_CALIBRATE 0x04 #define SWEEP_SELFTEST 0x08 #define SWEEP_REMOTE 0x10 +//#define SWEEP_FACTORY 0x20 + extern int8_t sweep_mode; extern bool completed; diff --git a/plot.c b/plot.c index 94bcb11..bbcba5e 100644 --- a/plot.c +++ b/plot.c @@ -1708,10 +1708,10 @@ draw_all(bool flush) markmap_upperarea(); if (redraw_request & (REDRAW_CELLS | REDRAW_MARKER | REDRAW_AREA)) draw_all_cells(flush); + if (redraw_request & (REDRAW_CAL_STATUS | REDRAW_FREQUENCY) ) + draw_cal_status(); // calculates the actual sweep time, must be before draw_frequencies if (redraw_request & REDRAW_FREQUENCY) draw_frequencies(); - if (redraw_request & REDRAW_CAL_STATUS) - draw_cal_status(); if (redraw_request & REDRAW_BATTERY) draw_battery_status(); redraw_request = 0; diff --git a/sa_cmd.c b/sa_cmd.c index af50c4f..f8c8fd6 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -84,6 +84,22 @@ VNA_SHELL_FUNCTION(cmd_spur) goto usage; } +VNA_SHELL_FUNCTION(cmd_output) +{ + if (argc != 1) { + usage: + shell_printf("usage: output on|off\r\n"); + return; + } + if (strcmp(argv[0],"on") == 0) { + setting.mute = false; + } else if (strcmp(argv[0],"off") == 0) { + setting.mute = true; + } else + goto usage; + dirty = true; +} + VNA_SHELL_FUNCTION(cmd_load) { if (argc != 1) { @@ -110,8 +126,8 @@ VNA_SHELL_FUNCTION(cmd_attenuate) set_auto_attenuation(); } else { int a = my_atoi(argv[0]); - if (a < 0 || a>31) - goto usage; +// if (a < 0 || a>31) +// goto usage; set_attenuation(a); } } @@ -436,6 +452,14 @@ return; set_RBW(p); } +VNA_SHELL_FUNCTION(cmd_f) +{ + (void)argc; + setting.test = 5; + setting.test_argument = my_atoi(argv[0]);; + sweep_mode = SWEEP_SELFTEST; +} + VNA_SHELL_FUNCTION(cmd_correction) { (void)argc; diff --git a/sa_core.c b/sa_core.c index 60a560d..15d7f61 100644 --- a/sa_core.c +++ b/sa_core.c @@ -311,20 +311,18 @@ void set_level(float v) void set_attenuation(float a) { if (setting.mode == M_GENLOW) { - setting.drive = 8; // Start at lowest drive level; a = a + POWER_OFFSET; - if (a > 0) { - setting.drive++; + if (a > 6) { // +9dB + setting.drive = 11; // Maximum save drive for SAW filters. + a = a - 9; + } else if (a > 3) { // +6dB + setting.drive = 10; + a = a - 6; + } else if (a > 0) { // +3dB + setting.drive = 9; a = a - 3; - } - if (a > 0) { - setting.drive++; - a = a - 3; - } - if (a > 0) { - setting.drive++; - a = a - 3; - } + } else + setting.drive = 8; // defined as 0dB level if (a > 0) a = 0; if( a > - SWITCH_ATTENUATION) { @@ -687,6 +685,7 @@ void set_mode(int m) if (setting.mode == m) return; reset_settings(m); +// dirty = true; } void apply_settings(void) @@ -1123,7 +1122,12 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) } if (setting.mode == M_GENLOW && setting.level_sweep != 0.0) { - float a = ((int)((setting.level + (i / 290.0) * setting.level_sweep)*2.0 + 0.5)) / 2.0; + float ls=setting.level_sweep; + if (ls > 0) + ls += 0.5; + else + ls -= 0.5; + float a = ((int)((setting.level + (i / 290.0) * ls)*2.0)) / 2.0; if (a != old_a) { old_a = a; int d = 0; // Start at lowest drive level; @@ -1607,7 +1611,7 @@ again: //if (setting.scale * NGRIDY > r) set_scale(r / NGRIDY); set_reflevel(setting.scale*NGRIDY); - dirty = false; // Prevent reset of SI4432 + // dirty = false; // Prevent reset of SI4432 redraw_request |= REDRAW_CAL_STATUS; } } @@ -1627,7 +1631,7 @@ again: redraw_request |= REDRAW_CAL_STATUS; // dirty = true; // Must be above if(scandirty!!!!!) } - dirty = false; // Prevent reset of SI4432 + // dirty = false; // Prevent reset of SI4432 } } #if 1 @@ -1953,19 +1957,20 @@ void draw_cal_status(void) #endif ili9341_drawstring(buf, x, y); - // Attenuation - if (setting.auto_attenuation) - color = DEFAULT_FG_COLOR; - else - color = BRIGHT_COLOR_GREEN; - ili9341_set_foreground(color); - y += YSTEP + YSTEP/2 ; - ili9341_drawstring("Attn:", x, y); - - y += YSTEP; - plot_printf(buf, BLEN, "%.2FdB", setting.attenuate); - buf[6]=0; - ili9341_drawstring(buf, x, y); + if (setting.mode == M_LOW) { + // Attenuation + if (setting.auto_attenuation) + color = DEFAULT_FG_COLOR; + else + color = BRIGHT_COLOR_GREEN; + ili9341_set_foreground(color); + y += YSTEP + YSTEP/2 ; + ili9341_drawstring("Attn:", x, y); + y += YSTEP; + plot_printf(buf, BLEN, "%.2FdB", setting.attenuate); + buf[6]=0; + ili9341_drawstring(buf, x, y); + } // Average if (setting.average>0) { @@ -2647,6 +2652,43 @@ void self_test(int test) set_refer_output(-1); reset_settings(M_LOW); in_selftest = false; + } else if (test == 5) { +// reset_settings(M_LOW); // Make sure we are in a defined state + in_selftest = true; + switch (setting.test_argument) { + case 0: + touch_draw_test(); + area_width = AREA_WIDTH_NORMAL; + area_height = AREA_HEIGHT_NORMAL; + break; + case 1: + reset_settings(M_LOW); + set_sweep_frequency(ST_START, 0); + set_sweep_frequency(ST_STOP, 50000000); + break; + case 2: + reset_settings(M_LOW); + set_sweep_frequency(ST_START, 300000000); + set_sweep_frequency(ST_STOP, 350000000); + break; + case 3: + reset_settings(M_HIGH); + set_sweep_frequency(ST_START, 300000000); + set_sweep_frequency(ST_STOP, 350000000); + break; + case 4: + reset_settings(M_GENLOW); + set_sweep_frequency(ST_CENTER, 20000000); + set_sweep_frequency(ST_SPAN, 0); + setting.mute = false; + break; + case 5: + reset_settings(M_GENHIGH); + set_sweep_frequency(ST_CENTER, 320000000); + set_sweep_frequency(ST_SPAN, 0); + break; + } + in_selftest = false; } } diff --git a/ui.c b/ui.c index 1125bc0..2ac502b 100644 --- a/ui.c +++ b/ui.c @@ -359,7 +359,20 @@ touch_draw_test(void) ili9341_clear_screen(); ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, 233); - touch_wait_pressed(); +// touch_wait_pressed(); + + int old_button_state = 0; + while (touch_check() != EVT_TOUCH_PRESSED) { + int button_state = READ_PORT() & BUTTON_MASK; + if (button_state != old_button_state) { + char buf[20]; + plot_printf(buf, sizeof buf, "STATE: %4d ", button_state); + ili9341_drawstring_7x13(buf, 120, 120); + old_button_state = button_state; + } + + } + touch_position(&x0, &y0); do {