From 11ad1b16289774fcde0b42de507d0da9e91a3edf Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 4 Sep 2022 12:26:18 +0200 Subject: [PATCH] New is_calibrated logic and depth error message --- main.c | 7 ++++--- nanovna.h | 5 +++-- sa_core.c | 43 ++++++++++++++++--------------------------- ui_sa.c | 10 +++++----- 4 files changed, 28 insertions(+), 37 deletions(-) diff --git a/main.c b/main.c index 7bb1d9f..e9233e4 100644 --- a/main.c +++ b/main.c @@ -958,7 +958,7 @@ config_t config = { #ifdef TINYSA3 .vbat_offset = 500, .low_level_offset = 0, // Uncalibrated - .high_level_offset = 100, // Uncalibrated + .high_level_offset = 0, // Uncalibrated .correction_frequency = { { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, { 240000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 960000000 }}, #ifdef __ULTRA__ @@ -987,7 +987,7 @@ config_t config = { .low_level_offset = 0, // Uncalibrated .high_level_offset = 0, // Uncalibrated .lna_level_offset = 0, - .low_level_output_offset = 100, // Uncalibrated + .low_level_output_offset = 0, // Uncalibrated .high_level_output_offset = 0, // Uncalibrated, but checking code is not yet present .harmonic_level_offset = 10.5, .shift1_level_offset = 0.5, @@ -1032,7 +1032,8 @@ config_t config = { .cor_wfm = 0, .cor_nfm = 0, .ultra = false, - .is_calibrated = false, + .input_is_calibrated = false, + .output_is_calibrated = false, #ifndef __NEW_SWITCHES__ .high_out_adf4350 = true, #endif diff --git a/nanovna.h b/nanovna.h index 27f5723..41c9569 100644 --- a/nanovna.h +++ b/nanovna.h @@ -772,7 +772,8 @@ typedef struct config { freq_t direct_stop; int8_t ultra; #endif - uint8_t is_calibrated; + uint8_t input_is_calibrated; + uint8_t output_is_calibrated; uint8_t _mode; int8_t cor_wfm; int8_t cor_nfm; @@ -1352,7 +1353,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e5A /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e5B /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/sa_core.c b/sa_core.c index ec2b039..5655d5d 100644 --- a/sa_core.c +++ b/sa_core.c @@ -302,8 +302,8 @@ void set_output_path(freq_t f, float level) if (a > 0) { a = 0; if (!level_error) { level_error = true; redraw_request |= REDRAW_CAL_STATUS; draw_all(true);} - } else if (setting.modulation == MO_AM && a < -10) { // Insufficient headroom for modulation - if (!level_error) { level_error = true; redraw_request |= REDRAW_CAL_STATUS; draw_all(true); } +// } else if (setting.modulation == MO_AM && a < -10) { // Insufficient headroom for modulation +// if (!level_error) { level_error = true; redraw_request |= REDRAW_CAL_STATUS; draw_all(true); } } else { if (level_error) { level_error = false; redraw_request |= REDRAW_CAL_STATUS; draw_all(true); } } @@ -1193,26 +1193,11 @@ float level_range(void) #ifdef TINYSA4 float low_out_offset(void) { - if (config.low_level_output_offset == 100) - { - if (config.low_level_offset == 100) - return 0; - else - return - config.low_level_offset; - } else + if (config.output_is_calibrated) return config.low_level_output_offset; -} - -float high_out_offset(void) -{ - if (config.high_level_output_offset == 100) - { - if (config.high_level_offset == 100) - return 0; - else - return - config.high_level_offset; - } else - return config.high_level_output_offset; + if (config.input_is_calibrated) + return - config.low_level_offset; + return 0; } #endif @@ -1547,6 +1532,8 @@ float get_level_offset(void) return(config.high_level_offset); } if (setting.mode == M_LOW) { +// if (!config.input_is_calibrated) +// return 0; float lev; #ifdef TINYSA4 if (signal_path == PATH_DIRECT) { @@ -1564,7 +1551,7 @@ float get_level_offset(void) else #endif lev = config.low_level_offset; - return(lev == 100? 0 : lev); + return(lev); } if (setting.mode == M_GENLOW) { return(LOW_OUT_OFFSET); @@ -1580,7 +1567,7 @@ int level_is_calibrated(void) if (setting.mode == M_HIGH && config.high_level_offset != 100) return 1; if (setting.mode == M_LOW) { - if (!config.is_calibrated) + if (!config.input_is_calibrated) return 0; #ifdef TINYSA4 if (setting.extra_lna) { @@ -7213,9 +7200,11 @@ abort: void reset_calibration(void) { - config.is_calibrated = false; - config.low_level_offset = 100; - config.low_level_output_offset = 100; + config.input_is_calibrated = false; + config.output_is_calibrated = false; + config.low_level_offset = 0; + config.low_level_output_offset = 0; + } void calibrate_modulation(int modulation, int8_t *correction) @@ -7599,7 +7588,7 @@ void calibrate(void) } #endif - config.is_calibrated = true; + config.input_is_calibrated = true; config_save(); ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_drawstring_7x13("Calibration complete", 40, 200); diff --git a/ui_sa.c b/ui_sa.c index 7cd747d..1c29209 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -575,7 +575,7 @@ char range_text[20]; #ifdef TINYSA4 int input_is_calibrated(void) { - if (config.low_level_offset != 100) + if (!config.input_is_calibrated) return true; drawMessageBox("Error", "First calibrate 100kHz to 5.34GHz input", 2000); redraw_request|= REDRAW_AREA; @@ -584,7 +584,7 @@ int input_is_calibrated(void) int output_is_calibrated(void) { - if (config.low_level_output_offset != 100) + if (!config.output_is_calibrated) return true; drawMessageBox("Error", "First calibrate 30MHz output", 2000); redraw_request|= REDRAW_AREA; @@ -819,10 +819,10 @@ static UI_FUNCTION_ADV_CALLBACK(menu_output_level_acb) ui_mode_keypad(KM_LEVEL); if (kp_buf[0] != 0) { float old_offset = config.low_level_output_offset; - if (old_offset == 100) old_offset = 0; + if (!config.input_is_calibrated) old_offset = 0; float new_offset = uistat.value - (TEST_LEVEL) + old_offset; // calculate offset based on difference between measured peak level and known peak level - if (uistat.value == 100) new_offset = 100; - if ((new_offset > -10 && new_offset < 10) || new_offset == 100) { + if (uistat.value == 100) { new_offset = 0; config.input_is_calibrated = false; } + if (new_offset > -15 && new_offset < 15) { config.low_level_output_offset = new_offset; config_save(); }