mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2026-01-17 22:10:01 +01:00
add toggle sweep operation
This commit is contained in:
parent
4845bde486
commit
cb50a0e6c3
59
main.c
59
main.c
|
|
@ -40,6 +40,7 @@ int32_t frequency_offset = 5000;
|
|||
int32_t frequency = 10000000;
|
||||
uint8_t drive_strength = SI5351_CLK_DRIVE_STRENGTH_2MA;
|
||||
int8_t frequency_updated = FALSE;
|
||||
int8_t sweep_enabled = TRUE;
|
||||
|
||||
static THD_WORKING_AREA(waThread1, 440);
|
||||
static THD_FUNCTION(Thread1, arg)
|
||||
|
|
@ -48,22 +49,38 @@ static THD_FUNCTION(Thread1, arg)
|
|||
chRegSetThreadName("blink");
|
||||
|
||||
while (1) {
|
||||
chMtxLock(&mutex);
|
||||
sweep();
|
||||
chMtxUnlock(&mutex);
|
||||
if (sweep_enabled) {
|
||||
chMtxLock(&mutex);
|
||||
sweep();
|
||||
chMtxUnlock(&mutex);
|
||||
} else {
|
||||
__WFI();
|
||||
ui_process();
|
||||
}
|
||||
|
||||
/* calculate trace coordinates */
|
||||
plot_into_index(measured);
|
||||
/* plot trace as raster */
|
||||
draw_all_cells();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pause_sweep(void)
|
||||
{
|
||||
chMtxLock(&mutex);
|
||||
sweep_enabled = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
resume_sweep(void)
|
||||
{
|
||||
chMtxUnlockAll();
|
||||
sweep_enabled = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
toggle_sweep(void)
|
||||
{
|
||||
sweep_enabled = !sweep_enabled;
|
||||
}
|
||||
|
||||
static void cmd_pause(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
|
|
@ -122,13 +139,15 @@ static void cmd_offset(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
static void cmd_freq(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
{
|
||||
int freq;
|
||||
pause_sweep();
|
||||
if (argc != 1) {
|
||||
chprintf(chp, "usage: freq {frequency(Hz)}\r\n");
|
||||
return;
|
||||
}
|
||||
pause_sweep();
|
||||
chMtxLock(&mutex);
|
||||
freq = atoi(argv[0]);
|
||||
set_frequency(freq);
|
||||
chMtxUnlock(&mutex);
|
||||
}
|
||||
|
||||
static void cmd_power(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
|
|
@ -257,15 +276,17 @@ static void cmd_data(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
if (argc == 1)
|
||||
sel = atoi(argv[0]);
|
||||
if (sel == 0 || sel == 1) {
|
||||
pause_sweep();
|
||||
chMtxLock(&mutex);
|
||||
for (i = 0; i < sweep_points; i++) {
|
||||
chprintf(chp, "%f %f\r\n", measured[sel][i][0], measured[sel][i][1]);
|
||||
}
|
||||
chMtxUnlock(&mutex);
|
||||
} else if (sel >= 2 && sel < 7) {
|
||||
pause_sweep();
|
||||
chMtxLock(&mutex);
|
||||
for (i = 0; i < sweep_points; i++) {
|
||||
chprintf(chp, "%f %f\r\n", cal_data[sel-2][i][0], cal_data[sel-2][i][1]);
|
||||
}
|
||||
chMtxUnlock(&mutex);
|
||||
} else {
|
||||
chprintf(chp, "usage: data [array]\r\n");
|
||||
}
|
||||
|
|
@ -276,7 +297,6 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
int i, j;
|
||||
int len;
|
||||
|
||||
pause_sweep();
|
||||
if (argc == 1)
|
||||
dump_selection = atoi(argv[0]);
|
||||
|
||||
|
|
@ -300,8 +320,10 @@ static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
(void)argv;
|
||||
|
||||
pause_sweep();
|
||||
chMtxLock(&mutex);
|
||||
wait_dsp(4);
|
||||
calculate_gamma(gamma);
|
||||
chMtxUnlock(&mutex);
|
||||
|
||||
chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]);
|
||||
}
|
||||
|
|
@ -374,19 +396,21 @@ static void cmd_scan(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
(void)argv;
|
||||
|
||||
pause_sweep();
|
||||
chMtxLock(&mutex);
|
||||
freq = frequency0;
|
||||
step = (frequency1 - frequency0) / (sweep_points-1);
|
||||
delay = set_frequency(freq);
|
||||
delay += 2;
|
||||
set_frequency(freq);
|
||||
delay = 4;
|
||||
for (i = 0; i < sweep_points; i++) {
|
||||
freq = freq + step;
|
||||
wait_dsp(delay+1);
|
||||
wait_dsp(delay);
|
||||
delay = set_frequency(freq);
|
||||
palClearPad(GPIOC, GPIOC_LED);
|
||||
calculate_gamma(gamma);
|
||||
palSetPad(GPIOC, GPIOC_LED);
|
||||
chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]);
|
||||
}
|
||||
chMtxUnlock(&mutex);
|
||||
}
|
||||
|
||||
// main loop for measurement
|
||||
|
|
@ -426,12 +450,6 @@ void sweep(void)
|
|||
|
||||
if (cal_status & CALSTAT_APPLY)
|
||||
apply_error_term();
|
||||
|
||||
/* calculate trace coordinates */
|
||||
plot_into_index(measured);
|
||||
|
||||
/* plot trace as raster */
|
||||
draw_cell_all();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -920,12 +938,13 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
goto usage;
|
||||
|
||||
pause_sweep();
|
||||
chMtxLock(&mutex);
|
||||
if (caldata_recall(id) == 0) {
|
||||
// success
|
||||
update_frequencies();
|
||||
draw_cal_status();
|
||||
}
|
||||
|
||||
chMtxUnlock(&mutex);
|
||||
resume_sweep();
|
||||
return;
|
||||
|
||||
|
|
@ -967,7 +986,6 @@ void set_trace_type(int t, int type)
|
|||
}
|
||||
if (force) {
|
||||
plot_into_index(measured);
|
||||
//force_draw_cells();
|
||||
force_set_markmap();
|
||||
}
|
||||
}
|
||||
|
|
@ -1188,7 +1206,6 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
//pause_sweep();
|
||||
#if 0
|
||||
int i;
|
||||
for (i = 0; i < 100; i++) {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ void set_sweep_frequency(int type, float frequency);
|
|||
|
||||
float my_atof(const char *p);
|
||||
|
||||
void toggle_sweep(void);
|
||||
|
||||
/*
|
||||
* ui.c
|
||||
*/
|
||||
|
|
@ -201,11 +203,11 @@ typedef struct {
|
|||
void plot_init(void);
|
||||
void update_grid(void);
|
||||
void redraw(void);
|
||||
void redraw_all(void);
|
||||
void force_draw_cells(void);
|
||||
void redraw_marker(int marker, int update_info);
|
||||
void trace_get_info(int t, char *buf, int len);
|
||||
void plot_into_index(float measured[2][101][2]);
|
||||
void draw_cell_all(void);
|
||||
void force_set_markmap(void);
|
||||
|
||||
void draw_cal_status(void);
|
||||
|
|
|
|||
16
plot.c
16
plot.c
|
|
@ -811,6 +811,7 @@ search_index(int x, int y, uint32_t index[101], int *i0, int *i1)
|
|||
int i, j;
|
||||
int head = 0;
|
||||
int tail = sweep_points;
|
||||
i = 0;
|
||||
x &= 0x03e0;
|
||||
y &= 0x03e0;
|
||||
while (head < tail) {
|
||||
|
|
@ -848,6 +849,7 @@ search_index_x(int x, uint32_t index[101], int *i0, int *i1)
|
|||
int head = 0;
|
||||
int tail = sweep_points;
|
||||
x &= 0x03e0;
|
||||
i = 0;
|
||||
while (head < tail) {
|
||||
i = (head + tail) / 2;
|
||||
if (x < CELL_X0(index[i]))
|
||||
|
|
@ -899,7 +901,7 @@ cell_draw_refpos(int m, int n, int w, int h)
|
|||
{
|
||||
int x0 = m * CELLWIDTH;
|
||||
int y0 = n * CELLHEIGHT;
|
||||
int t, i;
|
||||
int t;
|
||||
for (t = 0; t < TRACES_MAX; t++) {
|
||||
if (!trace[t].enabled)
|
||||
continue;
|
||||
|
|
@ -1155,7 +1157,7 @@ draw_cell(int m, int n)
|
|||
}
|
||||
|
||||
void
|
||||
draw_cell_all(void)
|
||||
draw_all_cells(void)
|
||||
{
|
||||
int m, n;
|
||||
for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++)
|
||||
|
|
@ -1183,7 +1185,7 @@ redraw_marker(int marker, int update_info)
|
|||
if (update_info)
|
||||
markmap[current_mappage][0] = 0xffff;
|
||||
|
||||
draw_cell_all();
|
||||
draw_all_cells();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -1361,6 +1363,14 @@ redraw(void)
|
|||
draw_cal_status();
|
||||
}
|
||||
|
||||
void
|
||||
redraw_all(void)
|
||||
{
|
||||
redraw();
|
||||
force_set_markmap();
|
||||
draw_all_cells();
|
||||
}
|
||||
|
||||
void
|
||||
plot_init(void)
|
||||
{
|
||||
|
|
|
|||
39
ui.c
39
ui.c
|
|
@ -416,9 +416,7 @@ menu_trace_cb(int item)
|
|||
uistat.current_trace = item;
|
||||
menu_move_back();
|
||||
ui_mode_normal();
|
||||
redraw();
|
||||
force_set_markmap();
|
||||
draw_cell_all();
|
||||
redraw_all();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -443,9 +441,7 @@ menu_format_cb(int item)
|
|||
}
|
||||
|
||||
ui_mode_normal();
|
||||
redraw();
|
||||
force_set_markmap();
|
||||
draw_cell_all();
|
||||
redraw_all();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -495,9 +491,7 @@ menu_single_trace_cb(int item)
|
|||
trace[t].enabled = FALSE;
|
||||
}
|
||||
ui_mode_normal();
|
||||
redraw();
|
||||
force_set_markmap();
|
||||
draw_cell_all();
|
||||
redraw_all();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -520,7 +514,10 @@ menu_stimulus_cb(int item)
|
|||
ui_mode_keypad(item);
|
||||
ui_process_keypad();
|
||||
break;
|
||||
case 5: /* pause && resume */
|
||||
case 5:
|
||||
toggle_sweep();
|
||||
menu_move_back();
|
||||
ui_mode_normal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -549,9 +546,7 @@ menu_marker_op_cb(int item)
|
|||
break;
|
||||
}
|
||||
ui_mode_normal();
|
||||
redraw();
|
||||
force_set_markmap();
|
||||
//draw_cell_all();
|
||||
redraw_all();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -682,7 +677,7 @@ const menuitem_t menu_stimulus[] = {
|
|||
{ MT_CALLBACK, "CENTER", menu_stimulus_cb },
|
||||
{ MT_CALLBACK, "SPAN", menu_stimulus_cb },
|
||||
{ MT_CALLBACK, "CW FREQ", menu_stimulus_cb },
|
||||
{ MT_CALLBACK, "PAUSE", menu_stimulus_cb },
|
||||
{ MT_CALLBACK, "\2TOGGLE\0SWEEP", menu_stimulus_cb },
|
||||
{ MT_CANCEL, "BACK", NULL },
|
||||
{ MT_NONE, NULL, NULL } // sentinel
|
||||
};
|
||||
|
|
@ -764,6 +759,7 @@ static void menu_push_submenu(const menuitem_t *submenu)
|
|||
draw_menu();
|
||||
}
|
||||
|
||||
/*
|
||||
static void menu_move_top(void)
|
||||
{
|
||||
if (menu_current_level == 0)
|
||||
|
|
@ -773,6 +769,7 @@ static void menu_move_top(void)
|
|||
erase_menu_buttons();
|
||||
draw_menu();
|
||||
}
|
||||
*/
|
||||
|
||||
void menu_invoke(int item)
|
||||
{
|
||||
|
|
@ -899,11 +896,11 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
|
|||
if (menu == menu_trace && item < 4) {
|
||||
*bg = config.trace_color[item];
|
||||
} else if (menu == menu_calop) {
|
||||
if (item == 0 && (cal_status & CALSTAT_OPEN)
|
||||
|| item == 1 && (cal_status & CALSTAT_SHORT)
|
||||
|| item == 2 && (cal_status & CALSTAT_LOAD)
|
||||
|| item == 3 && (cal_status & CALSTAT_ISOLN)
|
||||
|| item == 4 && (cal_status & CALSTAT_THRU)) {
|
||||
if ((item == 0 && (cal_status & CALSTAT_OPEN))
|
||||
|| (item == 1 && (cal_status & CALSTAT_SHORT))
|
||||
|| (item == 2 && (cal_status & CALSTAT_LOAD))
|
||||
|| (item == 3 && (cal_status & CALSTAT_ISOLN))
|
||||
|| (item == 4 && (cal_status & CALSTAT_THRU))) {
|
||||
*bg = 0x0000;
|
||||
*fg = 0xffff;
|
||||
}
|
||||
|
|
@ -1197,9 +1194,7 @@ ui_process_keypad(void)
|
|||
}
|
||||
|
||||
ui_mode_normal();
|
||||
redraw();
|
||||
force_set_markmap();
|
||||
draw_cell_all();
|
||||
redraw_all();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Reference in a new issue