fix trace becoming broken line

This commit is contained in:
TT 2017-01-17 02:19:10 +09:00
parent cb50a0e6c3
commit 75ea6308ed
2 changed files with 11 additions and 7 deletions

3
main.c
View file

@ -421,7 +421,7 @@ void sweep(void)
rewind: rewind:
frequency_updated = FALSE; frequency_updated = FALSE;
delay = 4; delay = 5;
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
set_frequency(frequencies[i]); set_frequency(frequencies[i]);
@ -447,6 +447,7 @@ void sweep(void)
if (frequency_updated) if (frequency_updated)
goto rewind; goto rewind;
} }
set_frequency(frequencies[0]);
if (cal_status & CALSTAT_APPLY) if (cal_status & CALSTAT_APPLY)
apply_error_term(); apply_error_term();

15
plot.c
View file

@ -806,7 +806,7 @@ cell_drawline(int w, int h, int x0, int y0, int x1, int y1, int c)
} }
int int
search_index(int x, int y, uint32_t index[101], int *i0, int *i1) search_index_range(int x, int y, uint32_t index[101], int *i0, int *i1)
{ {
int i, j; int i, j;
int head = 0; int head = 0;
@ -843,7 +843,7 @@ search_index(int x, int y, uint32_t index[101], int *i0, int *i1)
} }
int int
search_index_x(int x, uint32_t index[101], int *i0, int *i1) search_index_range_x(int x, uint32_t index[101], int *i0, int *i1)
{ {
int i, j; int i, j;
int head = 0; int head = 0;
@ -852,12 +852,13 @@ search_index_x(int x, uint32_t index[101], int *i0, int *i1)
i = 0; i = 0;
while (head < tail) { while (head < tail) {
i = (head + tail) / 2; i = (head + tail) / 2;
if (x == CELL_X0(index[i]))
break;
if (x < CELL_X0(index[i])) if (x < CELL_X0(index[i]))
tail = i+1; tail = i+1;
else if (x > CELL_X0(index[i]))
head = i;
else else
break; head = i;
} }
if (x != CELL_X0(index[i])) if (x != CELL_X0(index[i]))
@ -1106,9 +1107,11 @@ draw_cell(int m, int n)
if (trace[t].type == TRC_SMITH || trace[t].type == TRC_POLAR) if (trace[t].type == TRC_SMITH || trace[t].type == TRC_POLAR)
continue; continue;
if (search_index_x(x0, trace_index[t], &i0, &i1)) { if (search_index_range_x(x0, trace_index[t], &i0, &i1)) {
if (i0 > 0) if (i0 > 0)
i0--; i0--;
if (i1 < 101-1)
i1++;
for (i = i0; i < i1; i++) { for (i = i0; i < i1; i++) {
int x1 = CELL_X(trace_index[t][i]); int x1 = CELL_X(trace_index[t][i]);
int x2 = CELL_X(trace_index[t][i+1]); int x2 = CELL_X(trace_index[t][i+1]);