add toggle sweep operation

pull/4/head
TT 9 years ago
parent 4845bde486
commit cb50a0e6c3

@ -40,6 +40,7 @@ int32_t frequency_offset = 5000;
int32_t frequency = 10000000; int32_t frequency = 10000000;
uint8_t drive_strength = SI5351_CLK_DRIVE_STRENGTH_2MA; uint8_t drive_strength = SI5351_CLK_DRIVE_STRENGTH_2MA;
int8_t frequency_updated = FALSE; int8_t frequency_updated = FALSE;
int8_t sweep_enabled = TRUE;
static THD_WORKING_AREA(waThread1, 440); static THD_WORKING_AREA(waThread1, 440);
static THD_FUNCTION(Thread1, arg) static THD_FUNCTION(Thread1, arg)
@ -48,22 +49,38 @@ static THD_FUNCTION(Thread1, arg)
chRegSetThreadName("blink"); chRegSetThreadName("blink");
while (1) { while (1) {
chMtxLock(&mutex); if (sweep_enabled) {
sweep(); chMtxLock(&mutex);
chMtxUnlock(&mutex); sweep();
chMtxUnlock(&mutex);
} else {
__WFI();
ui_process();
}
/* calculate trace coordinates */
plot_into_index(measured);
/* plot trace as raster */
draw_all_cells();
} }
} }
void void
pause_sweep(void) pause_sweep(void)
{ {
chMtxLock(&mutex); sweep_enabled = FALSE;
} }
void void
resume_sweep(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[]) 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[]) static void cmd_freq(BaseSequentialStream *chp, int argc, char *argv[])
{ {
int freq; int freq;
pause_sweep();
if (argc != 1) { if (argc != 1) {
chprintf(chp, "usage: freq {frequency(Hz)}\r\n"); chprintf(chp, "usage: freq {frequency(Hz)}\r\n");
return; return;
} }
pause_sweep();
chMtxLock(&mutex);
freq = atoi(argv[0]); freq = atoi(argv[0]);
set_frequency(freq); set_frequency(freq);
chMtxUnlock(&mutex);
} }
static void cmd_power(BaseSequentialStream *chp, int argc, char *argv[]) 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) if (argc == 1)
sel = atoi(argv[0]); sel = atoi(argv[0]);
if (sel == 0 || sel == 1) { if (sel == 0 || sel == 1) {
pause_sweep(); chMtxLock(&mutex);
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
chprintf(chp, "%f %f\r\n", measured[sel][i][0], measured[sel][i][1]); chprintf(chp, "%f %f\r\n", measured[sel][i][0], measured[sel][i][1]);
} }
chMtxUnlock(&mutex);
} else if (sel >= 2 && sel < 7) { } else if (sel >= 2 && sel < 7) {
pause_sweep(); chMtxLock(&mutex);
for (i = 0; i < sweep_points; i++) { 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]); chprintf(chp, "%f %f\r\n", cal_data[sel-2][i][0], cal_data[sel-2][i][1]);
} }
chMtxUnlock(&mutex);
} else { } else {
chprintf(chp, "usage: data [array]\r\n"); 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 i, j;
int len; int len;
pause_sweep();
if (argc == 1) if (argc == 1)
dump_selection = atoi(argv[0]); dump_selection = atoi(argv[0]);
@ -300,8 +320,10 @@ static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])
(void)argv; (void)argv;
pause_sweep(); pause_sweep();
chMtxLock(&mutex);
wait_dsp(4); wait_dsp(4);
calculate_gamma(gamma); calculate_gamma(gamma);
chMtxUnlock(&mutex);
chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]); 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; (void)argv;
pause_sweep(); pause_sweep();
chMtxLock(&mutex);
freq = frequency0; freq = frequency0;
step = (frequency1 - frequency0) / (sweep_points-1); step = (frequency1 - frequency0) / (sweep_points-1);
delay = set_frequency(freq); set_frequency(freq);
delay += 2; delay = 4;
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
freq = freq + step; freq = freq + step;
wait_dsp(delay+1); wait_dsp(delay);
delay = set_frequency(freq); delay = set_frequency(freq);
palClearPad(GPIOC, GPIOC_LED); palClearPad(GPIOC, GPIOC_LED);
calculate_gamma(gamma); calculate_gamma(gamma);
palSetPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);
chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]); chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]);
} }
chMtxUnlock(&mutex);
} }
// main loop for measurement // main loop for measurement
@ -426,12 +450,6 @@ void sweep(void)
if (cal_status & CALSTAT_APPLY) if (cal_status & CALSTAT_APPLY)
apply_error_term(); apply_error_term();
/* calculate trace coordinates */
plot_into_index(measured);
/* plot trace as raster */
draw_cell_all();
} }
void void
@ -920,12 +938,13 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
goto usage; goto usage;
pause_sweep(); pause_sweep();
chMtxLock(&mutex);
if (caldata_recall(id) == 0) { if (caldata_recall(id) == 0) {
// success // success
update_frequencies(); update_frequencies();
draw_cal_status(); draw_cal_status();
} }
chMtxUnlock(&mutex);
resume_sweep(); resume_sweep();
return; return;
@ -967,7 +986,6 @@ void set_trace_type(int t, int type)
} }
if (force) { if (force) {
plot_into_index(measured); plot_into_index(measured);
//force_draw_cells();
force_set_markmap(); force_set_markmap();
} }
} }
@ -1188,7 +1206,6 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[])
(void)argc; (void)argc;
(void)argv; (void)argv;
//pause_sweep();
#if 0 #if 0
int i; int i;
for (i = 0; i < 100; 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); float my_atof(const char *p);
void toggle_sweep(void);
/* /*
* ui.c * ui.c
*/ */
@ -201,11 +203,11 @@ typedef struct {
void plot_init(void); void plot_init(void);
void update_grid(void); void update_grid(void);
void redraw(void); void redraw(void);
void redraw_all(void);
void force_draw_cells(void); void force_draw_cells(void);
void redraw_marker(int marker, int update_info); void redraw_marker(int marker, int update_info);
void trace_get_info(int t, char *buf, int len); void trace_get_info(int t, char *buf, int len);
void plot_into_index(float measured[2][101][2]); void plot_into_index(float measured[2][101][2]);
void draw_cell_all(void);
void force_set_markmap(void); void force_set_markmap(void);
void draw_cal_status(void); void draw_cal_status(void);

@ -811,6 +811,7 @@ search_index(int x, int y, uint32_t index[101], int *i0, int *i1)
int i, j; int i, j;
int head = 0; int head = 0;
int tail = sweep_points; int tail = sweep_points;
i = 0;
x &= 0x03e0; x &= 0x03e0;
y &= 0x03e0; y &= 0x03e0;
while (head < tail) { while (head < tail) {
@ -848,6 +849,7 @@ search_index_x(int x, uint32_t index[101], int *i0, int *i1)
int head = 0; int head = 0;
int tail = sweep_points; int tail = sweep_points;
x &= 0x03e0; x &= 0x03e0;
i = 0;
while (head < tail) { while (head < tail) {
i = (head + tail) / 2; i = (head + tail) / 2;
if (x < CELL_X0(index[i])) 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 x0 = m * CELLWIDTH;
int y0 = n * CELLHEIGHT; int y0 = n * CELLHEIGHT;
int t, i; int t;
for (t = 0; t < TRACES_MAX; t++) { for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled) if (!trace[t].enabled)
continue; continue;
@ -1155,7 +1157,7 @@ draw_cell(int m, int n)
} }
void void
draw_cell_all(void) draw_all_cells(void)
{ {
int m, n; int m, n;
for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++) for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++)
@ -1183,7 +1185,7 @@ redraw_marker(int marker, int update_info)
if (update_info) if (update_info)
markmap[current_mappage][0] = 0xffff; markmap[current_mappage][0] = 0xffff;
draw_cell_all(); draw_all_cells();
} }
void void
@ -1361,6 +1363,14 @@ redraw(void)
draw_cal_status(); draw_cal_status();
} }
void
redraw_all(void)
{
redraw();
force_set_markmap();
draw_all_cells();
}
void void
plot_init(void) plot_init(void)
{ {

39
ui.c

@ -416,9 +416,7 @@ menu_trace_cb(int item)
uistat.current_trace = item; uistat.current_trace = item;
menu_move_back(); menu_move_back();
ui_mode_normal(); ui_mode_normal();
redraw(); redraw_all();
force_set_markmap();
draw_cell_all();
} }
static void static void
@ -443,9 +441,7 @@ menu_format_cb(int item)
} }
ui_mode_normal(); ui_mode_normal();
redraw(); redraw_all();
force_set_markmap();
draw_cell_all();
} }
static void static void
@ -495,9 +491,7 @@ menu_single_trace_cb(int item)
trace[t].enabled = FALSE; trace[t].enabled = FALSE;
} }
ui_mode_normal(); ui_mode_normal();
redraw(); redraw_all();
force_set_markmap();
draw_cell_all();
} }
static void static void
@ -520,7 +514,10 @@ menu_stimulus_cb(int item)
ui_mode_keypad(item); ui_mode_keypad(item);
ui_process_keypad(); ui_process_keypad();
break; break;
case 5: /* pause && resume */ case 5:
toggle_sweep();
menu_move_back();
ui_mode_normal();
break; break;
} }
} }
@ -549,9 +546,7 @@ menu_marker_op_cb(int item)
break; break;
} }
ui_mode_normal(); ui_mode_normal();
redraw(); redraw_all();
force_set_markmap();
//draw_cell_all();
} }
static void static void
@ -682,7 +677,7 @@ const menuitem_t menu_stimulus[] = {
{ 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 FREQ", 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_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
@ -764,6 +759,7 @@ static void menu_push_submenu(const menuitem_t *submenu)
draw_menu(); draw_menu();
} }
/*
static void menu_move_top(void) static void menu_move_top(void)
{ {
if (menu_current_level == 0) if (menu_current_level == 0)
@ -773,6 +769,7 @@ static void menu_move_top(void)
erase_menu_buttons(); erase_menu_buttons();
draw_menu(); draw_menu();
} }
*/
void menu_invoke(int item) 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) { if (menu == menu_trace && item < 4) {
*bg = config.trace_color[item]; *bg = config.trace_color[item];
} else if (menu == menu_calop) { } else if (menu == menu_calop) {
if (item == 0 && (cal_status & CALSTAT_OPEN) if ((item == 0 && (cal_status & CALSTAT_OPEN))
|| item == 1 && (cal_status & CALSTAT_SHORT) || (item == 1 && (cal_status & CALSTAT_SHORT))
|| item == 2 && (cal_status & CALSTAT_LOAD) || (item == 2 && (cal_status & CALSTAT_LOAD))
|| item == 3 && (cal_status & CALSTAT_ISOLN) || (item == 3 && (cal_status & CALSTAT_ISOLN))
|| item == 4 && (cal_status & CALSTAT_THRU)) { || (item == 4 && (cal_status & CALSTAT_THRU))) {
*bg = 0x0000; *bg = 0x0000;
*fg = 0xffff; *fg = 0xffff;
} }
@ -1197,9 +1194,7 @@ ui_process_keypad(void)
} }
ui_mode_normal(); ui_mode_normal();
redraw(); redraw_all();
force_set_markmap();
draw_cell_all();
} }
void void

Loading…
Cancel
Save

Powered by TurnKey Linux.