add CW, mod freq from limits

This commit is contained in:
TT 2016-12-12 21:03:43 +09:00
parent 52dce51f31
commit aa91bc23fc
4 changed files with 57 additions and 3 deletions

40
main.c
View file

@ -494,6 +494,9 @@ freq_mode_centerspan(void)
} }
#define START_MIN 500000
#define STOP_MAX 300000000
void void
set_sweep_frequency(int type, int frequency) set_sweep_frequency(int type, int frequency)
{ {
@ -501,6 +504,8 @@ set_sweep_frequency(int type, int frequency)
case ST_START: case ST_START:
ensure_edit_config(); ensure_edit_config();
freq_mode_startstop(); freq_mode_startstop();
if (frequency < START_MIN)
frequency = START_MIN;
if (freq_start != frequency) { if (freq_start != frequency) {
freq_start = frequency; freq_start = frequency;
update_frequencies(); update_frequencies();
@ -509,6 +514,8 @@ set_sweep_frequency(int type, int frequency)
case ST_STOP: case ST_STOP:
ensure_edit_config(); ensure_edit_config();
freq_mode_startstop(); freq_mode_startstop();
if (frequency > STOP_MAX)
frequency = STOP_MAX;
if (freq_stop != frequency) { if (freq_stop != frequency) {
freq_stop = frequency; freq_stop = frequency;
update_frequencies(); update_frequencies();
@ -519,6 +526,16 @@ set_sweep_frequency(int type, int frequency)
freq_mode_centerspan(); freq_mode_centerspan();
if (freq_start != frequency) { if (freq_start != frequency) {
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(); update_frequencies();
} }
break; break;
@ -527,6 +544,25 @@ set_sweep_frequency(int type, int frequency)
freq_mode_centerspan(); freq_mode_centerspan();
if (freq_stop != -frequency) { if (freq_stop != -frequency) {
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(); update_frequencies();
} }
break; break;
@ -559,6 +595,10 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
int32_t value = atoi(argv[1]); int32_t value = atoi(argv[1]);
set_sweep_frequency(ST_SPAN, value); set_sweep_frequency(ST_SPAN, value);
return; return;
} else if (strcmp(argv[0], "cw") == 0) {
int32_t value = atoi(argv[1]);
set_sweep_frequency(ST_CW, value);
return;
} }
} }

View file

@ -197,7 +197,7 @@ void cal_collect(int type);
void cal_done(void); void cal_done(void);
enum { 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); void set_sweep_frequency(int type, int frequency);

11
plot.c
View file

@ -1251,7 +1251,7 @@ draw_frequencies(void)
(int)((fstop / 1000) % 1000), (int)((fstop / 1000) % 1000),
(int)(fstop % 1000)); (int)(fstop % 1000));
ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000);
} else { } else if (fstop < 0) {
int fcenter = fstart; int fcenter = fstart;
int fspan = -fstop; int fspan = -fstop;
chsnprintf(buf, 24, "CENTER %d.%03d %03d MHz ", chsnprintf(buf, 24, "CENTER %d.%03d %03d MHz ",
@ -1264,6 +1264,15 @@ draw_frequencies(void)
(int)((fspan / 1000) % 1000), (int)((fspan / 1000) % 1000),
(int)(fspan % 1000)); (int)(fspan % 1000));
ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); 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);
} }
} }

7
ui.c
View file

@ -60,7 +60,7 @@ enum {
}; };
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; uint8_t ui_mode = UI_NORMAL;
@ -305,6 +305,7 @@ menu_stimulus_cb(int item)
case 1: case 1:
case 2: case 2:
case 3: case 3:
case 4:
ui_mode_keypad(item); ui_mode_keypad(item);
ui_process_keypad(); ui_process_keypad();
break; break;
@ -410,6 +411,7 @@ const menuitem_t menu_stimulus[] = {
{ MT_CALLBACK, "STOP", menu_stimulus_cb }, { MT_CALLBACK, "STOP", menu_stimulus_cb },
{ MT_CALLBACK, "CENTER", menu_stimulus_cb }, { MT_CALLBACK, "CENTER", menu_stimulus_cb },
{ MT_CALLBACK, "SPAN", menu_stimulus_cb }, { MT_CALLBACK, "SPAN", menu_stimulus_cb },
{ MT_CALLBACK, "CW", menu_stimulus_cb },
{ MT_CANCEL, "BACK", NULL }, { MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
@ -805,6 +807,9 @@ ui_process_keypad(void)
case KM_SPAN: case KM_SPAN:
set_sweep_frequency(ST_SPAN, value); set_sweep_frequency(ST_SPAN, value);
break; break;
case KM_CW:
set_sweep_frequency(ST_CW, value);
break;
case KM_SCALE: case KM_SCALE:
set_trace_scale(uistat.current_trace, value); set_trace_scale(uistat.current_trace, value);
break; break;