From 2898c02d36a77a7a2eb6805da350e5cc35248a95 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 27 Apr 2020 16:17:08 +0200 Subject: [PATCH] Load/Store of settings added --- STM32F072xB.ld | 4 +- flash.c | 48 +++-- main.c | 149 +++++++------- nanovna.h | 132 ++++++++---- plot.c | 4 +- sa_core.c | 546 ++++++++++++++++++++++++------------------------- si4432.c | 16 +- ui.c | 5 +- ui_sa.c | 153 +++++++++----- 9 files changed, 591 insertions(+), 466 deletions(-) diff --git a/STM32F072xB.ld b/STM32F072xB.ld index b1f2ea2..8f7b034 100644 --- a/STM32F072xB.ld +++ b/STM32F072xB.ld @@ -19,14 +19,14 @@ */ MEMORY { - flash0 : org = 0x08000000, len = 104k + flash0 : org = 0x08000000, len = 108k flash1 : org = 0x00000000, len = 0 flash2 : org = 0x00000000, len = 0 flash3 : org = 0x00000000, len = 0 flash4 : org = 0x00000000, len = 0 flash5 : org = 0x00000000, len = 0 flash6 : org = 0x00000000, len = 0 - flash7 : org = 0x0801C000, len = 16k + flash7 : org = 0x0801B000, len = 20k ram0 : org = 0x20000000, len = 16k ram1 : org = 0x00000000, len = 0 ram2 : org = 0x00000000, len = 0 diff --git a/flash.c b/flash.c index a66315d..46251e1 100644 --- a/flash.c +++ b/flash.c @@ -120,48 +120,54 @@ config_recall(void) return 0; } -const uint32_t saveareas[SAVEAREA_MAX] = { +const uint32_t saveareas[SAVEAREA_MAX] = +{ SAVE_PROP_CONFIG_0_ADDR, SAVE_PROP_CONFIG_1_ADDR, SAVE_PROP_CONFIG_2_ADDR, SAVE_PROP_CONFIG_3_ADDR, - SAVE_PROP_CONFIG_4_ADDR }; + SAVE_PROP_CONFIG_4_ADDR, + SAVE_PROP_CONFIG_5_ADDR, + SAVE_PROP_CONFIG_6_ADDR, + SAVE_PROP_CONFIG_7_ADDR, + SAVE_PROP_CONFIG_8_ADDR, +}; int16_t lastsaveid = 0; int caldata_save(int id) { - uint16_t *src = (uint16_t*)¤t_props; + uint16_t *src = (uint16_t*)&setting; uint16_t *dst; - int count = sizeof(properties_t) / sizeof(uint16_t); + int count = sizeof(setting_t) / sizeof(uint16_t); if (id < 0 || id >= SAVEAREA_MAX) return -1; dst = (uint16_t*)saveareas[id]; - current_props.magic = CONFIG_MAGIC; - current_props.checksum = checksum( - ¤t_props, sizeof current_props - sizeof current_props.checksum); + setting.magic = CONFIG_MAGIC; + setting.checksum = checksum( + &setting, sizeof setting - sizeof setting.checksum); flash_unlock(); /* erase flash pages */ void *p = dst; - void *tail = p + sizeof(properties_t); + void *tail = p + sizeof(setting_t); while (p < tail) { flash_erase_page((uint32_t)p); p += FLASH_PAGESIZE; } - /* write to flahs */ + /* write to flash */ while (count-- > 0) { flash_program_half_word((uint32_t)dst, *src++); dst++; } /* after saving data, make active configuration points to flash */ - active_props = (properties_t*)saveareas[id]; +// active_props = (setting_t*)saveareas[id]; lastsaveid = id; return 0; @@ -170,14 +176,14 @@ caldata_save(int id) int caldata_recall(int id) { - properties_t *src; - void *dst = ¤t_props; + setting_t *src; + void *dst = &setting; if (id < 0 || id >= SAVEAREA_MAX) goto load_default; // point to saved area on the flash memory - src = (properties_t*)saveareas[id]; + src = (setting_t*)saveareas[id]; if (src->magic != CONFIG_MAGIC) goto load_default; @@ -185,24 +191,27 @@ caldata_recall(int id) goto load_default; /* active configuration points to save data on flash memory */ - active_props = src; +// active_props = src; lastsaveid = id; /* duplicated saved data onto sram to be able to modify marker/trace */ - memcpy(dst, src, sizeof(properties_t)); + memcpy(dst, src, sizeof(setting_t)); + update_frequencies(); + SetScale(setting.scale); + SetReflevel(setting.reflevel); return 0; load_default: load_default_properties(); return -1; } - -const properties_t * +#if 0 +const setting_t * caldata_ref(int id) { - const properties_t *src; + const setting_t *src; if (id < 0 || id >= SAVEAREA_MAX) return NULL; - src = (const properties_t*)saveareas[id]; + src = (const setting_t*)saveareas[id]; if (src->magic != CONFIG_MAGIC) return NULL; @@ -210,6 +219,7 @@ caldata_ref(int id) return NULL; return src; } +#endif const uint32_t save_config_prop_area_size = SAVE_CONFIG_AREA_SIZE; diff --git a/main.c b/main.c index 42f137d..8025ecb 100644 --- a/main.c +++ b/main.c @@ -89,7 +89,7 @@ static void apply_error_term_at(int i); static void apply_edelay_at(int i); static void cal_interpolate(int s); #endif -static void update_frequencies(void); +void update_frequencies(void); static void set_frequencies(uint32_t start, uint32_t stop, uint16_t points); static bool sweep(bool break_on_operation); #ifdef __VNA__ @@ -110,7 +110,7 @@ volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags const char *info_about[]={ BOARD_NAME, "2016-2020 Copyright @Erik Kaashoek", - "Licensed under GPL. See: https://github.com/erikkaashoek/tinySA", + "SW licensed under GPL. See: https://github.com/erikkaashoek/tinySA", "Version: " VERSION, "Build Time: " __DATE__ " - " __TIME__, "Kernel: " CH_KERNEL_VERSION, @@ -135,7 +135,7 @@ static THD_FUNCTION(Thread1, arg) sweep_mode&=~SWEEP_ONCE; } else if (sweep_mode & SWEEP_SELFTEST) { // call from lowest level to save stack space - self_test(setting_test); + self_test(setting.test); sweep_mode = SWEEP_ENABLE; } else if (sweep_mode & SWEEP_CALIBRATE) { // call from lowest level to save stack space @@ -821,8 +821,8 @@ config_t config = { .high_level_offset = 100, // Uncalibrated }; -properties_t current_props; -properties_t *active_props = ¤t_props; +//properties_t current_props; +//properties_t *active_props = ¤t_props; // NanoVNA Default settings static const trace_t def_trace[TRACES_MAX] = {//enable, type, channel, reserved, scale, refpos @@ -843,43 +843,44 @@ void load_default_properties(void) { //Magic add on caldata_save //current_props.magic = CONFIG_MAGIC; - current_props._frequency0 = 0; // start = 0Hz - current_props._frequency1 = 350000000; // end = 350MHz - current_props._frequency_IF= 433800000, +// current_props._setting.frequency0 = 0; // start = 0Hz +// current_props._setting.frequency1 = 350000000; // end = 350MHz +// current_props._setting.frequency_IF= 433800000, - current_props._sweep_points = POINTS_COUNT; + setting._sweep_points = POINTS_COUNT; #ifdef VNA__ - current_props._cal_status = 0; + setting._cal_status = 0; //This data not loaded by default -//current_props._frequencies[POINTS_COUNT]; -//current_props._cal_data[5][POINTS_COUNT][2]; +//setting._frequencies[POINTS_COUNT]; +//setting._cal_data[5][POINTS_COUNT][2]; //============================================= - current_props._electrical_delay = 0.0; + setting._electrical_delay = 0.0; #endif - memcpy(current_props._trace, def_trace, sizeof(def_trace)); - memcpy(current_props._markers, def_markers, sizeof(def_markers)); + memcpy(setting._trace, def_trace, sizeof(def_trace)); + memcpy(setting._markers, def_markers, sizeof(def_markers)); #ifdef __VNA__ - current_props._velocity_factor = 0.7; + setting._velocity_factor = 0.7; #endif - current_props._active_marker = 0; + setting._active_marker = 0; #ifdef __VNA__ - current_props._domain_mode = 0; - current_props._marker_smith_format = MS_RLC; + setting._domain_mode = 0; + setting._marker_smith_format = MS_RLC; #endif + reset_settings(-1); //Checksum add on caldata_save -//current_props.checksum = 0; +//setting.checksum = 0; } void ensure_edit_config(void) { +#ifdef __VNA__ if (active_props == ¤t_props) return; //memcpy(¤t_props, active_props, sizeof(config_t)); active_props = ¤t_props; // move to uncal state -#ifdef __VNA__ cal_status = 0; #endif } @@ -1029,11 +1030,11 @@ set_frequencies(uint32_t start, uint32_t stop, uint16_t points) // disable at out of sweep range for (; i < POINTS_COUNT; i++) frequencies[i] = 0; - setting_frequency_step = delta; + setting.frequency_step = delta; update_rbw(); } -static void +void update_frequencies(void) { uint32_t start, stop; @@ -1065,55 +1066,55 @@ set_sweep_frequency(int type, uint32_t freq) ensure_edit_config(); switch (type) { case ST_START: - config.freq_mode &= ~FREQ_MODE_CENTER_SPAN; - if (frequency0 != freq) { - frequency0 = freq; + setting.freq_mode &= ~FREQ_MODE_CENTER_SPAN; + if (setting.frequency0 != freq) { + setting.frequency0 = freq; // if start > stop then make start = stop - if (frequency1 < freq) frequency1 = freq; + if (setting.frequency1 < freq) setting.frequency1 = freq; } break; case ST_STOP: - config.freq_mode &= ~FREQ_MODE_CENTER_SPAN; - if (frequency1 != freq) { - frequency1 = freq; + setting.freq_mode &= ~FREQ_MODE_CENTER_SPAN; + if (setting.frequency1 != freq) { + setting.frequency1 = freq; // if start > stop then make start = stop - if (frequency0 > freq) frequency0 = freq; + if (setting.frequency0 > freq) setting.frequency0 = freq; } break; case ST_CENTER: - config.freq_mode |= FREQ_MODE_CENTER_SPAN; - uint32_t center = frequency0 / 2 + frequency1 / 2; + setting.freq_mode |= FREQ_MODE_CENTER_SPAN; + uint32_t center = setting.frequency0 / 2 + setting.frequency1 / 2; if (center != freq) { - uint32_t span = frequency1 - frequency0; + uint32_t span = setting.frequency1 - setting.frequency0; if (freq < START_MIN + span / 2) { span = (freq - START_MIN) * 2; } if (freq > STOP_MAX - span / 2) { span = (STOP_MAX - freq) * 2; } - frequency0 = freq - span / 2; - frequency1 = freq + span / 2; + setting.frequency0 = freq - span / 2; + setting.frequency1 = freq + span / 2; } break; case ST_SPAN: - config.freq_mode |= FREQ_MODE_CENTER_SPAN; - if (frequency1 - frequency0 != freq) { - uint32_t center = frequency0 / 2 + frequency1 / 2; + setting.freq_mode |= FREQ_MODE_CENTER_SPAN; + if (setting.frequency1 - setting.frequency0 != freq) { + uint32_t center = setting.frequency0 / 2 + setting.frequency1 / 2; if (center < START_MIN + freq / 2) { center = START_MIN + freq / 2; } if (center > STOP_MAX - freq / 2) { center = STOP_MAX - freq / 2; } - frequency0 = center - freq / 2; - frequency1 = center + freq / 2; + setting.frequency0 = center - freq / 2; + setting.frequency1 = center + freq / 2; } break; case ST_CW: - config.freq_mode |= FREQ_MODE_CENTER_SPAN; - if (frequency0 != freq || frequency1 != freq) { - frequency0 = freq; - frequency1 = freq; + setting.freq_mode |= FREQ_MODE_CENTER_SPAN; + if (setting.frequency0 != freq || setting.frequency1 != freq) { + setting.frequency0 = freq; + setting.frequency1 = freq; } break; } @@ -1128,17 +1129,17 @@ uint32_t get_sweep_frequency(int type) { // Obsolete, ensure correct start/stop, start always must be < stop - if (frequency0 > frequency1) { - uint32_t t = frequency0; - frequency0 = frequency1; - frequency1 = t; + if (setting.frequency0 > setting.frequency1) { + uint32_t t = setting.frequency0; + setting.frequency0 = setting.frequency1; + setting.frequency1 = t; } switch (type) { - case ST_START: return frequency0; - case ST_STOP: return frequency1; - case ST_CENTER: return frequency0/2 + frequency1/2; - case ST_SPAN: return frequency1 - frequency0; - case ST_CW: return frequency0; + case ST_START: return setting.frequency0; + case ST_STOP: return setting.frequency1; + case ST_CENTER: return setting.frequency0/2 + setting.frequency1/2; + case ST_SPAN: return setting.frequency1 - setting.frequency0; + case ST_CW: return setting.frequency0; } return 0; } @@ -2242,7 +2243,7 @@ VNA_SHELL_FUNCTION(cmd_selftest) shell_printf("usage: selftest (1-3)\r\n"); return; } - setting_test = my_atoi(argv[0]); + setting.test = my_atoi(argv[0]); sweep_mode = SWEEP_SELFTEST; } @@ -2292,7 +2293,7 @@ VNA_SHELL_FUNCTION(cmd_o) return; uint32_t value = my_atoi(argv[0]); // if (VFO == 0) -// frequency_IF = value; +// setting.frequency_IF = value; setFreq(VFO, value); } @@ -2300,7 +2301,7 @@ VNA_SHELL_FUNCTION(cmd_d) { (void) argc; int32_t a = my_atoi(argv[0]); - setting_drive = a; + setting.drive = a; } @@ -2327,11 +2328,11 @@ VNA_SHELL_FUNCTION(cmd_t) VNA_SHELL_FUNCTION(cmd_e) { (void)argc; - setting_tracking = my_atoi(argv[0]); - if (setting_tracking == -1) - setting_tracking = false; + setting.tracking = my_atoi(argv[0]); + if (setting.tracking == -1) + setting.tracking = false; else - setting_tracking = true; + setting.tracking = true; if (argc >1) frequencyExtra = my_atoi(argv[1]); @@ -2349,25 +2350,25 @@ VNA_SHELL_FUNCTION(cmd_m) (void)argv; SetMode(0); - setting_tracking = false; //Default test setup - setting_step_atten = false; + setting.tracking = false; //Default test setup + setting.step_atten = false; SetAttenuation(0); SetReflevel(-10); - set_sweep_frequency(ST_START,frequencyStart - frequency_IF ); - set_sweep_frequency(ST_STOP, frequencyStop - frequency_IF); + set_sweep_frequency(ST_START,frequencyStart - setting.frequency_IF ); + set_sweep_frequency(ST_STOP, frequencyStop - setting.frequency_IF); draw_cal_status(); pause_sweep(); int32_t f_step = (frequencyStop-frequencyStart)/ points; palClearPad(GPIOB, GPIOB_LED); // disable led and wait for voltage stabilization - int old_step = setting_frequency_step; - setting_frequency_step = f_step; + int old_step = setting.frequency_step; + setting.frequency_step = f_step; update_rbw(); chThdSleepMilliseconds(10); streamPut(shell_stream, '{'); dirty = true; for (int i = 0; i_cal_data #define electrical_delay current_props._electrical_delay #endif -#define trace current_props._trace -#define markers current_props._markers -#define active_marker current_props._active_marker +#define trace setting._trace +#define markers setting._markers +#define active_marker setting._active_marker #ifdef __VNA__ #define domain_mode current_props._domain_mode #define velocity_factor current_props._velocity_factor @@ -541,14 +602,12 @@ extern properties_t current_props; #define bandwidth current_props._bandwidth #endif -#define FREQ_IS_STARTSTOP() (!(config.freq_mode&FREQ_MODE_CENTER_SPAN)) -#define FREQ_IS_CENTERSPAN() (config.freq_mode&FREQ_MODE_CENTER_SPAN) -#define FREQ_IS_CW() (frequency0 == frequency1) +#define FREQ_IS_STARTSTOP() (!(setting.freq_mode&FREQ_MODE_CENTER_SPAN)) +#define FREQ_IS_CENTERSPAN() (setting.freq_mode&FREQ_MODE_CENTER_SPAN) +#define FREQ_IS_CW() (setting.frequency0 == setting.frequency1) int caldata_recall(int id); -#ifdef __VNA__ int caldata_save(int id); -const properties_t *caldata_ref(int id); -#endif +//const properties_t *caldata_ref(int id); int config_save(void); int config_recall(void); @@ -561,6 +620,9 @@ extern void ui_init(void); extern void ui_process(void); int current_menu_is_form(void); +void menu_mode_cb(int, uint8_t); +void ui_mode_normal(void); + // Irq operation process set #define OP_NONE 0x00 #define OP_LEVER 0x01 @@ -622,11 +684,11 @@ int16_t adc_vbat_read(void); */ int plot_printf(char *str, int, const char *fmt, ...); #define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0) -extern int setting_attenuate; -extern int settingPowerCal; -extern int setting_step_delay; -extern int actualStepDelay; -extern int setting_mode; +//extern int setting_attenuate; +//extern int settingPowerCal; +//extern int setting_step_delay; +//extern int actualStepDelay; +//extern int setting_mode; void update_rbw(void); int GetActualRBW(void); @@ -660,9 +722,9 @@ void SetReflevel(int); void SetScale(int); void SetRBW(int); void SetRX(int); -extern int setting_measurement; +//extern int setting_measurement; void self_test(int); -extern int setting_test; +//extern int setting_test; void wait_user(void); void calibrate(void); diff --git a/plot.c b/plot.c index 14669f1..3ee76d3 100644 --- a/plot.c +++ b/plot.c @@ -1907,7 +1907,7 @@ static void cell_draw_marker_info(int x0, int y0) } } for (int i = 0; i < MARKER_COUNT; i++) { - if (i >= 2 && setting_measurement == M_OIP3 && markers[2].enabled && markers[3].enabled) { + if (i >= 2 && setting.measurement == M_OIP3 && markers[2].enabled && markers[3].enabled) { float il = logmag(&(actual_t[markers[2].index])); float ir = logmag(&(actual_t[markers[3].index])); float sl = logmag(&(actual_t[markers[0].index])); @@ -2031,7 +2031,7 @@ draw_frequencies(void) { char buf1[32]; char buf2[32]; buf2[0] = 0; - if (MODE_OUTPUT(setting_mode)) // No frequencies during output + if (MODE_OUTPUT(setting.mode)) // No frequencies during output return; if (current_menu_is_form() && !in_selftest) return; diff --git a/sa_core.c b/sa_core.c index c26a5af..d2ec817 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1,111 +1,120 @@ #include "SI4432.h" // comment out for simulation -int setting_mode = -1; // To force initialzation +int dirty = true; +int scandirty = true; +#if 0 +int setting.mode = -1; // To force initialzation +int setting.attenuate = 0; +int setting.auto_attenuation; +int setting.step_atten; +int setting.rbw = 0; +int setting.below_IF; +int setting.average = 0; +int setting.show_stored = 0; +int setting.subtract_stored = 0; +int setting.drive; // 0-7 , 7=+20dBm, 3dB steps +int setting.agc = true; +int setting.lna = false; +int setting.auto_reflevel; +int setting.reflevel; +int setting.scale; +int setting.tracking = false; +int setting.modulation = MO_NONE; +int setting.step_delay = 0; +int setting.frequency_step; +int setting.test; +int setting.harmonic; +int setting.decay; +int setting.noise; +float setting.vbw = 0; +int setting.tracking_output; +int setting.repeat; +uint32_t setting.frequency0; +uint32_t setting.frequency1; +uint32_t setting.setting.frequency_IF; +int setting.measurement; +#endif +extern int actualStepDelay; +setting_t setting; +uint32_t frequencies[POINTS_COUNT]; -int dirty = true; -int scandirty = true; -int setting_attenuate = 0; -int setting_auto_attenuation; -int setting_step_atten; -int setting_rbw = 0; -int setting_below_IF; -int setting_average = 0; -int setting_show_stored = 0; -int setting_subtract_stored = 0; -int setting_drive; // 0-7 , 7=+20dBm, 3dB steps -int setting_agc = true; -int setting_lna = false; -int setting_auto_reflevel; -int setting_reflevel; -int setting_scale; -int setting_tracking = false; -int setting_modulation = MO_NONE; -int setting_step_delay = 0; -int setting_frequency_step; -int setting_test; -int setting_harmonic; -int setting_decay; -int setting_noise; float actual_rbw = 0; -float setting_vbw = 0; -int setting_tracking_output; -int setting_repeat; -uint32_t setting_frequency0; -uint32_t setting_frequency1; -uint32_t setting_frequency_IF; -int setting_measurement; + int vbwSteps = 1; #ifdef __ULTRA__ -int setting_spur = 0; +int setting.spur = 0; #endif float minFreq = 0; float maxFreq = 520000000; -int setting_refer = -1; // Off by default +//int setting.refer = -1; // Off by default const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; int in_selftest = false; void reset_settings(int m) { - setting_mode = m; + setting.mode = m; SetScale(10); SetReflevel(-10); - setting_attenuate = 0; - setting_rbw = 0; - setting_average = 0; - setting_harmonic = 0; - setting_show_stored = 0; - setting_auto_attenuation = true; - setting_subtract_stored = 0; - setting_drive=15; - setting_step_atten = 0; // Only used in low output mode - setting_agc = true; - setting_lna = false; - setting_tracking = false; - setting_modulation = MO_NONE; - setting_step_delay = 0; - setting_vbw = 0; - setting_auto_reflevel = true; // Must be after SetReflevel - setting_decay=20; - setting_noise=5; - setting_below_IF = false; - setting_repeat = 1; - setting_tracking_output = false; + setting.attenuate = 0; + setting.rbw = 0; + setting.average = 0; + setting.harmonic = 0; + setting.show_stored = 0; + setting.auto_attenuation = true; + setting.subtract_stored = 0; + setting.drive=13; + setting.step_atten = 0; // Only used in low output mode + setting.agc = true; + setting.lna = false; + setting.tracking = false; + setting.modulation = MO_NONE; + setting.step_delay = 0; + setting.vbw = 0; + setting.auto_reflevel = true; // Must be after SetReflevel + setting.decay=20; + setting.noise=5; + setting.below_IF = false; + setting.repeat = 1; + setting.tracking_output = false; + setting.measurement = M_OFF; + setting.frequency_IF = 433800000; trace[TRACE_STORED].enabled = false; trace[TRACE_TEMP].enabled = false; - - setting_measurement = M_OFF; -#ifdef __ULTRA__ - setting_spur = 0; + #ifdef __ULTRA__ + setting.spur = 0; #endif switch(m) { + case -1: + setting.refer = -1; // Clear cal signal when no autostart + break; case M_LOW: minFreq = 0; maxFreq = 520000000; set_sweep_frequency(ST_START, (uint32_t) 0); set_sweep_frequency(ST_STOP, (uint32_t) 350000000); - setting_attenuate = 30; + setting.attenuate = 30; break; #ifdef __ULTRA__ case M_ULTRA: minFreq = 870000000; - if (setting_harmonic * 240000000 > 870000000) - minFreq = setting_harmonic * 240000000; - if (setting_harmonic == 0) + if (setting.harmonic * 240000000 > 870000000) + minFreq = setting.harmonic * 240000000; + if (setting.harmonic == 0) maxFreq = 4360000000; else - maxFreq = 960000000 * setting_harmonic; + maxFreq = 960000000 * setting.harmonic; set_sweep_frequency(ST_START, (uint32_t) minFreq); set_sweep_frequency(ST_STOP, (uint32_t) maxFreq); - setting_attenuate = 0; + setting.attenuate = 0; break; #endif case M_GENLOW: - setting_drive=8; + setting.drive=8; minFreq = 0; maxFreq = 520000000; set_sweep_frequency(ST_CENTER, (int32_t) 10000000); @@ -123,7 +132,7 @@ void reset_settings(int m) set_sweep_frequency(ST_STOP, (int32_t) maxFreq); break; case M_GENHIGH: - setting_drive=8; + setting.drive=8; minFreq = 240000000; maxFreq = 960000000; set_sweep_frequency(ST_CENTER, (int32_t) 300000000); @@ -140,33 +149,22 @@ void reset_settings(int m) dirty = true; } -void menu_load_preset_cb(int item, uint8_t data) -{ - -} - -void menu_store_preset_cb(int item, uint8_t data) -{ - -} - - void set_refer_output(int v) { - setting_refer = v; + setting.refer = v; dirty = true; } int get_refer_output(void) { - return(setting_refer); + return(setting.refer); } void set_decay(int d) { if (d < 0 || d > 200) return; - setting_decay = d; + setting.decay = d; dirty = true; } @@ -174,61 +172,61 @@ void set_noise(int d) { if (d < 2 || d > 50) return; - setting_noise = d; + setting.noise = d; dirty = true; } void set_measurement(int m) { - setting_measurement = m; + setting.measurement = m; dirty = true; } void SetDrive(int d) { - setting_drive = d; + setting.drive = d; dirty = true; } void set_tracking_output(int t) { - setting_tracking_output = t; + setting.tracking_output = t; dirty = true; } void toggle_tracking_output(void) { - setting_tracking_output = !setting_tracking_output; + setting.tracking_output = !setting.tracking_output; dirty = true; } void toggle_below_IF(void) { - setting_below_IF = !setting_below_IF; + setting.below_IF = !setting.below_IF; dirty = true; } void SetModulation(int m) { - setting_modulation = m; + setting.modulation = m; dirty = true; } void set_repeat(int r) { if (r > 0 && r < 50) { - setting_repeat = r; + setting.repeat = r; dirty = true; } } void SetIF(int f) { - frequency_IF = f; + setting.frequency_IF = f; dirty = true; } int GetMode(void) { - return(setting_mode); + return(setting.mode); dirty = true; } @@ -239,62 +237,62 @@ int GetMode(void) int GetAttenuation(void) { - if (setting_mode == M_GENLOW) { - if (setting_step_atten) - return ( -(POWER_OFFSET + setting_attenuate - (setting_step_atten-1)*POWER_STEP + SWITCH_ATTENUATION)); + if (setting.mode == M_GENLOW) { + if (setting.step_atten) + return ( -(POWER_OFFSET + setting.attenuate - (setting.step_atten-1)*POWER_STEP + SWITCH_ATTENUATION)); else - return ( -POWER_OFFSET - setting_attenuate + (setting_drive & 7) * 3); + return ( -POWER_OFFSET - setting.attenuate + (setting.drive & 7) * 3); } - return(setting_attenuate); + return(setting.attenuate); } void set_auto_attenuation(void) { - setting_auto_attenuation = true; - setting_attenuate = 30; + setting.auto_attenuation = true; + setting.attenuate = 30; } void set_auto_reflevel(void) { - setting_auto_reflevel = true; + setting.auto_reflevel = true; } void SetAttenuation(int a) { - if (setting_mode == M_GENLOW) { - setting_drive = 8; // Start at lowest drive level; + if (setting.mode == M_GENLOW) { + setting.drive = 8; // Start at lowest drive level; a = a + POWER_OFFSET; if (a > 0) { - setting_drive++; + setting.drive++; a = a - 3; } if (a > 0) { - setting_drive++; + setting.drive++; a = a - 3; } if (a > 0) { - setting_drive++; + setting.drive++; a = a - 3; } if (a > 0) a = 0; if( a > - SWITCH_ATTENUATION) { - setting_step_atten = 0; + setting.step_atten = 0; } else { a = a + SWITCH_ATTENUATION; - setting_step_atten = 1; + setting.step_atten = 1; } a = -a; } else { - setting_step_atten = 0; + setting.step_atten = 0; } if (a<0) a = 0; if (a> 31) a=31; -// if (setting_attenuate == a) +// if (setting.attenuate == a) // return; - setting_attenuate = a; + setting.attenuate = a; dirty = true; } @@ -302,52 +300,52 @@ void SetStorage(void) { for (int i=0; i 360) + setting.spur = v; + if (setting.spur && actual_rbw > 360) SetRBW(300); dirty = true; } @@ -411,71 +409,71 @@ void SetSpur(int v) void set_harmonic(int h) { - setting_harmonic = h; + setting.harmonic = h; minFreq = 870000000; - if (setting_harmonic * 240000000 > 870000000) - minFreq = setting_harmonic * 240000000; + if (setting.harmonic * 240000000 > 870000000) + minFreq = setting.harmonic * 240000000; maxFreq = 4360000000; - if (setting_harmonic != 0 && 960000000.0 * setting_harmonic < 4360000000.0) - maxFreq = ((uint32_t)960000000) * (uint32_t)setting_harmonic; + if (setting.harmonic != 0 && 960000000.0 * setting.harmonic < 4360000000.0) + maxFreq = ((uint32_t)960000000) * (uint32_t)setting.harmonic; set_sweep_frequency(ST_START, (uint32_t) minFreq); set_sweep_frequency(ST_STOP, (uint32_t) maxFreq); } void SetStepDelay(int d) { - setting_step_delay = d; + setting.step_delay = d; dirty = true; } void SetAverage(int v) { - setting_average = v; + setting.average = v; trace[TRACE_TEMP].enabled = (v != 0); dirty = true; } int GetAverage(void) { - return(setting_average); + return(setting.average); } void ToggleLNA(void) { - setting_lna = !setting_lna; + setting.lna = !setting.lna; dirty = true; } void toggle_tracking(void) { - setting_tracking = !setting_tracking; + setting.tracking = !setting.tracking; dirty = true; } int GetExtraVFO(void) { - return(setting_tracking); + return(setting.tracking); } int GetLNA(void) { - return(setting_lna); + return(setting.lna); } void ToggleAGC(void) { - setting_agc = !setting_agc; + setting.agc = !setting.agc; dirty = true; } int GetAGC(void) { - return(setting_agc); + return(setting.agc); } void SetReflevel(int level) { - setting_reflevel = (level / setting_scale) * setting_scale; + setting.reflevel = (level / setting.scale) * setting.scale; set_trace_refpos(0, NGRIDY - level / get_trace_scale(0)); set_trace_refpos(1, NGRIDY - level / get_trace_scale(0)); set_trace_refpos(2, NGRIDY - level / get_trace_scale(0)); @@ -487,7 +485,7 @@ void SetReflevel(int level) //} void SetScale(int s) { - setting_scale = s; + setting.scale = s; set_trace_scale(0, s); set_trace_scale(1, s); set_trace_scale(2, s); @@ -502,22 +500,22 @@ void SetMode(int m) if (m == 6) m = M_ULTRA; #endif - if (setting_mode == m) + if (setting.mode == m) return; reset_settings(m); } void apply_settings(void) { - if (setting_mode == M_HIGH) + if (setting.mode == M_HIGH) PE4302_Write_Byte(40); else - PE4302_Write_Byte(setting_attenuate * 2); + PE4302_Write_Byte(setting.attenuate * 2); #if 0 - if (setting_modulation == MO_NFM ) { + if (setting.modulation == MO_NFM ) { SI4432_Sel = 1; SI4432_Write_Byte(0x7A, 1); // Use frequency hopping channel width for FM modulation - } else if (setting_modulation == MO_WFM ) { + } else if (setting.modulation == MO_WFM ) { SI4432_Sel = 1; SI4432_Write_Byte(0x7A, 10); // Use frequency hopping channel width for FM modulation } else { @@ -525,10 +523,10 @@ void apply_settings(void) SI4432_Write_Byte(0x79, 0); // IF no FM back to channel 0 } #endif - SetRX(setting_mode); - SI4432_SetReference(setting_refer); + SetRX(setting.mode); + SI4432_SetReference(setting.refer); update_rbw(); - if (setting_step_delay == 0){ + if (setting.step_delay == 0){ if (actual_rbw > 90.0) actualStepDelay = 400; else if (actual_rbw > 75.0) actualStepDelay = 550; else if (actual_rbw > 56.0) actualStepDelay = 650; @@ -538,7 +536,7 @@ void apply_settings(void) else if (actual_rbw > 5.0) actualStepDelay = 3500; else actualStepDelay = 6000; } else - actualStepDelay = setting_step_delay; + actualStepDelay = setting.step_delay; } //------------------------------------------ @@ -592,8 +590,8 @@ void SetSwitchOff(void) { void SetAGCLNA(void) { unsigned char v = 0x40; - if (setting_agc) v |= 0x20; - if (setting_lna) v |= 0x10; + if (setting.agc) v |= 0x20; + if (setting.lna) v |= 0x10; SI4432_Write_Byte(0x69, v); } @@ -606,7 +604,7 @@ case M_ULTRA: #endif SI4432_Sel = 0; SI4432_Receive(); - if (setting_step_atten) { + if (setting.step_atten) { SetSwitchTransmit(); } else { SetSwitchReceive(); @@ -614,13 +612,13 @@ case M_ULTRA: SetAGCLNA(); SI4432_Sel = 1; - if (setting_tracking_output) + if (setting.tracking_output) SetSwitchTransmit(); else SetSwitchOff(); // SI4432_Receive(); For noise testing only - SI4432_Transmit(setting_drive); - // SI4432_SetReference(setting_refer); + SI4432_Transmit(setting.drive); + // SI4432_SetReference(setting.refer); break; case M_HIGH: // Direct into 1 // SI4432_SetReference(-1); // Stop reference output @@ -636,15 +634,15 @@ case M_HIGH: // Direct into 1 break; case M_GENLOW: // Mixed output from 0 SI4432_Sel = 0; - if (setting_step_atten) { + if (setting.step_atten) { SetSwitchOff(); } else { SetSwitchTransmit(); } - SI4432_Transmit(setting_drive); + SI4432_Transmit(setting.drive); SI4432_Sel = 1; - if (setting_modulation == MO_EXTERNAL) { + if (setting.modulation == MO_EXTERNAL) { SetSwitchTransmit(); // High input for external LO scuh as tracking output of other tinySA SI4432_Receive(); } else { @@ -658,12 +656,12 @@ case M_GENHIGH: // Direct output from 1 SetSwitchReceive(); SI4432_Sel = 1; - if (setting_drive < 8) { + if (setting.drive < 8) { SetSwitchOff(); } else { SetSwitchTransmit(); } - SI4432_Transmit(setting_drive); + SI4432_Transmit(setting.drive); break; } @@ -675,20 +673,20 @@ case M_GENHIGH: // Direct output from 1 void update_rbw(void) { - setting_vbw = (setting_frequency_step)/1000.0; - actual_rbw = setting_rbw; + setting.vbw = (setting.frequency_step)/1000.0; + actual_rbw = setting.rbw; // float old_rbw = actual_rbw; if (actual_rbw == 0) - actual_rbw = 2*setting_vbw; + actual_rbw = 2*setting.vbw; if (actual_rbw < 2.6) actual_rbw = 2.6; if (actual_rbw > 600) actual_rbw = 600; - SI4432_Sel = MODE_SELECT(setting_mode); + SI4432_Sel = MODE_SELECT(setting.mode); actual_rbw = SI4432_SET_RBW(actual_rbw); - vbwSteps = ((int)(2 * setting_vbw / actual_rbw)); + vbwSteps = ((int)(2 * setting.vbw / actual_rbw)); if (vbwSteps < 1) vbwSteps = 1; @@ -740,7 +738,7 @@ search_maximum(int m, int center, int span) if (temppeakLevel > actual_t[i]) { // Follow down temppeakIndex = i; // Latest minimum temppeakLevel = actual_t[i]; - } else if (temppeakLevel + setting_noise < actual_t[i]) { // Local minimum found + } else if (temppeakLevel + setting.noise < actual_t[i]) { // Local minimum found temppeakIndex = i; // This is now the latest maximum temppeakLevel = actual_t[i]; downslope = false; @@ -749,7 +747,7 @@ search_maximum(int m, int center, int span) if (temppeakLevel < actual_t[i]) { // Follow up temppeakIndex = i; temppeakLevel = actual_t[i]; - } else if (temppeakLevel - setting_noise > actual_t[i]) { // Local max found + } else if (temppeakLevel - setting.noise > actual_t[i]) { // Local max found found = true; int j = 0; // Insertion index @@ -893,7 +891,7 @@ int avoid_spur(int f) // int window = ((int)actual_rbw ) * 1000*2; // if (window < 50000) // window = 50000; - if (! setting_mode == M_LOW || frequency_IF != spur_IF || actual_rbw > 300.0) + if (! setting.mode == M_LOW || setting.frequency_IF != spur_IF || actual_rbw > 300.0) return(false); return binary_search(f); #if 0 @@ -917,28 +915,28 @@ char age[POINTS_COUNT]; float perform(bool break_on_operation, int i, uint32_t f, int tracking) { long local_IF; - if (MODE_HIGH(setting_mode)) + if (MODE_HIGH(setting.mode)) local_IF = 0; else - local_IF = frequency_IF; + local_IF = setting.frequency_IF; if (i == 0 && dirty) { apply_settings(); scandirty = true; dirty = false; } - if (MODE_OUTPUT(setting_mode) && setting_modulation == MO_AM) { - int p = setting_attenuate * 2 + modulation_counter; + if (MODE_OUTPUT(setting.mode) && setting.modulation == MO_AM) { + int p = setting.attenuate * 2 + modulation_counter; PE4302_Write_Byte(p); if (modulation_counter == 3) modulation_counter = 0; else modulation_counter++; chThdSleepMicroseconds(250); - } else if (MODE_OUTPUT(setting_mode) && (setting_modulation == MO_NFM || setting_modulation == MO_WFM )) { + } else if (MODE_OUTPUT(setting.mode) && (setting.modulation == MO_NFM || setting.modulation == MO_WFM )) { SI4432_Sel = 1; int offset; - if (setting_modulation == MO_NFM ) { + if (setting.modulation == MO_NFM ) { offset = modulation_counter ; SI4432_Write_Byte(0x73, (offset & 0xff )); // Use frequency hopping channel for FM modulation SI4432_Write_Byte(0x74, ((offset >> 8) & 0x03 )); // Use frequency hopping channel for FM modulation @@ -965,23 +963,23 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) float spur_RSSI = 0; again: #endif - if (setting_mode == M_LOW && tracking) { - setFreq (0, frequency_IF + lf - reffer_freq[setting_refer]); // Offset so fundamental of reffer is visible - local_IF = frequency_IF ; - } else if (MODE_LOW(setting_mode)) { - if (setting_mode == M_LOW && !in_selftest && avoid_spur(f)) { + if (setting.mode == M_LOW && tracking) { + setFreq (0, setting.frequency_IF + lf - reffer_freq[setting.refer]); // Offset so fundamental of reffer is visible + local_IF = setting.frequency_IF ; + } else if (MODE_LOW(setting.mode)) { + if (setting.mode == M_LOW && !in_selftest && avoid_spur(f)) { local_IF = spur_alternate_IF; } else { -// local_IF = frequency_IF ; +// local_IF = setting.frequency_IF ; } - if (setting_mode == M_GENLOW && setting_modulation == MO_EXTERNAL) + if (setting.mode == M_GENLOW && setting.modulation == MO_EXTERNAL) local_IF += lf; setFreq (0, local_IF); #ifdef __ULTRA__ - } else if (setting_mode == M_ULTRA) { - local_IF = frequency_IF + (int)(actual_rbw < 350.0 ? setting_spur*300000 : 0 ); + } else if (setting.mode == M_ULTRA) { + local_IF = setting.frequency_IF + (int)(actual_rbw < 350.0 ? setting.spur*300000 : 0 ); setFreq (0, local_IF); - // local_IF = frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw:0); + // local_IF = setting.frequency_IF + (int)(actual_rbw < 300.0?setting.spur * 1000 * actual_rbw:0); #endif } else local_IF= 0; @@ -992,7 +990,7 @@ again: } #endif #ifdef __ULTRA__ - if (setting_mode == M_ULTRA) { + if (setting.mode == M_ULTRA) { // if (lf > 3406000000 ) // setFreq (1, local_IF/5 + lf/5); // else @@ -1014,33 +1012,33 @@ again: setFreq (2, IF_2 + lf); setFreq (1, 433800000); #else - if (setting_mode == M_LOW && !setting_tracking && setting_below_IF) + if (setting.mode == M_LOW && !setting.tracking && setting.below_IF) setFreq (1, local_IF-lf); else setFreq (1, local_IF+lf); #endif } - if (MODE_OUTPUT(setting_mode)) // No substepping in output mode + if (MODE_OUTPUT(setting.mode)) // No substepping in output mode return(0); float signal_path_loss; #ifdef __ULTRA__ - if (setting_mode == M_ULTRA) + if (setting.mode == M_ULTRA) signal_path_loss = -15; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2 else #endif - if (setting_mode == M_LOW) + if (setting.mode == M_LOW) signal_path_loss = -5.5; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2 else signal_path_loss = +7; // Loss in dB (+ is gain) - float subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting_mode))+settingLevelOffset()+ setting_attenuate - signal_path_loss; + float subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode))+settingLevelOffset()+ setting.attenuate - signal_path_loss; #ifdef __ULTRA__ - if (setting_spur == 1) { // First pass + if (setting.spur == 1) { // First pass spur_RSSI = subRSSI; - setting_spur = -1; + setting.spur = -1; goto again; // Skip all other processing - } else if (setting_spur == -1) { // Second pass + } else if (setting.spur == -1) { // Second pass subRSSI = ( subRSSI < spur_RSSI ? subRSSI : spur_RSSI); // Minimum of two passes - setting_spur = 1; + setting.spur = 1; } #endif @@ -1067,27 +1065,27 @@ static bool sweep(bool break_on_operation) float temp_min_level = 100; // spur_old_stepdelay = 0; for (int i = 0; i < sweep_points; i++) { - RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking); + RSSI = perform(break_on_operation, i, frequencies[i], setting.tracking); // back to toplevel to handle ui operation if (operation_requested && break_on_operation) return false; - if (MODE_OUTPUT(setting_mode) && setting_modulation == MO_NONE) { + if (MODE_OUTPUT(setting.mode) && setting.modulation == MO_NONE) { osalThreadSleepMilliseconds(10); } - if (MODE_INPUT(setting_mode)) { + if (MODE_INPUT(setting.mode)) { temp_t[i] = RSSI; - if (setting_subtract_stored) { + if (setting.subtract_stored) { RSSI = RSSI - stored_t[i] ; } // stored_t[i] = (SI4432_Read_Byte(0x69) & 0x0f) * 3.0 - 90.0; // Display the AGC value in thestored trace - if (scandirty || setting_average == AV_OFF) { + if (scandirty || setting.average == AV_OFF) { actual_t[i] = RSSI; age[i] = 0; } else { - switch(setting_average) { + switch(setting.average) { case AV_MIN: if (actual_t[i] > RSSI) actual_t[i] = RSSI; break; case AV_MAX_HOLD: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; case AV_MAX_DECAY: @@ -1095,7 +1093,7 @@ static bool sweep(bool break_on_operation) actual_t[i] = RSSI; age[i] = 0; } else { - if (age[i] > setting_decay) + if (age[i] > setting.decay) actual_t[i] -= 0.5; else age[i] += 1; @@ -1118,7 +1116,7 @@ static bool sweep(bool break_on_operation) if (temppeakLevel > actual_t[i]) { // Follow down temppeakIndex = i; // Latest minimum temppeakLevel = actual_t[i]; - } else if (temppeakLevel + setting_noise < actual_t[i] ) { // Local minimum found + } else if (temppeakLevel + setting.noise < actual_t[i] ) { // Local minimum found temppeakIndex = i; // This is now the latest maximum temppeakLevel = actual_t[i]; downslope = false; @@ -1127,7 +1125,7 @@ static bool sweep(bool break_on_operation) if (temppeakLevel < actual_t[i]) { // Follow up temppeakIndex = i; temppeakLevel = actual_t[i]; - } else if (actual_t[i] < temppeakLevel - setting_noise) { // Local max found + } else if (actual_t[i] < temppeakLevel - setting.noise) { // Local max found int j = 0; // Insertion index while (j= temppeakLevel) // Find where to insert @@ -1169,34 +1167,34 @@ static bool sweep(bool break_on_operation) scandirty = false; draw_cal_status(); } - if (!in_selftest && setting_mode == M_LOW && setting_auto_attenuation && max_index[0] > 0) { - if (actual_t[max_index[0]] - setting_attenuate < - 3*setting_scale && setting_attenuate >= setting_scale) { - setting_attenuate -= setting_scale; + if (!in_selftest && setting.mode == M_LOW && setting.auto_attenuation && max_index[0] > 0) { + if (actual_t[max_index[0]] - setting.attenuate < - 3*setting.scale && setting.attenuate >= setting.scale) { + setting.attenuate -= setting.scale; redraw_request |= REDRAW_CAL_STATUS; dirty = true; // Must be above if(scandirty!!!!!) - } else if (actual_t[max_index[0]] - setting_attenuate > - 1.5*setting_scale && setting_attenuate <= 30 - setting_scale) { - setting_attenuate += setting_scale; + } else if (actual_t[max_index[0]] - setting.attenuate > - 1.5*setting.scale && setting.attenuate <= 30 - setting.scale) { + setting.attenuate += setting.scale; redraw_request |= REDRAW_CAL_STATUS; dirty = true; // Must be above if(scandirty!!!!!) } } - if (!in_selftest && MODE_INPUT(setting_mode) && setting_auto_reflevel && max_index[0] > 0) { - if (actual_t[max_index[0]] > setting_reflevel - setting_scale/2) { - SetReflevel(setting_reflevel + setting_scale); + if (!in_selftest && MODE_INPUT(setting.mode) && setting.auto_reflevel && max_index[0] > 0) { + if (actual_t[max_index[0]] > setting.reflevel - setting.scale/2) { + SetReflevel(setting.reflevel + setting.scale); redraw_request |= REDRAW_CAL_STATUS; dirty = true; // Must be above if(scandirty!!!!!) - } else if (temp_min_level < setting_reflevel - 9 * setting_scale - 2 && actual_t[max_index[0]] < setting_reflevel - setting_scale * 3 / 2) { - SetReflevel(setting_reflevel - setting_scale); + } else if (temp_min_level < setting.reflevel - 9 * setting.scale - 2 && actual_t[max_index[0]] < setting.reflevel - setting.scale * 3 / 2) { + SetReflevel(setting.reflevel - setting.scale); redraw_request |= REDRAW_CAL_STATUS; dirty = true; // Must be above if(scandirty!!!!!) - } else if (temp_min_level > setting_reflevel - 9 * setting_scale + setting_scale + 2) { - SetReflevel(setting_reflevel + setting_scale); + } else if (temp_min_level > setting.reflevel - 9 * setting.scale + setting.scale + 2) { + SetReflevel(setting.reflevel + setting.scale); redraw_request |= REDRAW_CAL_STATUS; dirty = true; // Must be above if(scandirty!!!!!) } } #if 1 - if (MODE_INPUT(setting_mode)) { + if (MODE_INPUT(setting.mode)) { int i = 0; int m = 0; while (i < cur_max) { // For all maxima found @@ -1219,11 +1217,11 @@ static bool sweep(bool break_on_operation) m++; // Try next marker } #ifdef __MEASURE__ - if (setting_measurement == M_IMD && markers[0].index > 10) { + if (setting.measurement == M_IMD && markers[0].index > 10) { markers[1].enabled = search_maximum(1, frequencies[markers[0].index]*2, 8); markers[2].enabled = search_maximum(2, frequencies[markers[0].index]*3, 12); markers[3].enabled = search_maximum(3, frequencies[markers[0].index]*4, 16); - } else if (setting_measurement == M_OIP3 && markers[0].index > 10 && markers[1].index > 10) { + } else if (setting.measurement == M_OIP3 && markers[0].index > 10 && markers[1].index > 10) { int l = markers[0].index; int r = markers[1].index; if (r < l) { @@ -1236,14 +1234,14 @@ static bool sweep(bool break_on_operation) uint32_t rf = frequencies[r]; markers[2].enabled = search_maximum(2, lf - (rf - lf), 12); markers[3].enabled = search_maximum(3, rf + (rf - lf), 12); - } else if (setting_measurement == M_PHASE_NOISE && markers[0].index > 10) { - markers[1].index = markers[0].index + (setting_mode == M_LOW ? 290/4 : -290/4); // Position phase noise marker at requested offset - } else if (setting_measurement == M_STOP_BAND && markers[0].index > 10) { + } else if (setting.measurement == M_PHASE_NOISE && markers[0].index > 10) { + markers[1].index = markers[0].index + (setting.mode == M_LOW ? 290/4 : -290/4); // Position phase noise marker at requested offset + } else if (setting.measurement == M_STOP_BAND && markers[0].index > 10) { markers[1].index = marker_search_left_min(markers[0].index); if (markers[1].index < 0) markers[1].index = 0; markers[2].index = marker_search_right_min(markers[0].index); if (markers[2].index < 0) markers[1].index = POINTS_COUNT - 1; - } else if (setting_measurement == M_PASS_BAND && markers[0].index > 10) { + } else if (setting.measurement == M_PASS_BAND && markers[0].index > 10) { int t = markers[0].index; float v = actual_t[t]; while (t > 0 && actual_t[t] > v - 3.0) @@ -1268,7 +1266,7 @@ static bool sweep(bool break_on_operation) #endif min_level = temp_min_level; #if 0 // Auto ref level setting - int scale = setting_scale; + int scale = setting.scale; int rp = GetRepos(); if (scale > 0 && peakLevel > rp && peakLevel - min_level < 8 * scale ) { SetReflevel((((int)(peakLevel/scale)) + 1) * scale); @@ -1302,7 +1300,7 @@ marker_search_left_max(int from) if (new_value < value) { value = new_value; found = i; - } else if (new_value > value + setting_noise ) + } else if (new_value > value + setting.noise ) break; } @@ -1311,7 +1309,7 @@ marker_search_left_max(int from) if (new_value > value) { value = new_value; found = i; - } else if (new_value < value - setting_noise ) + } else if (new_value < value - setting.noise ) break; } return found; @@ -1331,7 +1329,7 @@ marker_search_right_max(int from) if (new_value < value) { // follow down value = new_value; found = i; - } else if (new_value > value + setting_noise) // larger then lowest value + noise + } else if (new_value > value + setting.noise) // larger then lowest value + noise break; // past the minimum } for (; i < sweep_points; i++) { @@ -1339,7 +1337,7 @@ marker_search_right_max(int from) if (new_value > value) { // follow up value = new_value; found = i; - } else if (new_value < value - setting_noise) + } else if (new_value < value - setting.noise) break; } return found; @@ -1427,18 +1425,18 @@ void draw_cal_status(void) ili9341_fill(x, y, OFFSETX, HEIGHT, 0x0000); - if (MODE_OUTPUT(setting_mode)) // No cal status during output + if (MODE_OUTPUT(setting.mode)) // No cal status during output return; if (current_menu_is_form() && !in_selftest) return; ili9341_set_background(DEFAULT_BG_COLOR); - int yMax = setting_reflevel; + int yMax = setting.reflevel; plot_printf(buf, BLEN, "%ddB", yMax); buf[5]=0; if (level_is_calibrated()) { - if (setting_auto_reflevel) + if (setting.auto_reflevel) color = DEFAULT_FG_COLOR; else color = BRIGHT_COLOR_GREEN; @@ -1451,10 +1449,10 @@ void draw_cal_status(void) color = DEFAULT_FG_COLOR; ili9341_set_foreground(color); y += YSTEP*2; - plot_printf(buf, BLEN, "%ddB/",(int)setting_scale); + plot_printf(buf, BLEN, "%ddB/",(int)setting.scale); ili9341_drawstring(buf, x, y); - if (setting_auto_attenuation) + if (setting.auto_attenuation) color = DEFAULT_FG_COLOR; else color = BRIGHT_COLOR_GREEN; @@ -1463,22 +1461,22 @@ void draw_cal_status(void) ili9341_drawstring("Attn:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%ddB", setting_attenuate); + plot_printf(buf, BLEN, "%ddB", setting.attenuate); buf[5]=0; ili9341_drawstring(buf, x, y); - if (setting_average>0) { + if (setting.average>0) { ili9341_set_foreground(BRIGHT_COLOR_BLUE); y += YSTEP*2; ili9341_drawstring("Calc:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%s",averageText[setting_average]); + plot_printf(buf, BLEN, "%s",averageText[setting.average]); buf[5]=0; ili9341_drawstring(buf, x, y); } #ifdef __ULTRA__ - if (setting_spur) { + if (setting.spur) { ili9341_set_foreground(BRIGHT_COLOR_BLUE); y += YSTEP*2; ili9341_drawstring("Spur:", x, y); @@ -1489,7 +1487,7 @@ void draw_cal_status(void) } #endif - if (setting_rbw) + if (setting.rbw) color = BRIGHT_COLOR_GREEN; else color = DEFAULT_FG_COLOR; @@ -1508,13 +1506,13 @@ void draw_cal_status(void) ili9341_drawstring("VBW:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%dkHz",(int)setting_vbw); + plot_printf(buf, BLEN, "%dkHz",(int)setting.vbw); buf[5]=0; ili9341_drawstring(buf, x, y); if (dirty) color = BRIGHT_COLOR_RED; - else if (setting_step_delay) + else if (setting.step_delay) color = BRIGHT_COLOR_GREEN; else color = DEFAULT_FG_COLOR; @@ -1527,7 +1525,7 @@ void draw_cal_status(void) y += YSTEP; int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 #ifdef __ULTRA__ - * (setting_spur ? 2 : 1) + * (setting.spur ? 2 : 1) #endif ; // in mS if (t>1000) @@ -1539,30 +1537,30 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); - if (setting_refer >= 0) { + if (setting.refer >= 0) { ili9341_set_foreground(BRIGHT_COLOR_RED); y += YSTEP*2; ili9341_drawstring("Ref:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%dMHz",reffer_freq[setting_refer]/1000000); + plot_printf(buf, BLEN, "%dMHz",reffer_freq[setting.refer]/1000000); buf[5]=0; ili9341_drawstring(buf, x, y); } ili9341_set_foreground(BRIGHT_COLOR_GREEN); y += YSTEP*2; - if (MODE_LOW(setting_mode)) + if (MODE_LOW(setting.mode)) ili9341_drawstring_7x13("M:L", x, y); else ili9341_drawstring_7x13("M:H", x, y); y = HEIGHT-7 + OFFSETY; - plot_printf(buf, BLEN, "%ddB", (int)(yMax - setting_scale * NGRIDY)); + plot_printf(buf, BLEN, "%ddB", (int)(yMax - setting.scale * NGRIDY)); buf[5]=0; if (level_is_calibrated()) - if (setting_auto_reflevel) + if (setting.auto_reflevel) color = DEFAULT_FG_COLOR; else color = BRIGHT_COLOR_GREEN; @@ -1634,9 +1632,9 @@ static void test_acquire(int i) pause_sweep(); #if 0 if (test_case[i].center < 300) - setting_mode = M_LOW; + setting.mode = M_LOW; else - setting_mode = M_HIGH; + setting.mode = M_HIGH; #endif // SetAverage(4); sweep(false); @@ -1813,8 +1811,8 @@ int test_validate(int i) void test_prepare(int i) { - setting_tracking = false; //Default test setup - setting_step_atten = false; + setting.tracking = false; //Default test setup + setting.step_atten = false; SetAttenuation(0); switch(test_case[i].setup) { // Prepare test conditions case TPH_SILENT: // No input signal @@ -1830,12 +1828,12 @@ common_silent: case TP_10MHZ_SWITCH: SetMode(M_LOW); set_refer_output(2); - setting_step_atten = true; + setting.step_atten = true; goto common; case TP_10MHZEXTRA: // Swept receiver SetMode(M_LOW); - setting_tracking = true; //Sweep BPF - frequency_IF = 434000000; // Center on SAW filters + setting.tracking = true; //Sweep BPF + setting.frequency_IF = 434000000; // Center on SAW filters set_refer_output(2); goto common; case TP_10MHZ: // 10MHz input @@ -1859,8 +1857,8 @@ common_silent: set_refer_output(0); goto common; } - setting_auto_attenuation = false; - setting_attenuate = 0; + setting.auto_attenuation = false; + setting.attenuate = 0; trace[TRACE_STORED].enabled = true; SetReflevel(test_case[i].pass+10); set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000)); @@ -1909,7 +1907,7 @@ void self_test(int test) f += FREQ_STEP; p1 = perform(false, 1, f, false); f += FREQ_STEP; - shell_printf("\n\rStarting with %4.2f, %4.2f and IF at %d\n\r", p2, p1, frequency_IF); + shell_printf("\n\rStarting with %4.2f, %4.2f and IF at %d\n\r", p2, p1, setting.frequency_IF); f = 400000; while (f < 100000000) { @@ -1926,7 +1924,7 @@ void self_test(int test) f += FREQ_STEP; } } - shell_printf("\n\rTable for IF at %d\n\r", frequency_IF); + shell_printf("\n\rTable for IF at %d\n\r", setting.frequency_IF); for (int j = 0; j < last_spur; j++) { if ((int)stored_t[j] > 1) shell_printf("%d, %d\n\r", ((int)temp_t[j])/1000, (int)stored_t[j]); @@ -1959,11 +1957,11 @@ void self_test(int test) reset_settings(M_LOW); int i = 15; // calibrate low mode power on 30 MHz; test_prepare(i); - setting_step_delay = 6000; + setting.step_delay = 6000; for (int j= 0; j < 57; j++ ) { - setting_step_delay = setting_step_delay * 4/3; - setting_rbw = SI4432_force_RBW(j); - shell_printf("RBW = %d, ",setting_rbw); + setting.step_delay = setting.step_delay * 4/3; + setting.rbw = SI4432_force_RBW(j); + shell_printf("RBW = %d, ",setting.rbw); test_prepare(i); test_acquire(i); // Acquire test test_validate(i); // Validate test @@ -1974,19 +1972,19 @@ void self_test(int test) } shell_printf("Start level = %f, ",peakLevel); - while (setting_step_delay > 100 && peakLevel > saved_peakLevel - 1) { - setting_step_delay = setting_step_delay * 3 / 4; + while (setting.step_delay > 100 && peakLevel > saved_peakLevel - 1) { + setting.step_delay = setting.step_delay * 3 / 4; test_prepare(i); // shell_printf("\n\rRBW = %f",SI4432_force_RBW(j)); test_acquire(i); // Acquire test test_validate(i); // Validate test - // shell_printf(" Step %f, %d",peakLevel, setting_step_delay); + // shell_printf(" Step %f, %d",peakLevel, setting.step_delay); } - setting_step_delay = setting_step_delay * 4 / 3; - shell_printf("End level = %f, step time = %d\n\r",peakLevel, setting_step_delay); + setting.step_delay = setting.step_delay * 4 / 3; + shell_printf("End level = %f, step time = %d\n\r",peakLevel, setting.step_delay); } } else if (test == 0) { - int old_IF = frequency_IF; + int old_IF = setting.frequency_IF; in_selftest = true; menu_autosettings_cb(0); for (int i=0; i < TEST_COUNT; i++) { // All test cases waiting @@ -1998,7 +1996,7 @@ void self_test(int test) show_test_info = TRUE; int i=0; while (test_case[i].kind != TC_END) { - frequency_IF = old_IF; + setting.frequency_IF = old_IF; test_prepare(i); test_acquire(i); // Acquire test test_status[i] = test_validate(i); // Validate test diff --git a/si4432.c b/si4432.c index ac67060..396fbbc 100644 --- a/si4432.c +++ b/si4432.c @@ -332,11 +332,11 @@ float SI4432_RBW_table(int i){ return(RBW_choices[i*4-1]); } -int setting_10mhz = 10000000; +int setting_frequency_10mhz = 10000000; void set_10mhz(int f) { - setting_10mhz = f; + setting_frequency_10mhz = f; } void SI4432_Set_Frequency ( long Freq ) { @@ -349,8 +349,8 @@ void SI4432_Set_Frequency ( long Freq ) { hbsel = 0; } int sbsel = 1; - int N = Freq / setting_10mhz; - Carrier = ( 4 * ( Freq - N * setting_10mhz )) / 625; + int N = Freq / setting_frequency_10mhz; + Carrier = ( 4 * ( Freq - N * setting_frequency_10mhz )) / 625; int Freq_Band = ( N - 24 ) | ( hbsel << 5 ) | ( sbsel << 6 ); #if 0 SI4432_Write_Byte ( 0x75, Freq_Band ); @@ -362,7 +362,7 @@ void SI4432_Set_Frequency ( long Freq ) { } int actualStepDelay = 1500; -extern int setting_repeat; +//extern int setting.repeat; float SI4432_RSSI(uint32_t i, int s) { @@ -378,12 +378,12 @@ float SI4432_RSSI(uint32_t i, int s) //START_PROFILE SI4432_Sel = s; chThdSleepMicroseconds(actualStepDelay); - i = setting_repeat; + i = setting.repeat; RSSI_RAW = 0; while (i-->0) RSSI_RAW += (unsigned char)SI4432_Read_Byte( 0x26 ) ; - RSSI_RAW = RSSI_RAW / setting_repeat; - // if (MODE_INPUT(setting_mode) && RSSI_RAW == 0) + RSSI_RAW = RSSI_RAW / setting.repeat; + // if (MODE_INPUT(setting.mode) && RSSI_RAW == 0) // SI4432_Init(); float dBm = (RSSI_RAW-240)/2.0 - SI4432_RSSI_correction; #ifdef __SIMULATION__ diff --git a/ui.c b/ui.c index 899d0d0..53e3954 100644 --- a/ui.c +++ b/ui.c @@ -119,7 +119,7 @@ static int16_t last_touch_y; #define KP_DONE 1 #define KP_CANCEL 2 -static void ui_mode_normal(void); +void ui_mode_normal(void); static void ui_mode_menu(void); static void ui_mode_numeric(int _keypad_mode); static void ui_mode_keypad(int _keypad_mode); @@ -1149,6 +1149,7 @@ menu_move_back(void) static void menu_push_submenu(const menuitem_t *submenu) { + ui_mode = UI_MENU; // Only needed for auto mode setting erase_menu_buttons(); if (menu_current_level < MENU_STACK_DEPTH_MAX-1) menu_current_level++; @@ -1849,7 +1850,7 @@ ui_mode_keypad(int _keypad_mode) draw_numeric_input(""); } -static void +void ui_mode_normal(void) { if (ui_mode == UI_NORMAL) diff --git a/ui_sa.c b/ui_sa.c index 7c111f0..773e147 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -14,7 +14,7 @@ int get_refer_output(void); void SetAttenuation(int); int GetAttenuation(void); void set_harmonic(int); -extern int setting_harmonic; +//extern int setting.harmonic; int search_is_greater(void); void set_auto_attenuation(void); void set_auto_reflevel(void); @@ -26,15 +26,15 @@ void SetDrive(int d); void SetIF(int f); void SetStepDelay(int t); void set_repeat(int); -extern int setting_repeat; -extern int setting_rbw; +//extern int setting.repeat; +//extern int setting.rbw; #ifdef __ULTRA__ -extern int setting_spur; +//extern int setting.spur; void SetSpur(int v); #endif void SetAverage(int); int GetAverage(void); -extern int setting_average; +//extern int setting.average; void SetStorage(void); void SetClearStorage(void); void SetSubtractStorage(void); @@ -51,28 +51,28 @@ void redrawHisto(void); void self_test(int); void set_decay(int); void set_noise(int); -void menu_load_preset_cb(int,int); -void menu_store_preset_cb(int,int); void toggle_tracking_output(void); extern int32_t frequencyExtra; -extern int setting_tracking; -extern int setting_tracking_output; -extern int setting_drive; -extern int setting_lna; -extern int setting_agc; -extern int setting_decay; -extern int setting_noise; -extern int setting_auto_reflevel; -extern int setting_auto_attenuation; -extern int setting_reflevel; -extern int setting_scale; -extern int setting_10mhz; +#if 0 +extern int setting.tracking; +extern int setting.tracking_output; +extern int setting.drive; +extern int setting.lna; +extern int setting.agc; +extern int setting.decay; +extern int setting.noise; +extern int setting.auto_reflevel; +extern int setting.auto_attenuation; +extern int setting.reflevel; +extern int setting.scale; +extern int setting.10mhz; +#endif void set_10mhz(int); void SetModulation(int); -extern int setting_modulation; +//extern int setting.modulation; void set_measurement(int); // extern int settingSpeed; -extern int setting_step_delay; +//extern int setting.step_delay; void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap); @@ -485,7 +485,7 @@ extern const menuitem_t menu_top[]; extern const menuitem_t menu_tophigh[]; extern const menuitem_t menu_topultra[]; -static void menu_mode_cb(int item, uint8_t data) + void menu_mode_cb(int item, uint8_t data) { (void)data; SetMode(item-1); @@ -512,6 +512,27 @@ static void menu_mode_cb(int item, uint8_t data) // draw_cal_status(); } +void menu_load_preset_cb(int item, uint8_t data) +{ + (void)item; + caldata_recall(data); + menu_move_back(); + ui_mode_normal(); +} + +void menu_store_preset_cb(int item, uint8_t data) +{ + (void)item; + if (data == 100) { + setting.mode = -1; + data = 0; + } + caldata_save(data); + menu_move_back(); + ui_mode_normal(); +} + + extern int dirty; void menu_autosettings_cb(int item, uint8_t data) { @@ -572,7 +593,7 @@ static void menu_config_cb(int item, uint8_t data) sweep_mode = 0; // Suspend sweep to save time menu_move_back(); ui_mode_normal(); - setting_test = 0; + setting.test = 0; sweep_mode = SWEEP_SELFTEST; break; case 4: @@ -636,7 +657,7 @@ static void menu_spur_cb(int item, uint8_t data) { (void)data; (void)item; - if (setting_spur) + if (setting.spur) SetSpur(0); else SetSpur(1); // must be 0 or 1 !!!! @@ -949,19 +970,45 @@ const char *menu_drive_text[]={"-36dBm","-34dBm","-32dBm","-30dBm","-28dBm","-26 // ===[MENU DEFINITION]========================================================= +static const menuitem_t menu_store_preset_high[] = +{ + { MT_CALLBACK, 0, "\2STORE\0STARTUP",menu_store_preset_cb}, + { MT_CALLBACK, 5, "STORE 5" , menu_store_preset_cb}, + { MT_CALLBACK, 6, "STORE 6" , menu_store_preset_cb}, + { MT_CALLBACK, 7, "STORE 7" , menu_store_preset_cb}, + { MT_CALLBACK, 8, "STORE 8" , menu_store_preset_cb}, + { MT_CALLBACK, 100, "\2ERASE\0STARTUP",menu_store_preset_cb}, + { MT_CANCEL, 255, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + +static const menuitem_t menu_load_preset_high[] = +{ + { MT_CALLBACK, 0, "\2LOAD\0STARTUP",menu_load_preset_cb}, + { MT_CALLBACK, 5, "LOAD 5" , menu_load_preset_cb}, + { MT_CALLBACK, 6, "LOAD 6" , menu_load_preset_cb}, + { MT_CALLBACK, 7, "LOAD 7" , menu_load_preset_cb}, + { MT_CALLBACK, 8, "LOAD 8" , menu_load_preset_cb}, + { MT_SUBMENU, 0, "STORE" , menu_store_preset_high}, + { MT_CANCEL, 255, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + static const menuitem_t menu_store_preset[] = { + { MT_CALLBACK, 0, "\2STORE\0STARTUP",menu_store_preset_cb}, { MT_CALLBACK, 1, "STORE 1" , menu_store_preset_cb}, { MT_CALLBACK, 2, "STORE 2" , menu_store_preset_cb}, { MT_CALLBACK, 3, "STORE 3" , menu_store_preset_cb}, { MT_CALLBACK, 4, "STORE 4" , menu_store_preset_cb}, + { MT_CALLBACK, 100, "\2ERASE\0STARTUP",menu_store_preset_cb}, { MT_CANCEL, 255, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; static const menuitem_t menu_load_preset[] = { - { MT_CALLBACK, 0, "DEFAULTS" , menu_load_preset_cb}, + { MT_CALLBACK, 0, "\2LOAD\0STARTUP",menu_load_preset_cb}, { MT_CALLBACK, 1, "LOAD 1" , menu_load_preset_cb}, { MT_CALLBACK, 2, "LOAD 2" , menu_load_preset_cb}, { MT_CALLBACK, 3, "LOAD 3" , menu_load_preset_cb}, @@ -1388,7 +1435,7 @@ const menuitem_t menu_topultra[] = { #endif const menuitem_t menu_top[] = { - { MT_CALLBACK, 0, "RESET", menu_autosettings_cb}, + { MT_SUBMENU, 0, "PRESET", menu_load_preset}, { MT_SUBMENU, 0, "FREQ", menu_stimulus}, { MT_SUBMENU, 0, "LEVEL", menu_level}, { MT_SUBMENU, 0, "DISPLAY", menu_display}, @@ -1401,7 +1448,7 @@ const menuitem_t menu_top[] = { }; const menuitem_t menu_tophigh[] = { - { MT_CALLBACK, 0, "RESET", menu_autosettings_cb}, + { MT_SUBMENU, 0, "PRESET", menu_load_preset_high}, { MT_SUBMENU, 0, "FREQ", menu_stimulus}, { MT_SUBMENU, 0, "LEVEL", menu_levelhigh}, { MT_SUBMENU, 0, "DISPLAY", menu_display}, @@ -1469,10 +1516,10 @@ static void menu_item_modify_attribute( plot_printf(uistat.text, sizeof uistat.text, menu_reffer_text[get_refer_output()+1]); } } else if (menu == menu_highoutputmode && item == 2) { - plot_printf(uistat.text, sizeof uistat.text, menu_drive_text[setting_drive]); + plot_printf(uistat.text, sizeof uistat.text, menu_drive_text[setting.drive]); } else if (menu == menu_lowoutputmode || menu == menu_highoutputmode) { if (item == 3) { - plot_printf(uistat.text, sizeof uistat.text, menu_modulation_text[setting_modulation]); + plot_printf(uistat.text, sizeof uistat.text, menu_modulation_text[setting.modulation]); } } else if (menu == menu_reffer) { if (item < 5 && item == get_refer_output() + 1){ @@ -1487,7 +1534,7 @@ static void menu_item_modify_attribute( mark = true; } #ifdef __ULTRA__ - if (item == 6 && setting_spur) { + if (item == 6 && setting.spur) { mark = true; } #endif @@ -1496,11 +1543,11 @@ static void menu_item_modify_attribute( mark = true; } } else if (menu == menu_dBper) { - if (data == setting_scale){ + if (data == setting.scale){ mark = true; } } else if (menu == menu_measure && MT_MASK(menu[item].type) == MT_CALLBACK) { - if (data == setting_measurement){ + if (data == setting.measurement){ mark = true; } } else if (menu == menu_rbw) { @@ -1509,11 +1556,11 @@ static void menu_item_modify_attribute( } } else if (MT_MASK(menu[item].type) == MT_CALLBACK && (menu == menu_drive || menu == menu_drive_wide || menu == menu_drive_wide2|| menu == menu_drive_wide3)) { - if (data == setting_drive){ + if (data == setting.drive){ mark = true; } } else if (menu == menu_modulation && MT_MASK(menu[item].type) == MT_CALLBACK) { - if (data == setting_modulation){ + if (data == setting.modulation){ mark = true; } } else if (menu == menu_display) { @@ -1530,22 +1577,22 @@ static void menu_item_modify_attribute( mark = true; } } else if (menu == menu_settings) { - if (item ==0 && setting_tracking_output){ + if (item ==0 && setting.tracking_output){ mark = true; } #ifdef __ULTRA__ } else if (MT_MASK(menu[item].type) == MT_CALLBACK && menu == menu_harmonic) { - if (data == setting_harmonic) + if (data == setting.harmonic) mark = true; #endif } else if (menu == menu_settings2 || menu == menu_settingshigh2) { - if (item ==0 && setting_agc){ + if (item ==0 && setting.agc){ mark = true; } - if (item == 1 && setting_lna){ + if (item == 1 && setting.lna){ mark = true; } - if (item == 2 && setting_tracking){ // should not happen in high mode + if (item == 2 && setting.tracking){ // should not happen in high mode mark = true; } } else if (menu == menu_marker_modify && active_marker >= 0 && markers[active_marker].enabled == M_ENABLED) { @@ -1570,10 +1617,10 @@ static void menu_item_modify_attribute( else if (item == 6 && uistat.marker_tracking) mark = true; } else if (menu == menu_reflevel) { - if ((item == 0 && setting_auto_reflevel) || (item == 1 && !setting_auto_reflevel)) + if ((item == 0 && setting.auto_reflevel) || (item == 1 && !setting.auto_reflevel)) mark = true; } else if (menu == menu_atten) { - if ((item == 0 && setting_auto_attenuation ) || (item == 1 && !setting_auto_attenuation)) + if ((item == 0 && setting.auto_attenuation ) || (item == 1 && !setting.auto_attenuation)) mark = true; } if (mark) { @@ -1615,11 +1662,11 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SCALE: - uistat.value = setting_scale; + uistat.value = setting.scale; plot_printf(uistat.text, sizeof uistat.text, "%ddB/", ((int32_t)uistat.value)); break; case KM_REFPOS: - uistat.value = setting_reflevel; + uistat.value = setting.reflevel; plot_printf(uistat.text, sizeof uistat.text, "%ddB", ((int32_t)uistat.value)); break; case KM_ATTENUATION: @@ -1631,19 +1678,19 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%ddB", ((int32_t)uistat.value)); break; case KM_IF: - uistat.value = frequency_IF; + uistat.value = setting.frequency_IF; plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SAMPLETIME: - uistat.value = setting_step_delay; + uistat.value = setting.step_delay; plot_printf(uistat.text, sizeof uistat.text, "%3duS", ((int32_t)uistat.value)); break; case KM_REPEAT: - uistat.value = setting_repeat; + uistat.value = setting.repeat; plot_printf(uistat.text, sizeof uistat.text, "%2d", ((int32_t)uistat.value)); break; case KM_DRIVE: - uistat.value = setting_drive; + uistat.value = setting.drive; plot_printf(uistat.text, sizeof uistat.text, "%3ddB", ((int32_t)uistat.value)); break; case KM_LOWOUTLEVEL: @@ -1651,15 +1698,15 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%ddB", ((int32_t)uistat.value)); break; case KM_DECAY: - uistat.value = setting_decay; + uistat.value = setting.decay; plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value)); break; case KM_NOISE: - uistat.value = setting_noise; + uistat.value = setting.noise; plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value)); break; case KM_10MHZ: - uistat.value = setting_10mhz; + uistat.value = setting_frequency_10mhz; plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0); break; @@ -1700,11 +1747,11 @@ set_numeric_value(void) set_trace_scale(2, uistat.value / 1000.0); break; case KM_REFPOS: - setting_auto_reflevel = false; + setting.auto_reflevel = false; SetReflevel(uistat.value); break; case KM_ATTENUATION: - setting_auto_attenuation = false; + setting.auto_attenuation = false; SetAttenuation(uistat.value); break; case KM_ACTUALPOWER: @@ -1735,7 +1782,7 @@ set_numeric_value(void) break; case KM_10MHZ: if (uistat.value < 9000000) { - set_10mhz(setting_10mhz + uistat.value); + set_10mhz(setting_frequency_10mhz + uistat.value); } else set_10mhz(uistat.value); dirty = true;