add polar_grid, experimental smith_grid2

This commit is contained in:
TT 2016-11-27 00:47:21 +09:00
parent 1f64bb759b
commit 121691b5e1
4 changed files with 261 additions and 18 deletions

View file

@ -116,7 +116,7 @@ typedef struct {
uint8_t polar;
} trace_t;
//extern trace_t trace[TRACES_MAX];
extern trace_t trace[TRACES_MAX];
typedef struct {
int enabled;
@ -138,6 +138,8 @@ void draw_cell_all(void);
void draw_cal_status(void);
void markmap_all_markers(void);
/*
* main.c

170
plot.c
View file

@ -112,45 +112,191 @@ circle_inout(int x, int y, int r)
}
#define POLAR_CENTER_X 146
#define POLAR_CENTER_Y 116
#define POLAR_RADIUS 116
#define P_CENTER_X 146
#define P_CENTER_Y 116
#define P_RADIUS 116
int
polar_grid(int x, int y)
{
int c = grid_color;
int d;
// offset to center
x -= P_CENTER_X;
y -= P_CENTER_Y;
// outer circle
d = circle_inout(x, y, P_RADIUS);
if (d < 0) return 0;
if (d == 0) return c;
// vertical and horizontal axis
if (x == 0 || y == 0)
return c;
d = circle_inout(x, y, P_RADIUS / 5);
if (d == 0) return c;
if (d > 0) return 0;
d = circle_inout(x, y, P_RADIUS * 2 / 5);
if (d == 0) return c;
if (d > 0) return 0;
// cross sloping lines
if (x == y || x == -y)
return c;
d = circle_inout(x, y, P_RADIUS * 3 / 5);
if (d == 0) return c;
if (d > 0) return 0;
d = circle_inout(x, y, P_RADIUS * 4 / 5);
if (d == 0) return c;
return 0;
}
/*
* Constant Resistance circle: (u - r/(r+1))^2 + v^2 = 1/(r+1)^2
* Constant Reactance circle: (u - 1)^2 + (v-1/x)^2 = 1/x^2
*/
int
smith_grid(int x, int y)
{
int d = circle_inout(x-146, y-116, 116);
int c = grid_color;
int d;
// offset to center
x -= P_CENTER_X;
y -= P_CENTER_Y;
// outer circle
d = circle_inout(x, y, P_RADIUS);
if (d < 0)
return 0;
else if (d == 0)
if (d == 0)
return c;
x -= 146+116;
y -= 116;
// shift circle center to right origin
x -= P_RADIUS;
// Constant Reactance Circle: 2j : R/2 = 58
if (circle_inout(x, y+58, 58) == 0)
return c;
if (circle_inout(x, y-58, 58) == 0)
return c;
// Constant Resistance Circle: 3 : R/4 = 29
d = circle_inout(x+29, y, 29);
if (d > 0) return 0;
if (d == 0) return c;
// Constant Reactance Circle: 1j : R = 116
if (circle_inout(x, y+116, 116) == 0)
return c;
if (circle_inout(x, y-116, 116) == 0)
return c;
// Constant Resistance Circle: 1 : R/2 = 58
d = circle_inout(x+58, y, 58);
if (d > 0) return 0;
if (d == 0) return c;
// Constant Reactance Circle: 1/2j : R*2 = 232
if (circle_inout(x, y+232, 232) == 0)
return c;
if (circle_inout(x, y-232, 232) == 0)
return c;
// Constant Resistance Circle: 1/3 : R*3/4 = 87
if (circle_inout(x+87, y, 87) == 0)
return c;
return 0;
}
int
smith_grid2(int x, int y, float scale)
{
int c = grid_color;
int d;
// offset to center
x -= P_CENTER_X;
y -= P_CENTER_Y;
// outer circle
d = circle_inout(x, y, P_RADIUS);
if (d < 0)
return 0;
if (d == 0)
return c;
// shift circle center to right origin
x -= P_RADIUS * scale;
// Constant Reactance Circle: 2j : R/2 = 58
if (circle_inout(x, y+58*scale, 58*scale) == 0)
return c;
if (circle_inout(x, y-58*scale, 58*scale) == 0)
return c;
#if 0
// Constant Resistance Circle: 3 : R/4 = 29
d = circle_inout(x+29*scale, y, 29*scale);
if (d > 0) return 0;
if (d == 0) return c;
d = circle_inout(x-29*scale, y, 29*scale);
if (d > 0) return 0;
if (d == 0) return c;
#endif
// Constant Reactance Circle: 1j : R = 116
if (circle_inout(x, y+116*scale, 116*scale) == 0)
return c;
if (circle_inout(x, y-116*scale, 116*scale) == 0)
return c;
// Constant Resistance Circle: 1 : R/2 = 58
d = circle_inout(x+58*scale, y, 58*scale);
if (d > 0) return 0;
if (d == 0) return c;
d = circle_inout(x-58*scale, y, 58*scale);
if (d > 0) return 0;
if (d == 0) return c;
// Constant Reactance Circle: 1/2j : R*2 = 232
if (circle_inout(x, y+232*scale, 232*scale) == 0)
return c;
if (circle_inout(x, y-232*scale, 232*scale) == 0)
return c;
#if 0
// Constant Resistance Circle: 1/3 : R*3/4 = 87
d = circle_inout(x+87*scale, y, 87*scale);
if (d > 0) return 0;
if (d == 0) return c;
d = circle_inout(x+87*scale, y, 87*scale);
if (d > 0) return 0;
if (d == 0) return c;
#endif
// Constant Resistance Circle: 0 : R
d = circle_inout(x+P_RADIUS*scale, y, P_RADIUS*scale);
if (d > 0) return 0;
if (d == 0) return c;
d = circle_inout(x-P_RADIUS*scale, y, P_RADIUS*scale);
if (d > 0) return 0;
if (d == 0) return c;
// Constant Resistance Circle: -1/3 : R*3/2 = 174
d = circle_inout(x+174*scale, y, 174*scale);
if (d > 0) return 0;
if (d == 0) return c;
d = circle_inout(x-174*scale, y, 174*scale);
//if (d > 0) return 0;
if (d == 0) return c;
return 0;
}
#if 0
int
rectangular_grid(int x, int y)
@ -493,6 +639,12 @@ is_mapmarked(int x, int y)
return (markmap[0][y] & bit) || (markmap[1][y] & bit);
}
static inline void
markmap_upperarea(void)
{
markmap[current_mappage][0] |= 0xffff;
}
static void
swap_markmap(void)
{
@ -779,9 +931,9 @@ markmap_all_markers(void)
continue;
markmap_marker(i);
}
markmap_upperarea();
}
int area_width = WIDTH;
int area_height = HEIGHT;
@ -820,6 +972,8 @@ draw_cell(int m, int n)
for (x = 0; x < w; x++) {
//uint16_t c = rectangular_grid(x+x0, y+y0);
uint16_t c = smith_grid(x+x0, y+y0);
//uint16_t c = smith_grid2(x+x0, y+y0, 0.5);
//uint16_t c = polar_grid(x+x0, y+y0);
spi_buffer[y * w + x] |= c;
}
}

View file

@ -168,7 +168,7 @@ const uint8_t adc_filter_config[] = {
0x81, 0x1e, 0xf9, 0x00,
0 /* sentinel */
};
#elsif 0
#elif 0
/* bb, aa = signal.ellip(2, 0.1, 100, (4500.0/24000, 5500.0/24000), 'bandpass') */
const uint8_t adc_filter_config[] = {
/* len, page, reg, data.... */

101
ui.c
View file

@ -24,10 +24,11 @@
#include <stdlib.h>
struct {
enum { CHANNEL, FREQ, VOLUME, MOD, AGC, RFGAIN, DGAIN, MODE_MAX } mode;
int digit; /* 0~5 */
int digit; /* 0~5 */
int current_trace; /* 0..3 */
} uistat;
#define NO_EVENT 0
#define EVT_BUTTON_SINGLE_CLICK 0x01
#define EVT_BUTTON_DOUBLE_CLICK 0x02
@ -169,7 +170,8 @@ enum {
MT_BLANK,
MT_SUBMENU,
MT_CALLBACK,
MT_CANCEL
MT_CANCEL,
MT_CLOSE
};
typedef void (*menuaction_cb_t)(int item);
@ -178,7 +180,6 @@ typedef void (*menuaction_cb_t)(int item);
static void menu_move_back(void);
static void
menu_cal_cb(int item)
{
@ -214,7 +215,7 @@ menu_caldone_cb(int item)
static void
menu_recall_cb(int item)
{
if (item < 0 || item > 5)
if (item < 0 || item >= 5)
return;
if (caldata_recall(item) == 0) {
ui_status = FALSE;
@ -224,6 +225,51 @@ menu_recall_cb(int item)
}
}
static void
menu_trace_cb(int item)
{
if (item < 0 || item >= 4)
return;
uistat.current_trace = item;
}
static void
menu_format_cb(int item)
{
trace[uistat.current_trace].type = item;
}
static void
elect_active_marker(void)
{
int i;
for (i = 0; i < 4; i++)
if (markers[i].enabled) {
active_marker = i;
return;
}
active_marker = -1;
}
static void
menu_marker_cb(int item)
{
if (item < 0 || item >= 4)
return;
if (active_marker == item) {
markers[active_marker].enabled = FALSE;
elect_active_marker();
} else {
active_marker = item;
markers[active_marker].enabled = TRUE;
}
if (active_marker >= 0)
redraw_marker(active_marker, TRUE);
ui_status = FALSE;
ui_hide();
}
typedef struct {
uint8_t type;
char *label;
@ -241,6 +287,43 @@ const menuitem_t menu_cal[] = {
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_trace[] = {
{ MT_CALLBACK, "0", menu_trace_cb },
{ MT_CALLBACK, "1", menu_trace_cb },
{ MT_CALLBACK, "2", menu_trace_cb },
{ MT_CALLBACK, "3", menu_trace_cb },
{ MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_format[] = {
{ MT_CALLBACK, "LOGMAG", menu_format_cb },
{ MT_CALLBACK, "PHASE", menu_format_cb },
{ MT_CALLBACK, "SMITH", menu_format_cb },
{ MT_CALLBACK, "ADMIT", menu_format_cb },
{ MT_CALLBACK, "DELAY", menu_format_cb },
{ MT_CALLBACK, "SWR", menu_format_cb },
{ MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_display[] = {
{ MT_SUBMENU, "TRACE", menu_trace },
{ MT_SUBMENU, "FORMAT", menu_format },
{ MT_SUBMENU, "SCALE", menu_format },
{ MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_marker[] = {
{ MT_CALLBACK, "1", menu_marker_cb },
{ MT_CALLBACK, "2", menu_marker_cb },
{ MT_CALLBACK, "3", menu_marker_cb },
{ MT_CALLBACK, "4", menu_marker_cb },
{ MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_recall[] = {
{ MT_CALLBACK, "0", menu_recall_cb },
{ MT_CALLBACK, "1", menu_recall_cb },
@ -253,8 +336,10 @@ const menuitem_t menu_recall[] = {
const menuitem_t menu_top[] = {
{ MT_SUBMENU, "CAL", menu_cal },
{ MT_SUBMENU, "DISPLAY", menu_display },
{ MT_SUBMENU, "MARKER", menu_marker },
{ MT_SUBMENU, "RECALL", menu_recall },
{ MT_CANCEL, "BACK", NULL },
{ MT_CLOSE, "CLOSE", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
@ -288,6 +373,7 @@ void menu_invoke(int selection)
switch (menu->type) {
case MT_NONE:
case MT_BLANK:
case MT_CLOSE:
ui_status = FALSE;
ui_hide();
break;
@ -422,7 +508,8 @@ ui_process(void)
}
status = btn_wait_release();
} while (status != 0);
redraw_marker(active_marker, TRUE);
if (active_marker >= 0)
redraw_marker(active_marker, TRUE);
}
}
}