add refpos indicator, make marker able to be sticking out

This commit is contained in:
TT 2017-01-15 23:27:05 +09:00
parent 6bb1a588b6
commit c083fb9298
4 changed files with 107 additions and 29 deletions

28
main.c
View file

@ -338,10 +338,10 @@ properties_t current_props = {
/* cal_data */ {}, /* cal_data */ {},
/* trace[4] */ /* trace[4] */
{/*enable, type, channel, polar, scale*/ {/*enable, type, channel, polar, scale*/
{ 1, TRC_LOGMAG, 0, 0, 1.0 }, { 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
{ 1, TRC_LOGMAG, 1, 0, 1.0 }, { 1, TRC_LOGMAG, 1, 0, 1.0, 7.0 },
{ 1, TRC_SMITH, 0, 1, 1.0 }, { 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
{ 1, TRC_PHASE, 1, 0, 1.0 } { 1, TRC_PHASE, 1, 0, 1.0, 4.0 }
}, },
/* markers[4] */ { /* markers[4] */ {
{ 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 } { 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 }
@ -946,6 +946,10 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
const char *trc_type_name[] = { const char *trc_type_name[] = {
"LOGMAG", "PHASE", "DELAY", "SMITH", "POLAR", "LINEAR", "SWR" "LOGMAG", "PHASE", "DELAY", "SMITH", "POLAR", "LINEAR", "SWR"
}; };
const uint8_t default_refpos[] = {
7, 4, 4, 0, 0, 0, 0
};
const char *trc_channel_name[] = { const char *trc_channel_name[] = {
"CH0", "CH1" "CH0", "CH1"
}; };
@ -966,6 +970,7 @@ void set_trace_type(int t, int type)
} }
if (trace[t].type != type) { if (trace[t].type != type) {
trace[t].type = type; trace[t].type = type;
trace[t].refpos = default_refpos[type];
if (polar) if (polar)
force = TRUE; force = TRUE;
} }
@ -992,6 +997,14 @@ void set_trace_scale(int t, float scale)
} }
} }
void set_trace_refpos(int t, float refpos)
{
if (trace[t].refpos != refpos) {
trace[t].refpos = refpos;
force_set_markmap();
}
}
float float
my_atof(const char *p) my_atof(const char *p)
{ {
@ -1079,7 +1092,12 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
} else if (strcmp(argv[1], "off") == 0) { } else if (strcmp(argv[1], "off") == 0) {
set_trace_type(t, TRC_OFF); set_trace_type(t, TRC_OFF);
} else if (strcmp(argv[1], "scale") == 0 && argc >= 3) { } else if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
trace[t].scale = my_atof(argv[2]); //trace[t].scale = my_atof(argv[2]);
set_trace_scale(t, my_atof(argv[2]));
goto exit;
} else if (strcmp(argv[1], "refpos") == 0 && argc >= 3) {
//trace[t].refpos = my_atof(argv[2]);
set_trace_refpos(t, my_atof(argv[2]));
goto exit; goto exit;
} }
} }

View file

@ -120,6 +120,9 @@ extern void tlv320aic3204_adc_filter_enable(int enable);
#define WIDTH 291 #define WIDTH 291
#define HEIGHT 233 #define HEIGHT 233
#define CELLOFFSETX 5
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
extern int area_width; extern int area_width;
extern int area_height; extern int area_height;
@ -162,7 +165,7 @@ typedef struct {
uint8_t channel; uint8_t channel;
uint8_t polar; uint8_t polar;
float scale; float scale;
//float ref; float refpos;
} trace_t; } trace_t;
typedef struct { typedef struct {

86
plot.c
View file

@ -23,7 +23,7 @@ int32_t fgrid = 50000000;
int16_t grid_offset; int16_t grid_offset;
int16_t grid_width; int16_t grid_width;
int area_width = WIDTH; int area_width = AREA_WIDTH_NORMAL;
int area_height = HEIGHT; int area_height = HEIGHT;
#define GRID_RECTANGULAR (1<<0) #define GRID_RECTANGULAR (1<<0)
@ -354,7 +354,7 @@ rectangular_grid(int x, int y)
//if ((m - n) > 0) //if ((m - n) > 0)
//if (((x * 6) % (WIDTH-1)) < 6) //if (((x * 6) % (WIDTH-1)) < 6)
//if (((x - grid_offset) % grid_width) == 0) //if (((x - grid_offset) % grid_width) == 0)
if (x == 0 || x == (WIDTH-1)) if (x == 0 || x == WIDTH-1)
return c; return c;
if ((y % GRIDY) == 0) if ((y % GRIDY) == 0)
return c; return c;
@ -368,7 +368,9 @@ int
rectangular_grid_x(int x) rectangular_grid_x(int x)
{ {
int c = config.grid_color; int c = config.grid_color;
if (x == 0 || x == (WIDTH-1)) if (x < 0)
return 0;
if (x == 0 || x == WIDTH)
return c; return c;
if ((((x + grid_offset) * 10) % grid_width) < 10) if ((((x + grid_offset) * 10) % grid_width) < 10)
return c; return c;
@ -379,6 +381,8 @@ int
rectangular_grid_y(int y) rectangular_grid_y(int y)
{ {
int c = config.grid_color; int c = config.grid_color;
if (y < 0)
return 0;
if ((y % GRIDY) == 0) if ((y % GRIDY) == 0)
return c; return c;
return 0; return 0;
@ -476,30 +480,31 @@ trace_into_index(int x, int t, int i, float coeff[2])
{ {
int y = 0; int y = 0;
float v = 0; float v = 0;
float refpos = 8 - trace[t].refpos;
switch (trace[t].type) { switch (trace[t].type) {
case TRC_LOGMAG: case TRC_LOGMAG:
v = 1 - logmag(coeff); v = refpos - logmag(coeff);
break; break;
case TRC_PHASE: case TRC_PHASE:
v = 4 - phase(coeff); v = refpos - phase(coeff);
break; break;
case TRC_LINEAR: case TRC_LINEAR:
v = 8 + linear(coeff); v = refpos + linear(coeff);
break; break;
case TRC_SWR: case TRC_SWR:
v = 9 - swr(coeff); v = refpos+1 - swr(coeff);
break; break;
case TRC_SMITH: case TRC_SMITH:
//case TRC_ADMIT: //case TRC_ADMIT:
case TRC_POLAR: case TRC_POLAR:
cartesian_scale(coeff[0], coeff[1], &x, &y, trace[t].scale); cartesian_scale(coeff[0], coeff[1], &x, &y, trace[t].scale);
return INDEX(x, y, i); return INDEX(x +CELLOFFSETX, y, i);
break; break;
} }
if (v < 0) v = 0; if (v < 0) v = 0;
if (v > 8) v = 8; if (v > 8) v = 8;
y = v * GRIDY; y = v * GRIDY;
return INDEX(x, y, i); return INDEX(x +CELLOFFSETX, y, i);
} }
int int
@ -867,6 +872,46 @@ search_index_x(int x, uint32_t index[101], int *i0, int *i1)
return TRUE; return TRUE;
} }
void
draw_refpos(int w, int h, int x, int y, int c)
{
// draw triangle
int i, j;
if (y < -3 || y > 32 + 3)
return;
for (j = 0; j < 3; j++) {
int j0 = 6 - j*2;
for (i = 0; i < j0; i++) {
int x0 = x + i-5;
int y0 = y - j;
int y1 = y + j;
if (y0 >= 0 && y0 < h && x0 >= 0 && x0 < w)
spi_buffer[y0*w+x0] = c;
if (j != 0 && y1 >= 0 && y1 < h && x0 >= 0 && x0 < w)
spi_buffer[y1*w+x0] = c;
}
}
}
void
cell_draw_refpos(int m, int n, int w, int h)
{
int x0 = m * CELLWIDTH;
int y0 = n * CELLHEIGHT;
int t, i;
for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled)
continue;
if (trace[t].type == TRC_SMITH || trace[t].type == TRC_POLAR)
continue;
int x = 0 - x0 +CELLOFFSETX;
int y = 8*GRIDY - (int)(trace[t].refpos * GRIDY) - y0;
if (x > -5 && x < w && y >= -3 && y < h+3)
draw_refpos(w, h, x, y, config.trace_color[t]);
}
}
void void
draw_marker(int w, int h, int x, int y, int c, int ch) draw_marker(int w, int h, int x, int y, int c, int ch)
{ {
@ -987,6 +1032,7 @@ draw_cell(int m, int n)
{ {
int x0 = m * CELLWIDTH; int x0 = m * CELLWIDTH;
int y0 = n * CELLHEIGHT; int y0 = n * CELLHEIGHT;
int x0off = x0 - CELLOFFSETX;
int w = CELLWIDTH; int w = CELLWIDTH;
int h = CELLHEIGHT; int h = CELLHEIGHT;
int x, y; int x, y;
@ -994,8 +1040,8 @@ draw_cell(int m, int n)
int i; int i;
int t; int t;
if (x0 + w > area_width) if (x0off + w > area_width)
w = area_width - x0; w = area_width - x0off;
if (y0 + h > area_height) if (y0 + h > area_height)
h = area_height - y0; h = area_height - y0;
if (w <= 0 || h <= 0) if (w <= 0 || h <= 0)
@ -1020,13 +1066,14 @@ draw_cell(int m, int n)
/* draw grid */ /* draw grid */
if (grid_mode & GRID_RECTANGULAR) { if (grid_mode & GRID_RECTANGULAR) {
for (x = 0; x < w; x++) { for (x = 0; x < w; x++) {
uint16_t c = rectangular_grid_x(x+x0); uint16_t c = rectangular_grid_x(x+x0off);
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
spi_buffer[y * w + x] = c; spi_buffer[y * w + x] = c;
} }
for (y = 0; y < h; y++) { for (y = 0; y < h; y++) {
uint16_t c = rectangular_grid_y(y+y0); uint16_t c = rectangular_grid_y(y+y0);
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
if (x+x0off >= 0 && x+x0off <= WIDTH)
spi_buffer[y * w + x] |= c; spi_buffer[y * w + x] |= c;
} }
} else { } else {
@ -1037,12 +1084,12 @@ draw_cell(int m, int n)
for (x = 0; x < w; x++) { for (x = 0; x < w; x++) {
uint16_t c = 0; uint16_t c = 0;
if (grid_mode & GRID_SMITH) if (grid_mode & GRID_SMITH)
c = smith_grid(x+x0, y+y0); c = smith_grid(x+x0off, y+y0);
else if (grid_mode & GRID_ADMIT) else if (grid_mode & GRID_ADMIT)
c = smith_grid3(x+x0, y+y0); c = smith_grid3(x+x0off, y+y0);
//c = smith_grid2(x+x0, y+y0, 0.5); //c = smith_grid2(x+x0, y+y0, 0.5);
else if (grid_mode & GRID_POLAR) else if (grid_mode & GRID_POLAR)
c = polar_grid(x+x0, y+y0); c = polar_grid(x+x0off, y+y0);
spi_buffer[y * w + x] |= c; spi_buffer[y * w + x] |= c;
} }
} }
@ -1101,7 +1148,10 @@ draw_cell(int m, int n)
cell_draw_marker_info(m, n, w, h); cell_draw_marker_info(m, n, w, h);
PULSE; PULSE;
ili9341_bulk(OFFSETX + x0, OFFSETY + y0, w, h); if (m == 0)
cell_draw_refpos(m, n, w, h);
ili9341_bulk(OFFSETX + x0off, OFFSETY + y0, w, h);
} }
void void
@ -1191,7 +1241,7 @@ cell_draw_marker_info(int m, int n, int w, int h)
continue; continue;
int xpos = 1 + (j%2)*146; int xpos = 1 + (j%2)*146;
int ypos = 1 + (j/2)*7; int ypos = 1 + (j/2)*7;
xpos -= m * CELLWIDTH; xpos -= m * CELLWIDTH -CELLOFFSETX;
ypos -= n * CELLHEIGHT; ypos -= n * CELLHEIGHT;
trace_get_info(t, buf, sizeof buf); trace_get_info(t, buf, sizeof buf);
cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]); cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]);
@ -1203,7 +1253,7 @@ cell_draw_marker_info(int m, int n, int w, int h)
int xpos = 192; int xpos = 192;
int ypos = 1 + (j/2)*7; int ypos = 1 + (j/2)*7;
xpos -= m * CELLWIDTH; xpos -= m * CELLWIDTH -CELLOFFSETX;
ypos -= n * CELLHEIGHT; ypos -= n * CELLHEIGHT;
chsnprintf(buf, sizeof buf, "%d:", active_marker + 1); chsnprintf(buf, sizeof buf, "%d:", active_marker + 1);
cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff);

13
ui.c
View file

@ -415,6 +415,10 @@ menu_trace_cb(int item)
trace[item].enabled = TRUE; trace[item].enabled = TRUE;
uistat.current_trace = item; uistat.current_trace = item;
menu_move_back(); menu_move_back();
ui_mode_normal();
redraw();
force_set_markmap();
draw_cell_all();
} }
static void static void
@ -439,6 +443,9 @@ menu_format_cb(int item)
} }
ui_mode_normal(); ui_mode_normal();
redraw();
force_set_markmap();
draw_cell_all();
} }
static void static void
@ -986,7 +993,7 @@ ui_mode_menu(void)
ui_mode = UI_MENU; ui_mode = UI_MENU;
/* narrowen plotting area */ /* narrowen plotting area */
area_width = WIDTH - (64-14-4); area_width = AREA_WIDTH_NORMAL - (64-8);
area_height = HEIGHT; area_height = HEIGHT;
ensure_selection(); ensure_selection();
draw_menu(); draw_menu();
@ -999,7 +1006,7 @@ ui_mode_keypad(int _keypad_mode)
return; return;
ui_mode = UI_KEYPAD; ui_mode = UI_KEYPAD;
area_width = WIDTH - (64-14-4); area_width = AREA_WIDTH_NORMAL - (64-8);
area_height = HEIGHT; area_height = HEIGHT;
draw_menu(); draw_menu();
draw_keypad(); draw_keypad();
@ -1014,7 +1021,7 @@ ui_mode_normal(void)
return; return;
ui_mode = UI_NORMAL; ui_mode = UI_NORMAL;
area_width = WIDTH; area_width = AREA_WIDTH_NORMAL;
area_height = HEIGHT; area_height = HEIGHT;
erase_menu_buttons(); erase_menu_buttons();
force_draw_cells(); force_draw_cells();