add freq center/span

This commit is contained in:
TT 2016-12-11 21:51:54 +09:00
parent 8014d3442e
commit 52dce51f31
3 changed files with 113 additions and 44 deletions

102
main.c
View file

@ -453,35 +453,82 @@ void
update_frequencies(void) update_frequencies(void)
{ {
int i; int i;
int32_t span = (freq_stop - freq_start)/100; int32_t span;
int32_t start;
if (freq_stop > 0) {
start = freq_start;
span = (freq_stop - freq_start)/100;
} else {
span = -freq_stop / 100;
start = freq_start - span/2;
}
for (i = 0; i < sweep_points; i++) for (i = 0; i < sweep_points; i++)
frequencies[i] = freq_start + span * i / (sweep_points - 1) * 100; frequencies[i] = start + span * i / (sweep_points - 1) * 100;
// set grid layout // set grid layout
set_sweep(freq_start, freq_stop); set_sweep(freq_start, freq_stop);
} }
void
freq_mode_startstop(void)
{
if (freq_stop <= 0) {
int center = freq_start;
int span = -freq_stop;
freq_start = center - span/2;
freq_stop = center + span/2;
}
}
void
freq_mode_centerspan(void)
{
if (freq_stop > 0) {
int start = freq_start;
int stop = freq_stop;
freq_start = (start + stop)/2; // center
freq_stop = -(stop - start); // span
}
}
void void
set_sweep_frequency(int type, int frequency) set_sweep_frequency(int type, int frequency)
{ {
switch (type) { switch (type) {
case ST_START: case ST_START:
if (freq_start != frequency) {
ensure_edit_config(); ensure_edit_config();
freq_mode_startstop();
if (freq_start != frequency) {
freq_start = frequency; freq_start = frequency;
update_frequencies(); update_frequencies();
} }
break; break;
case ST_STOP: case ST_STOP:
if (freq_start != frequency) {
ensure_edit_config(); ensure_edit_config();
freq_mode_startstop();
if (freq_stop != frequency) {
freq_stop = frequency; freq_stop = frequency;
update_frequencies(); update_frequencies();
} }
break; break;
case ST_CENTER: case ST_CENTER:
ensure_edit_config();
freq_mode_centerspan();
if (freq_start != frequency) {
freq_start = frequency;
update_frequencies();
}
break; break;
case ST_SPAN: case ST_SPAN:
ensure_edit_config();
freq_mode_centerspan();
if (freq_stop != -frequency) {
freq_stop = -frequency;
update_frequencies();
}
break; break;
} }
} }
@ -495,35 +542,34 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
chprintf(chp, "usage: sweep {start(Hz)} [stop] [points]\r\n"); chprintf(chp, "usage: sweep {start(Hz)} [stop] [points]\r\n");
return; return;
} }
if (argc >= 1) { if (argc >= 2) {
ensure_edit_config(); if (strcmp(argv[0], "start") == 0) {
int32_t x = atoi(argv[0]); int32_t value = atoi(argv[1]);
if (x < 300000) { set_sweep_frequency(ST_START, value);
chprintf(chp, "bad parameter\r\n"); return;
} else if (strcmp(argv[0], "stop") == 0) {
int32_t value = atoi(argv[1]);
set_sweep_frequency(ST_STOP, value);
return;
} else if (strcmp(argv[0], "center") == 0) {
int32_t value = atoi(argv[1]);
set_sweep_frequency(ST_CENTER, value);
return;
} else if (strcmp(argv[0], "span") == 0) {
int32_t value = atoi(argv[1]);
set_sweep_frequency(ST_SPAN, value);
return; return;
} }
freq_start = x; }
if (argc >= 1) {
int32_t value = atoi(argv[0]);
set_sweep_frequency(ST_START, value);
} }
if (argc >= 2) { if (argc >= 2) {
int32_t x = atoi(argv[1]); int32_t value = atoi(argv[1]);
if (x < 300000 || x <= freq_start) { set_sweep_frequency(ST_STOP, value);
chprintf(chp, "bad parameter\r\n");
return;
} }
freq_stop = x;
}
#if 0
if (argc >= 3) {
int32_t x = atoi(argv[2]);
if (x < 1 || x > 1601) {
chprintf(chp, "bad parameter\r\n");
return;
}
sweep_points = x;
}
#endif
update_frequencies();
} }

21
plot.c
View file

@ -74,9 +74,15 @@ void set_sweep(int32_t start, int stop)
{ {
int32_t gdigit = 100000000; int32_t gdigit = 100000000;
int32_t grid; int32_t grid;
if (stop > 0) {
fstart = start; fstart = start;
fstop = stop; fstop = stop;
fspan = stop - start; fspan = stop - start;
} else {
fspan = -stop;
fstart = start;
fstop = stop;
}
while (gdigit > 100) { while (gdigit > 100) {
grid = 5 * gdigit; grid = 5 * gdigit;
@ -1234,6 +1240,7 @@ void
draw_frequencies(void) draw_frequencies(void)
{ {
char buf[24]; char buf[24];
if (fstop > 0) {
chsnprintf(buf, 24, "START %d.%03d %03d MHz ", chsnprintf(buf, 24, "START %d.%03d %03d MHz ",
(int)(fstart / 1000000), (int)(fstart / 1000000),
(int)((fstart / 1000) % 1000), (int)((fstart / 1000) % 1000),
@ -1244,6 +1251,20 @@ 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 {
int fcenter = fstart;
int fspan = -fstop;
chsnprintf(buf, 24, "CENTER %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, "SPAN %d.%03d %03d MHz",
(int)(fspan / 1000000),
(int)((fspan / 1000) % 1000),
(int)(fspan % 1000));
ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000);
}
} }
void void

4
ui.c
View file

@ -772,10 +772,12 @@ ui_process_keypad(void)
} else if (c <= 9 && i < NUMINPUT_LEN) } else if (c <= 9 && i < NUMINPUT_LEN)
buf[i++] = '0' + c; buf[i++] = '0' + c;
else if (c == KP_PERIOD && i < NUMINPUT_LEN) { else if (c == KP_PERIOD && i < NUMINPUT_LEN) {
// check period in former input
int j; int j;
for (j = 0; j < i && buf[j] != '.'; j++) for (j = 0; j < i && buf[j] != '.'; j++)
; ;
if (buf[j] != '.') // append period if there are no period
if (i == j)
buf[i++] = '.'; buf[i++] = '.';
} else if (c == KP_BS) { } else if (c == KP_BS) {
if (i == 0) { if (i == 0) {