From 8bd2b4f8991515267095443b8b0042fceaf38121 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 8 Apr 2020 08:45:25 +0200 Subject: [PATCH 1/4] Problems with drive level --- sa_core.c | 12 ++++++++---- si4432.c | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sa_core.c b/sa_core.c index 908acfe..8ec0bd4 100644 --- a/sa_core.c +++ b/sa_core.c @@ -13,7 +13,7 @@ int setting_rbw = 0; int setting_average = 0; int setting_show_stored = 0; int setting_subtract_stored = 0; -int setting_drive=13; // 0-7 , 7=+20dBm, 3dB steps +int setting_drive; // 0-7 , 7=+20dBm, 3dB steps int setting_agc = true; int setting_lna = false; int setting_tracking = false; @@ -46,7 +46,7 @@ void reset_settings(int m) setting_average = 0; setting_show_stored = 0; setting_subtract_stored = 0; - setting_drive=13; + setting_drive=12; setting_step_atten = 0; // Only used in low output mode setting_agc = true; setting_lna = false; @@ -494,11 +494,11 @@ case M_GENLOW: // Mixed output from 0 } else { SetSwitchTransmit(); } - SI4432_Transmit(setting_drive); // Not to overdrive the mixer + SI4432_Transmit(setting_drive); SI4432_Sel = 1; SetSwitchReceive(); - SI4432_Transmit(13); // Fix LO drive a 10dBm + SI4432_Transmit(12); // Fix LO drive a 10dBm break; case M_GENHIGH: // Direct output from 1 @@ -516,6 +516,10 @@ case M_GENHIGH: // Direct output from 1 break; } + SI4432_Sel = 1; + SI4432_Write_Byte(0x73, 0); // Back to nominal offset + SI4432_Write_Byte(0x74, 0); + } void update_rbw(void) diff --git a/si4432.c b/si4432.c index 9f7edb9..90ab674 100644 --- a/si4432.c +++ b/si4432.c @@ -278,12 +278,13 @@ void SI4432_Sub_Init(void) { SI4432_Reset(); - +#if 1 // Not sure if these add any value //set VCO and PLL Only for SI4432 V2 SI4432_Write_Byte(0x72, 0x1F); //write 0x1F to the Frequency Deviation register SI4432_Write_Byte(0x5A, 0x7F); //write 0x7F to the VCO Current Trimming register SI4432_Write_Byte(0x58, 0x80); //write 0xD7 to the ChargepumpCurrentTrimmingOverride register SI4432_Write_Byte(0x59, 0x40); //write 0x40 to the Divider Current Trimming register +#endif //set the AGC SI4432_Write_Byte(0x6A, 0x0B); //write 0x0B to the AGC Override 2 register From 46e09bc8faa5cdbf1780fd6862665884932ba764 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 8 Apr 2020 18:32:54 +0200 Subject: [PATCH 2/4] Various small improvements --- Makefile | 4 ++-- sa_core.c | 14 +++++++------- ui_sa.c | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 341524d..e16ea2e 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ # Compiler options here. ifeq ($(USE_OPT),) - USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage -# USE_OPT = -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage +# USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage + USE_OPT = -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage endif # C specific options here (added to USE_OPT). diff --git a/sa_core.c b/sa_core.c index 8ec0bd4..1ec7be5 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1,8 +1,8 @@ -// --------------------------------------------------- #include "SI4432.h" // comment out for simulation -int setting_mode = M_LOW; +int setting_mode = -1; // To force initialzation + int dirty = true; @@ -152,7 +152,7 @@ int GetMode(void) #define POWER_STEP 0 // Should be 5 dB but appearently it is lower -#define POWER_OFFSET 12 +#define POWER_OFFSET 20 #define SWITCH_ATTENUATION 29 int GetAttenuation(void) @@ -170,7 +170,7 @@ int GetAttenuation(void) void SetAttenuation(int a) { if (setting_mode == M_GENLOW) { - setting_drive = 0; + setting_drive = 8; // Start at lowest drive level; a = a + POWER_OFFSET; if (a > 0) { setting_drive++; @@ -385,9 +385,9 @@ void SetMode(int m) void apply_settings(void) { if (setting_step_delay == 0){ - if (actual_rbw >142.0) actualStepDelay = 350; - else if (actual_rbw > 75.0) actualStepDelay = 450; - else if (actual_rbw > 56.0) actualStepDelay = 600; + if (actual_rbw >142.0) actualStepDelay = 450; + else if (actual_rbw > 75.0) actualStepDelay = 550; + else if (actual_rbw > 56.0) actualStepDelay = 650; else if (actual_rbw > 37.0) actualStepDelay = 800; else if (actual_rbw > 18.0) actualStepDelay = 1100; else if (actual_rbw > 9.0) actualStepDelay = 2000; diff --git a/ui_sa.c b/ui_sa.c index 37940f9..b1806e7 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -528,10 +528,10 @@ const char *menu_drive_text[]={"-30dBm","-27dBm","-24dBm","-21dBm","-18dBm","-15 // ===[MENU DEFINITION]========================================================= static const menuitem_t menu_drive[] = { - { MT_CALLBACK, 7, " 20dBm", menu_drive_cb}, - { MT_CALLBACK, 6, " 16dBm", menu_drive_cb}, - { MT_CALLBACK, 5, " 12dBm", menu_drive_cb}, - { MT_CALLBACK, 4, " 8dBm", menu_drive_cb}, + { MT_CALLBACK, 15, " 20dBm", menu_drive_cb}, + { MT_CALLBACK, 14, " 16dBm", menu_drive_cb}, + { MT_CALLBACK, 13, " 12dBm", menu_drive_cb}, + { MT_CALLBACK, 12, " 8dBm", menu_drive_cb}, { MT_CANCEL, 255, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; From 1f86864f9ae313778ff87f31373fdc16cda1b570 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 8 Apr 2020 19:17:17 +0200 Subject: [PATCH 3/4] Automatic attenuation added --- sa_core.c | 21 +++++++++++++++ ui_sa.c | 81 ++++++++++++++++++++++--------------------------------- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/sa_core.c b/sa_core.c index 1ec7be5..7a718d9 100644 --- a/sa_core.c +++ b/sa_core.c @@ -8,6 +8,7 @@ int setting_mode = -1; // To force initialzation int dirty = true; int scandirty = true; int setting_attenuate = 0; +int setting_auto_attenuation; int setting_step_atten; int setting_rbw = 0; int setting_average = 0; @@ -45,6 +46,7 @@ void reset_settings(int m) setting_rbw = 0; setting_average = 0; setting_show_stored = 0; + setting_auto_attenuation = true; setting_subtract_stored = 0; setting_drive=12; setting_step_atten = 0; // Only used in low output mode @@ -68,6 +70,7 @@ void reset_settings(int m) set_sweep_frequency(ST_START, (int32_t) 0); set_sweep_frequency(ST_STOP, (int32_t) 350000000); SetRefpos(-10); + setting_attenuate = 30; break; case M_GENLOW: setting_drive=8; @@ -166,6 +169,12 @@ int GetAttenuation(void) return(setting_attenuate); } +void set_auto_attenuation(void) +{ + setting_auto_attenuation = true; + setting_attenuate = 30; + +} void SetAttenuation(int a) { @@ -202,6 +211,7 @@ void SetAttenuation(int a) a=31; // if (setting_attenuate == a) // return; + setting_auto_attenuation = false; setting_attenuate = a; dirty = true; } @@ -882,6 +892,17 @@ static bool sweep(bool break_on_operation) scandirty = false; draw_cal_status(); } + if (setting_mode == M_LOW && setting_auto_attenuation ) { + if (actual_t[max_index[0]] - setting_attenuate < -30 && setting_attenuate >= 10) { + setting_attenuate -= 10; + redraw_request |= REDRAW_CAL_STATUS; + dirty = true; // Must be above if(scandirty!!!!!) + } else if (actual_t[max_index[0]] - setting_attenuate > -20 && setting_attenuate <= 20) { + setting_attenuate += 10; + redraw_request |= REDRAW_CAL_STATUS; + dirty = true; // Must be above if(scandirty!!!!!) + } + } #if 1 if (MODE_INPUT(setting_mode)) { int i = 0; diff --git a/ui_sa.c b/ui_sa.c index b1806e7..c8036c2 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -13,6 +13,7 @@ void set_refer_output(int); int get_refer_output(void); void SetAttenuation(int); int GetAttenuation(void); +void set_auto_attenuation(void); void SetPowerLevel(int); void SetGenerate(int); void SetRBW(int); @@ -387,6 +388,13 @@ static void menu_measure_cb(int item, uint8_t data) // draw_cal_status(); } +static void menu_atten_cb(int item, uint8_t data) +{ + set_auto_attenuation(); + menu_move_back(); + ui_mode_normal(); +} + static void menu_storage_cb(int item, uint8_t data) { (void)item; @@ -609,16 +617,6 @@ static const menuitem_t menu_average[] = { { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; -#if 0 -static const menuitem_t menu_storage[] = { - { MT_CALLBACK, 0, "STORE", menu_storage_cb}, - { MT_CALLBACK, 1, "CLEAR", menu_storage_cb}, - { MT_CALLBACK, 2, "SUBTRACT", menu_storage_cb}, - { MT_CALLBACK, 3, "WATERFALL",menu_storage_cb}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; -#endif static const menuitem_t menu_rbw[] = { { MT_CALLBACK, 0, " AUTO", menu_rbw_cb}, @@ -650,6 +648,7 @@ static const menuitem_t menu_reffer2[] = { { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; + static const menuitem_t menu_reffer[] = { { MT_FORM | MT_CALLBACK, 0, "OFF" , menu_reffer_cb}, { MT_FORM | MT_CALLBACK, 1, "30MHz", menu_reffer_cb}, @@ -661,58 +660,42 @@ static const menuitem_t menu_reffer[] = { { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_acquire[] = { - { MT_CALLBACK, 0, "AUTO", menu_autosettings_cb}, - { MT_KEYPAD, KM_ATTENUATION, "ATTEN", NULL}, - { MT_SUBMENU,0, "RBW", menu_rbw}, - { MT_SUBMENU,0, "CALC", menu_average}, +static const menuitem_t menu_atten[] = { + { MT_CALLBACK,0, "AUTO", menu_atten_cb}, + { MT_KEYPAD, KM_ATTENUATION, "MANUAL", NULL}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; +static const menuitem_t menu_acquire[] = { + { MT_CALLBACK, 0, "RESET", menu_autosettings_cb}, + { MT_SUBMENU, 0, "ATTEN", menu_atten}, + { MT_SUBMENU,0, "RBW", menu_rbw}, + { MT_SUBMENU,0, "AVER", menu_average}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel +}; + static const menuitem_t menu_acquirehigh[] = { - { MT_CALLBACK, 0, "AUTO", menu_autosettings_cb}, + { MT_CALLBACK, 0, "RESET", menu_autosettings_cb}, { MT_SUBMENU,0, "RBW", menu_rbw}, - { MT_SUBMENU,0, "CALC", menu_average}, + { MT_SUBMENU,0, "AVER", menu_average}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; static const menuitem_t menu_display[] = { - { MT_KEYPAD, KM_REFPOS, "\2REF\0LEVEL", NULL}, - { MT_SUBMENU,0, "\2SCALE/\0DIV", menu_dBper}, - { MT_CALLBACK, 0, "STORE", menu_storage_cb}, - { MT_CALLBACK, 1, "CLEAR", menu_storage_cb}, - { MT_CALLBACK, 2, "SUBTRACT", menu_storage_cb}, - { MT_CALLBACK, 3, "WATERFALL",menu_storage_cb}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -#if 0 -static const menuitem_t menu_scale[] = { - { MT_KEYPAD, KM_REFPOS, "\2REF\0LEVEL", NULL}, - { MT_SUBMENU,0, "\2SCALE/\0DIV", menu_dBper}, - { MT_KEYPAD, KM_ATTENUATION, "ATTEN", NULL}, - { MT_SUBMENU,0, "AVERAGE", menu_average}, - { MT_KEYPAD, 0, "\2SPUR\0REDUCT.", menu_spur_cb}, - { MT_SUBMENU,0, "RBW", menu_rbw}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_KEYPAD, KM_REFPOS, "\2REF\0LEVEL", NULL}, + { MT_SUBMENU, 0, "\2SCALE/\0DIV", menu_dBper}, + { MT_CALLBACK,0, "STORE", menu_storage_cb}, + { MT_CALLBACK,1, "CLEAR", menu_storage_cb}, + { MT_CALLBACK,2, "SUBTRACT", menu_storage_cb}, + { MT_CALLBACK,3, "WATERFALL",menu_storage_cb}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_scalehigh[] = { - { MT_KEYPAD, KM_REFPOS, "\2REF\0LEVEL", NULL}, - { MT_SUBMENU,0, "\2SCALE/\0DIV", menu_dBper}, - { MT_SUBMENU,0, "AVERAGE", menu_average}, - { MT_SUBMENU,0, "RBW", menu_rbw}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -#endif - static const menuitem_t menu_stimulus[8] = { { MT_KEYPAD, KM_START, "START", NULL}, { MT_KEYPAD, KM_STOP, "STOP", NULL}, @@ -858,7 +841,7 @@ static const menuitem_t menu_mode[] = { #if 1 const menuitem_t menu_top[] = { { MT_SUBMENU, 0, "ACQUIRE", menu_acquire}, - { MT_SUBMENU, 0, "SCAN", menu_stimulus}, + { MT_SUBMENU, 0, "FREQ", menu_stimulus}, { MT_SUBMENU, 0, "DISPLAY", menu_display}, { MT_SUBMENU, 0, "MARKER", menu_marker}, { MT_SUBMENU, 0, "MEASURE", menu_measure}, @@ -871,7 +854,7 @@ const menuitem_t menu_top[] = { const menuitem_t menu_tophigh[] = { { MT_SUBMENU, 0, "ACQUIRE", menu_acquirehigh}, - { MT_SUBMENU, 0, "SCAN", menu_stimulus}, + { MT_SUBMENU, 0, "FREQ", menu_stimulus}, { MT_SUBMENU, 0, "DISPLAY", menu_display}, { MT_SUBMENU, 0, "MARKER", menu_marker}, { MT_SUBMENU, 0, "MEASURE", menu_measure}, From e3d96b9beda24e7dec995aa81443d0b7936c077f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 9 Apr 2020 08:21:33 +0200 Subject: [PATCH 4/4] Auto reflevel and auto attenuation added --- nanovna.h | 2 +- sa_core.c | 69 ++++++++++++++++++++++++++++++++++++++++--------------- ui_sa.c | 50 ++++++++++++++++++++++++++++++---------- 3 files changed, 89 insertions(+), 32 deletions(-) diff --git a/nanovna.h b/nanovna.h index d5ff1e4..86ef5ce 100644 --- a/nanovna.h +++ b/nanovna.h @@ -637,7 +637,7 @@ int get_waterfall(void); void toggle_tracking(void); void calibrate(void); void reset_calibration(void); -void SetRefpos(int); +void SetReflevel(int); void SetScale(int); void SetRBW(int); void SetRX(int); diff --git a/sa_core.c b/sa_core.c index 7a718d9..1cd63b6 100644 --- a/sa_core.c +++ b/sa_core.c @@ -17,6 +17,9 @@ 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; @@ -42,6 +45,8 @@ int in_selftest = false; void reset_settings(int m) { setting_mode = m; + SetScale(10); + SetReflevel(-10); setting_attenuate = 0; setting_rbw = 0; setting_average = 0; @@ -56,8 +61,9 @@ void reset_settings(int m) setting_modulation = MO_NONE; setting_step_delay = 0; setting_vbw = 0; + setting_auto_reflevel = true; // Must be after SetReflevel setting_decay=20; - setting_noise=20; + setting_noise=5; trace[TRACE_STORED].enabled = false; trace[TRACE_TEMP].enabled = false; @@ -69,7 +75,6 @@ void reset_settings(int m) maxFreq = 520000000; set_sweep_frequency(ST_START, (int32_t) 0); set_sweep_frequency(ST_STOP, (int32_t) 350000000); - SetRefpos(-10); setting_attenuate = 30; break; case M_GENLOW: @@ -84,7 +89,6 @@ void reset_settings(int m) maxFreq = 960000000; set_sweep_frequency(ST_START, (int32_t) minFreq); set_sweep_frequency(ST_STOP, (int32_t) maxFreq); - SetRefpos(-30); break; case M_GENHIGH: setting_drive=8; @@ -94,7 +98,6 @@ void reset_settings(int m) set_sweep_frequency(ST_SPAN, 0); break; } - SetScale(10); dirty = true; } @@ -119,7 +122,7 @@ void set_decay(int d) void set_noise(int d) { - if (d < 5 || d > 200) + if (d < 2 || d > 50) return; setting_noise = d; dirty = true; @@ -173,7 +176,11 @@ void set_auto_attenuation(void) { setting_auto_attenuation = true; setting_attenuate = 30; +} +void set_auto_reflevel(void) +{ + setting_auto_reflevel = true; } void SetAttenuation(int a) @@ -211,7 +218,6 @@ void SetAttenuation(int a) a=31; // if (setting_attenuate == a) // return; - setting_auto_attenuation = false; setting_attenuate = a; dirty = true; } @@ -371,20 +377,29 @@ int GetAGC(void) return(setting_agc); } -void SetRefpos(int level) +void SetReflevel(int level) { + 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)); dirty = true; } +//int GetRefpos(void) { +// return (NGRIDY - get_trace_refpos(2)) * get_trace_scale(2); +//} + void SetScale(int s) { + setting_scale = s; set_trace_scale(0, s); set_trace_scale(1, s); set_trace_scale(2, s); } +//int GetScale(void) { +// return get_trace_refpos(2); +//} void SetMode(int m) { if (setting_mode == m) @@ -878,9 +893,10 @@ static bool sweep(bool break_on_operation) temppeakLevel = actual_t[i]; } } +#endif if (temp_min_level > actual_t[i]) temp_min_level = actual_t[i]; -#endif + } // if (setting_spur == 1) { // setting_spur = -1; @@ -892,13 +908,28 @@ static bool sweep(bool break_on_operation) scandirty = false; draw_cal_status(); } - if (setting_mode == M_LOW && setting_auto_attenuation ) { + if (setting_mode == M_LOW && setting_auto_attenuation && max_index[0] > 0) { if (actual_t[max_index[0]] - setting_attenuate < -30 && setting_attenuate >= 10) { - setting_attenuate -= 10; + 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 > -20 && setting_attenuate <= 20) { - setting_attenuate += 10; + setting_attenuate += setting_scale; + redraw_request |= REDRAW_CAL_STATUS; + dirty = true; // Must be above if(scandirty!!!!!) + } + } + if (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 && 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 * 3 / 2) { + SetReflevel(setting_reflevel + setting_scale); redraw_request |= REDRAW_CAL_STATUS; dirty = true; // Must be above if(scandirty!!!!!) } @@ -951,15 +982,15 @@ static bool sweep(bool break_on_operation) #endif min_level = temp_min_level; #if 0 // Auto ref level setting - int scale = get_trace_scale(2); - int rp = (NGRIDY - get_trace_refpos(2)) * scale; + int scale = setting_scale; + int rp = GetRepos(); if (scale > 0 && peakLevel > rp && peakLevel - min_level < 8 * scale ) { - SetRefpos((((int)(peakLevel/scale)) + 1) * scale); + SetReflevel((((int)(peakLevel/scale)) + 1) * scale); } if (scale > 0 && min_level < rp - 9*scale && peakLevel - min_level < 8 * scale ) { int new_rp = (((int)((min_level + 9*scale)/scale)) - 1) * scale; if (new_rp < rp) - SetRefpos(new_rp); + SetReflevel(new_rp); } #endif @@ -994,7 +1025,7 @@ void draw_cal_status(void) ili9341_set_background(DEFAULT_BG_COLOR); - int yMax = (NGRIDY - get_trace_refpos(0)) * get_trace_scale(0); + int yMax = setting_reflevel; plot_printf(buf, BLEN, "%ddB", yMax); buf[5]=0; if (level_is_calibrated()) @@ -1005,7 +1036,7 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); y += YSTEP*2; - plot_printf(buf, BLEN, "%ddB/",(int)get_trace_scale(0)); + plot_printf(buf, BLEN, "%ddB/",(int)setting_scale); ili9341_drawstring(buf, x, y); if (setting_attenuate) { @@ -1101,7 +1132,7 @@ void draw_cal_status(void) y = HEIGHT-7 + OFFSETY; - plot_printf(buf, BLEN, "%ddB", (int)(yMax - get_trace_scale(0) * NGRIDY)); + plot_printf(buf, BLEN, "%ddB", (int)(yMax - setting_scale * NGRIDY)); buf[5]=0; if (level_is_calibrated()) color = DEFAULT_FG_COLOR; @@ -1407,7 +1438,7 @@ common_silent: goto common; } trace[TRACE_STORED].enabled = true; - SetRefpos(test_case[i].pass+10); + SetReflevel(test_case[i].pass+10); set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000)); set_sweep_frequency(ST_SPAN, (int32_t)(test_case[i].span * 1000000)); draw_cal_status(); diff --git a/ui_sa.c b/ui_sa.c index c8036c2..7734392 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -14,6 +14,8 @@ int get_refer_output(void); void SetAttenuation(int); int GetAttenuation(void); void set_auto_attenuation(void); +void set_auto_reflevel(void); + void SetPowerLevel(int); void SetGenerate(int); void SetRBW(int); @@ -32,7 +34,7 @@ void SetSubtractStorage(void); void toggle_waterfall(void); void SetMode(int); int GetMode(void); -void SetRefpos(int); +void SetReflevel(int); void SetScale(int); void AllDirty(void); void MenuDirty(void); @@ -49,6 +51,10 @@ 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; void SetModulation(int); extern int setting_modulation; void set_measurement(int); @@ -390,11 +396,22 @@ static void menu_measure_cb(int item, uint8_t data) static void menu_atten_cb(int item, uint8_t data) { + (void)item; + (void)data; set_auto_attenuation(); menu_move_back(); ui_mode_normal(); } +static void menu_reflevel_cb(int item, uint8_t data) +{ + (void)item; + (void)data; + set_auto_reflevel(); + menu_move_back(); + ui_mode_normal(); +} + static void menu_storage_cb(int item, uint8_t data) { (void)item; @@ -684,14 +701,21 @@ static const menuitem_t menu_acquirehigh[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; +static const menuitem_t menu_reflevel[] = { + { MT_CALLBACK,0, "AUTO", menu_reflevel_cb}, + { MT_KEYPAD, KM_REFPOS, "MANUAL", NULL}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + static const menuitem_t menu_display[] = { - { MT_KEYPAD, KM_REFPOS, "\2REF\0LEVEL", NULL}, - { MT_SUBMENU, 0, "\2SCALE/\0DIV", menu_dBper}, - { MT_CALLBACK,0, "STORE", menu_storage_cb}, - { MT_CALLBACK,1, "CLEAR", menu_storage_cb}, - { MT_CALLBACK,2, "SUBTRACT", menu_storage_cb}, - { MT_CALLBACK,3, "WATERFALL",menu_storage_cb}, + { MT_SUBMENU, 0, "\2REF\0LEVEL", menu_reflevel}, + { MT_SUBMENU, 0, "\2SCALE/\0DIV",menu_dBper}, + { MT_CALLBACK,0, "STORE", menu_storage_cb}, + { MT_CALLBACK,1, "CLEAR", menu_storage_cb}, + { MT_CALLBACK,2, "SUBTRACT", menu_storage_cb}, + { MT_CALLBACK,3, "WATERFALL", menu_storage_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1021,12 +1045,12 @@ 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 = get_trace_scale(uistat.current_trace) * 1000; - plot_printf(uistat.text, sizeof uistat.text, "%ddB/", uistat.value / 1000); + uistat.value = setting_scale; + plot_printf(uistat.text, sizeof uistat.text, "%ddB/", uistat.value); break; case KM_REFPOS: - uistat.value = get_trace_refpos(uistat.current_trace) * 1000; - plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value / 1000); + uistat.value = setting_reflevel; + plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_ATTENUATION: uistat.value = GetAttenuation(); @@ -1097,9 +1121,11 @@ set_numeric_value(void) set_trace_scale(2, uistat.value / 1000.0); break; case KM_REFPOS: - SetRefpos(uistat.value); + setting_auto_reflevel = false; + SetReflevel(uistat.value); break; case KM_ATTENUATION: + setting_auto_attenuation = false; SetAttenuation(uistat.value); break; case KM_ACTUALPOWER: