diff --git a/main.c b/main.c index 2a292d4..88b429a 100644 --- a/main.c +++ b/main.c @@ -494,6 +494,9 @@ freq_mode_centerspan(void) } +#define START_MIN 500000 +#define STOP_MAX 300000000 + void set_sweep_frequency(int type, int frequency) { @@ -501,6 +504,8 @@ set_sweep_frequency(int type, int frequency) case ST_START: ensure_edit_config(); freq_mode_startstop(); + if (frequency < START_MIN) + frequency = START_MIN; if (freq_start != frequency) { freq_start = frequency; update_frequencies(); @@ -509,6 +514,8 @@ set_sweep_frequency(int type, int frequency) case ST_STOP: ensure_edit_config(); freq_mode_startstop(); + if (frequency > STOP_MAX) + frequency = STOP_MAX; if (freq_stop != frequency) { freq_stop = frequency; update_frequencies(); @@ -519,6 +526,16 @@ set_sweep_frequency(int type, int frequency) freq_mode_centerspan(); if (freq_start != frequency) { freq_start = frequency; + int center = freq_start; + int span = -freq_stop; + if (center-span/2 < START_MIN) { + span = (center - START_MIN) * 2; + freq_stop = -span; + } + if (center+span/2 > STOP_MAX) { + span = (STOP_MAX - center) * 2; + freq_stop = -span; + } update_frequencies(); } break; @@ -527,6 +544,25 @@ set_sweep_frequency(int type, int frequency) freq_mode_centerspan(); if (freq_stop != -frequency) { freq_stop = -frequency; + int center = freq_start; + int span = -freq_stop; + if (center-span/2 < START_MIN) { + center = START_MIN + span/2; + freq_start = center; + } + if (center+span/2 > STOP_MAX) { + center = STOP_MAX - span/2; + freq_start = center; + } + update_frequencies(); + } + break; + case ST_CW: + ensure_edit_config(); + freq_mode_centerspan(); + if (freq_start != frequency || freq_stop != 0) { + freq_start = frequency; + freq_stop = 0; update_frequencies(); } break; @@ -559,6 +595,10 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[]) int32_t value = atoi(argv[1]); set_sweep_frequency(ST_SPAN, value); return; + } else if (strcmp(argv[0], "cw") == 0) { + int32_t value = atoi(argv[1]); + set_sweep_frequency(ST_CW, value); + return; } } diff --git a/nanovna.h b/nanovna.h index 809cec7..5c4aa56 100644 --- a/nanovna.h +++ b/nanovna.h @@ -197,7 +197,7 @@ void cal_collect(int type); void cal_done(void); enum { - ST_START, ST_STOP, ST_CENTER, ST_SPAN + ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW }; void set_sweep_frequency(int type, int frequency); diff --git a/plot.c b/plot.c index 1636cfb..e027f7f 100644 --- a/plot.c +++ b/plot.c @@ -1251,7 +1251,7 @@ draw_frequencies(void) (int)((fstop / 1000) % 1000), (int)(fstop % 1000)); ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); - } else { + } else if (fstop < 0) { int fcenter = fstart; int fspan = -fstop; chsnprintf(buf, 24, "CENTER %d.%03d %03d MHz ", @@ -1264,6 +1264,15 @@ draw_frequencies(void) (int)((fspan / 1000) % 1000), (int)(fspan % 1000)); ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); + } else { + int fcenter = fstart; + chsnprintf(buf, 24, "CW %d.%03d %03d MHz ", + (int)(fcenter / 1000000), + (int)((fcenter / 1000) % 1000), + (int)(fcenter % 1000)); + ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); + chsnprintf(buf, 24, " "); + ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); } } diff --git a/ui.c b/ui.c index 8c6f918..741f8cd 100644 --- a/ui.c +++ b/ui.c @@ -60,7 +60,7 @@ enum { }; enum { - KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_SCALE + KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE }; uint8_t ui_mode = UI_NORMAL; @@ -305,6 +305,7 @@ menu_stimulus_cb(int item) case 1: case 2: case 3: + case 4: ui_mode_keypad(item); ui_process_keypad(); break; @@ -410,6 +411,7 @@ const menuitem_t menu_stimulus[] = { { MT_CALLBACK, "STOP", menu_stimulus_cb }, { MT_CALLBACK, "CENTER", menu_stimulus_cb }, { MT_CALLBACK, "SPAN", menu_stimulus_cb }, + { MT_CALLBACK, "CW", menu_stimulus_cb }, { MT_CANCEL, "BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -805,6 +807,9 @@ ui_process_keypad(void) case KM_SPAN: set_sweep_frequency(ST_SPAN, value); break; + case KM_CW: + set_sweep_frequency(ST_CW, value); + break; case KM_SCALE: set_trace_scale(uistat.current_trace, value); break;