diff --git a/nanovna.h b/nanovna.h index 3074186..85e05bc 100644 --- a/nanovna.h +++ b/nanovna.h @@ -123,6 +123,10 @@ enum { M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, }; +enum { + MO_NONE, MO_AM, MO_NFM, MO_WFM, +}; + #define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH ) #define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH ) #define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH ) diff --git a/plot.c b/plot.c index 81f628a..f8ee6e2 100644 --- a/plot.c +++ b/plot.c @@ -1503,7 +1503,7 @@ draw_all_cells(bool flush_markmap) #endif spi_buffer[i] = RGB565(r,g,b); } - ili9341_bulk(5*5,HEIGHT+3, 290,1); + ili9341_bulk(5*5,HEIGHT+3, area_width,1); } #endif } diff --git a/sa_core.c b/sa_core.c index 0b8d107..d9813f5 100644 --- a/sa_core.c +++ b/sa_core.c @@ -64,7 +64,7 @@ int scandirty = true; //---------------- menu system ----------------------- int settingAttenuate = 0; -int settingGenerate = 0; +// int settingGenerate = 0; int settingBandwidth = 0; //int settingLevelOffset = 0; @@ -80,6 +80,7 @@ int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; int extraVFO = false; +int settingModulation = MO_NONE; int settingStepDelay = 0; float rbw = 0; float vbw = 0; @@ -98,11 +99,13 @@ int get_refer_output(void) return(settingRefer); } +#if 0 void SetGenerate(int g) { settingGenerate = g; dirty = true; } +#endif void SetDrive(int d) { @@ -110,6 +113,11 @@ void SetDrive(int d) dirty = true; } +void SetModulation(int m) +{ + settingModulation = m; + dirty = true; +} void SetIF(int f) { frequency_IF = f; @@ -157,6 +165,12 @@ void SetMode(int m) void SetAttenuation(int a) { + if (a<0) + a = 0; + if (a> 31) + a=31; + if (settingAttenuate == a) + return; settingAttenuate = a; dirty = true; } @@ -610,6 +624,7 @@ void update_rbw(uint32_t delta_f) } static int old_lf = -1; +static int modulation_counter = 0; float perform(bool break_on_operation, int i, int32_t f, int extraV) { @@ -631,6 +646,16 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) int p = settingAttenuate * 2; PE4302_Write_Byte(p); + if (settingModulation == MO_NFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 1); // Use frequency hopping channel width for FM modulation + } else if (settingModulation == MO_WFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 10); // Use frequency hopping channel width for FM modulation + } else { + SI4432_Sel = 1; + SI4432_Write_Byte(0x79, 0); // IF no FM back to channel 0 + } SetRX(settingMode); SI4432_SetReference(settingRefer); temppeakLevel = -150; @@ -641,6 +666,23 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) dirty = false; // } } + if (settingModulation == MO_AM) { + int p = settingAttenuate * 2 + modulation_counter; + PE4302_Write_Byte(p); + if (modulation_counter == 3) + modulation_counter = 0; + else + modulation_counter++; + chThdSleepMicroseconds(250); + } else if (settingModulation == MO_NFM || settingModulation == MO_WFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x79, modulation_counter); // Use frequency hopping channel for FM modulation + if (modulation_counter == 3) + modulation_counter = 0; + else + modulation_counter++; + chThdSleepMicroseconds(250); + } volatile int subSteps = ((int)(2 * vbw / rbw)); float RSSI = -150.0; int t = 0; @@ -651,6 +693,8 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) if (lf != old_lf) // only set on change setFreq (1, local_IF + lf); old_lf = lf; + if (MODE_OUTPUT(settingMode)) + return(0); float subRSSI = SI4432_RSSI(lf, MODE_SELECT(settingMode))+settingLevelOffset()+settingAttenuate; if (RSSI < subRSSI) RSSI = subRSSI; diff --git a/ui.c b/ui.c index 615e017..73f4a48 100644 --- a/ui.c +++ b/ui.c @@ -1095,6 +1095,10 @@ menu_push_submenu(const menuitem_t *submenu) if (menu_is_form(submenu)) { redraw_frame(); area_width = 0; + } else { + redraw_frame(); + request_to_redraw_grid(); + area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; } draw_menu(); } diff --git a/ui_sa.c b/ui_sa.c index db92473..2735799 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -38,13 +38,16 @@ extern int extraVFO; extern int settingDrive; extern int settingLNA; extern int settingAGC; +void SetModulation(int); +extern int settingModulation; // extern int settingSpeed; extern int settingStepDelay; enum { - KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE + KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, + KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_HIGHOUTLEVEL }; @@ -136,6 +139,7 @@ static const keypads_t keypads_level[] = { static const keypads_t * const keypads_mode_tbl[] = { + NULL, // never used keypads_freq, // start keypads_freq, // stop keypads_freq, // center @@ -148,6 +152,8 @@ static const keypads_t * const keypads_mode_tbl[] = { keypads_freq, // IF keypads_level, // sample time keypads_scale, // drive + keypads_level, // KM_LOWOUTLEVEL + keypads_level, // KM_HIGHOUTLEVEL }; #ifdef __VNA__ @@ -157,7 +163,7 @@ static const char * const keypad_mode_label[] = { #endif #ifdef __SA__ static const char * const keypad_mode_label[] = { - "START", "STOP", "CENTER", "SPAN", "CW FREQ", "REFPOS", "SCALE", "ATTENUATION", "ACTUALPOWER", "IF", "SAMPLE TIME", "DRIVE" + "error", "START", "STOP", "CENTER", "SPAN", "CW FREQ", "REFPOS", "SCALE", "ATTENUATION", "ACTUALPOWER", "IF", "SAMPLE TIME", "DRIVE", "LEVEL", "LEVEL" }; #endif @@ -169,6 +175,7 @@ int generator_enabled = false; extern const menuitem_t menu_lowoutputmode[]; extern const menuitem_t menu_highoutputmode[]; +extern const menuitem_t menu_modulation[]; extern const menuitem_t menu_top[]; static void menu_mode_cb(int item, uint8_t data) @@ -213,15 +220,20 @@ void menu_autosettings_cb(int item, uint8_t data) set_trace_refpos(2, - value / get_trace_scale(0) + NGRIDY); active_marker = 0; - menu_marker_type_cb(M_REFERENCE,M_REFERENCE); - set_refer_output(1); + for (int i = 0; i