mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
split config and properties
This commit is contained in:
parent
bd2890e6af
commit
9f5259556c
24
flash.c
24
flash.c
|
|
@ -89,23 +89,23 @@ int16_t lastsaveid = 0;
|
|||
int
|
||||
caldata_save(int id)
|
||||
{
|
||||
uint16_t *src = (uint16_t*)¤t_config;
|
||||
uint16_t *src = (uint16_t*)¤t_props;
|
||||
uint16_t *dst;
|
||||
int count = sizeof(config_t) / sizeof(uint16_t);
|
||||
int count = sizeof(properties_t) / sizeof(uint16_t);
|
||||
|
||||
if (id < 0 || id >= SAVEAREA_MAX)
|
||||
return -1;
|
||||
dst = (uint16_t*)saveareas[id];
|
||||
|
||||
current_config.magic = CONFIG_MAGIC;
|
||||
current_config.checksum = 0;
|
||||
current_config.checksum = checksum(¤t_config, sizeof current_config);
|
||||
current_props.magic = CONFIG_MAGIC;
|
||||
current_props.checksum = 0;
|
||||
current_props.checksum = checksum(¤t_props, sizeof current_props);
|
||||
|
||||
flash_unlock();
|
||||
|
||||
/* erase flash pages */
|
||||
void *p = dst;
|
||||
void *tail = p + sizeof(config_t);
|
||||
void *tail = p + sizeof(properties_t);
|
||||
while (p < tail) {
|
||||
flash_erase_page((uint32_t)p);
|
||||
p += FLASH_PAGESIZE;
|
||||
|
|
@ -118,7 +118,7 @@ caldata_save(int id)
|
|||
}
|
||||
|
||||
/* after saving data, make active configuration points to flash */
|
||||
active = (config_t*)saveareas[id];
|
||||
active = (properties_t*)saveareas[id];
|
||||
lastsaveid = id;
|
||||
|
||||
return 0;
|
||||
|
|
@ -127,18 +127,18 @@ caldata_save(int id)
|
|||
int
|
||||
caldata_recall(int id)
|
||||
{
|
||||
config_t *src;
|
||||
void *dst = ¤t_config;
|
||||
properties_t *src;
|
||||
void *dst = ¤t_props;
|
||||
|
||||
if (id < 0 || id >= SAVEAREA_MAX)
|
||||
return -1;
|
||||
|
||||
// point to saved area on the flash memory
|
||||
src = (config_t*)saveareas[id];
|
||||
src = (properties_t*)saveareas[id];
|
||||
|
||||
if (src->magic != CONFIG_MAGIC)
|
||||
return -1;
|
||||
if (checksum(src, sizeof(config_t)) != 0)
|
||||
if (checksum(src, sizeof(properties_t)) != 0)
|
||||
return -1;
|
||||
|
||||
/* active configuration points to save data on flash memory */
|
||||
|
|
@ -146,7 +146,7 @@ caldata_recall(int id)
|
|||
lastsaveid = id;
|
||||
|
||||
/* duplicated saved data onto sram to be able to modify marker/trace */
|
||||
memcpy(dst, src, sizeof(config_t));
|
||||
memcpy(dst, src, sizeof(properties_t));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
28
main.c
28
main.c
|
|
@ -309,7 +309,15 @@ uint16_t cal_status;
|
|||
float cal_data[5][101][2];
|
||||
#endif
|
||||
|
||||
config_t current_config = {
|
||||
config_t config = {
|
||||
/* magic */ CONFIG_MAGIC,
|
||||
/* dac_value */ 1922,
|
||||
/* grid_color */ 0x1084,
|
||||
/* trace_colors */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
|
||||
/* checksum */ 0
|
||||
};
|
||||
|
||||
properties_t current_props = {
|
||||
/* magic */ CONFIG_MAGIC,
|
||||
/* frequency0 */ 1000000,
|
||||
/* frequency1 */ 300000000,
|
||||
|
|
@ -318,10 +326,10 @@ config_t current_config = {
|
|||
/* frequencies */ {},
|
||||
/* cal_data */ {},
|
||||
/* trace[4] */ {
|
||||
{ 1, TRC_LOGMAG, 0, 1.0, RGB565(0,255,255), 0 },
|
||||
{ 1, TRC_LOGMAG, 1, 1.0, RGB565(255,0,40), 0 },
|
||||
{ 1, TRC_SMITH, 0, 1.0, RGB565(0,0,255), 1 },
|
||||
{ 1, TRC_PHASE, 1, 1.0, RGB565(50,255,0), 1 }
|
||||
{ 1, TRC_LOGMAG, 0, 0, 1.0 },
|
||||
{ 1, TRC_LOGMAG, 1, 0, 1.0 },
|
||||
{ 1, TRC_SMITH, 0, 1, 1.0 },
|
||||
{ 1, TRC_PHASE, 1, 1, 1.0 }
|
||||
},
|
||||
/* markers[4] */ {
|
||||
{ 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 }
|
||||
|
|
@ -329,16 +337,16 @@ config_t current_config = {
|
|||
/* active_marker */ 0,
|
||||
/* checksum */ 0
|
||||
};
|
||||
config_t *active = ¤t_config;
|
||||
properties_t *active = ¤t_props;
|
||||
|
||||
void
|
||||
ensure_edit_config(void)
|
||||
{
|
||||
if (active == ¤t_config)
|
||||
if (active == ¤t_props)
|
||||
return;
|
||||
|
||||
//memcpy(¤t_config, active, sizeof(config_t));
|
||||
active = ¤t_config;
|
||||
//memcpy(¤t_props, active, sizeof(config_t));
|
||||
active = ¤t_props;
|
||||
// move to uncal state
|
||||
cal_status = 0;
|
||||
}
|
||||
|
|
@ -622,7 +630,7 @@ adjust_ed(void)
|
|||
for (i = 0; i < 101; i++) {
|
||||
// z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0
|
||||
// s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0)
|
||||
// prepare 1/s11ao for effeiciency
|
||||
// prepare 1/s11ao to avoid dividing complex
|
||||
float c = 1000e-15;
|
||||
float z0 = 50;
|
||||
//float z = 6.2832 * frequencies[i] * c * z0;
|
||||
|
|
|
|||
41
nanovna.h
41
nanovna.h
|
|
@ -157,15 +157,24 @@ extern const char *trc_type_name[];
|
|||
// Phase
|
||||
|
||||
typedef struct {
|
||||
int enabled;
|
||||
int type;
|
||||
int channel;
|
||||
uint8_t enabled;
|
||||
uint8_t type;
|
||||
uint8_t channel;
|
||||
uint8_t polar;
|
||||
float scale;
|
||||
//float ref;
|
||||
uint16_t color;
|
||||
uint8_t polar;
|
||||
} trace_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t magic;
|
||||
uint16_t dac_value;
|
||||
uint16_t grid_color;
|
||||
uint16_t trace_color[TRACES_MAX];
|
||||
int32_t checksum;
|
||||
} config_t;
|
||||
|
||||
extern config_t config;
|
||||
|
||||
//extern trace_t trace[TRACES_MAX];
|
||||
|
||||
void set_trace_type(int t, int type);
|
||||
|
|
@ -244,24 +253,24 @@ typedef struct {
|
|||
int _active_marker;
|
||||
|
||||
int32_t checksum;
|
||||
} config_t;
|
||||
} properties_t;
|
||||
|
||||
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
|
||||
|
||||
extern int16_t lastsaveid;
|
||||
extern config_t *active;
|
||||
extern config_t current_config;
|
||||
extern properties_t *active;
|
||||
extern properties_t current_props;
|
||||
|
||||
#define frequency0 current_config._frequency0
|
||||
#define frequency1 current_config._frequency1
|
||||
#define sweep_points current_config._sweep_points
|
||||
#define cal_status current_config._cal_status
|
||||
#define frequencies current_config._frequencies
|
||||
#define frequency0 current_props._frequency0
|
||||
#define frequency1 current_props._frequency1
|
||||
#define sweep_points current_props._sweep_points
|
||||
#define cal_status current_props._cal_status
|
||||
#define frequencies current_props._frequencies
|
||||
#define cal_data active->_cal_data
|
||||
|
||||
#define trace current_config._trace
|
||||
#define markers current_config._markers
|
||||
#define active_marker current_config._active_marker
|
||||
#define trace current_props._trace
|
||||
#define markers current_props._markers
|
||||
#define active_marker current_props._active_marker
|
||||
|
||||
int caldata_save(int id);
|
||||
int caldata_recall(int id);
|
||||
|
|
|
|||
28
plot.c
28
plot.c
|
|
@ -13,7 +13,7 @@ void frequency_string(char *buf, size_t len, uint32_t freq);
|
|||
void markmap_all_markers(void);
|
||||
|
||||
//#define GRID_COLOR 0x0863
|
||||
uint16_t grid_color = 0x1084;
|
||||
//uint16_t grid_color = 0x1084;
|
||||
|
||||
/* indicate dirty cells */
|
||||
uint16_t markmap[2][8];
|
||||
|
|
@ -111,7 +111,7 @@ circle_inout(int x, int y, int r)
|
|||
int
|
||||
polar_grid(int x, int y)
|
||||
{
|
||||
int c = grid_color;
|
||||
int c = config.grid_color;
|
||||
int d;
|
||||
|
||||
// offset to center
|
||||
|
|
@ -155,7 +155,7 @@ polar_grid(int x, int y)
|
|||
int
|
||||
smith_grid(int x, int y)
|
||||
{
|
||||
int c = grid_color;
|
||||
int c = config.grid_color;
|
||||
int d;
|
||||
|
||||
// offset to center
|
||||
|
|
@ -213,7 +213,7 @@ smith_grid(int x, int y)
|
|||
int
|
||||
smith_grid2(int x, int y, float scale)
|
||||
{
|
||||
int c = grid_color;
|
||||
int c = config.grid_color;
|
||||
int d;
|
||||
|
||||
// offset to center
|
||||
|
|
@ -310,7 +310,7 @@ const int cirs[][4] = {
|
|||
int
|
||||
smith_grid3(int x, int y)
|
||||
{
|
||||
int c = grid_color;
|
||||
int c = config.grid_color;
|
||||
int d;
|
||||
|
||||
// offset to center
|
||||
|
|
@ -347,7 +347,7 @@ smith_grid3(int x, int y)
|
|||
int
|
||||
rectangular_grid(int x, int y)
|
||||
{
|
||||
int c = grid_color;
|
||||
int c = config.grid_color;
|
||||
//#define FREQ(x) (((x) * (fspan / 1000) / (WIDTH-1)) * 1000 + fstart)
|
||||
//int32_t n = FREQ(x-1) / fgrid;
|
||||
//int32_t m = FREQ(x) / fgrid;
|
||||
|
|
@ -367,7 +367,7 @@ rectangular_grid(int x, int y)
|
|||
int
|
||||
rectangular_grid_x(int x)
|
||||
{
|
||||
int c = grid_color;
|
||||
int c = config.grid_color;
|
||||
if (x == 0 || x == (WIDTH-1))
|
||||
return c;
|
||||
if ((((x + grid_offset) * 10) % grid_width) < 10)
|
||||
|
|
@ -378,7 +378,7 @@ rectangular_grid_x(int x)
|
|||
int
|
||||
rectangular_grid_y(int y)
|
||||
{
|
||||
int c = grid_color;
|
||||
int c = config.grid_color;
|
||||
if ((y % GRIDY) == 0)
|
||||
return c;
|
||||
return 0;
|
||||
|
|
@ -901,7 +901,7 @@ cell_draw_markers(int m, int n, int w, int h)
|
|||
int x = CELL_X(index) - x0;
|
||||
int y = CELL_Y(index) - y0;
|
||||
if (x > -6 && x < w+6 && y >= 0 && y < h+12)
|
||||
draw_marker(w, h, x, y, trace[t].color, '1' + i);
|
||||
draw_marker(w, h, x, y, config.trace_color[t], '1' + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1029,7 +1029,7 @@ draw_cell(int m, int n)
|
|||
int x2 = CELL_X(trace_index[t][i+1]);
|
||||
int y1 = CELL_Y(trace_index[t][i]);
|
||||
int y2 = CELL_Y(trace_index[t][i+1]);
|
||||
int c = trace[t].color;
|
||||
int c = config.trace_color[t];
|
||||
cell_drawline(w, h, x1 - x0, y1 - y0, x2 - x0, y2 - y0, c);
|
||||
}
|
||||
}
|
||||
|
|
@ -1038,7 +1038,7 @@ draw_cell(int m, int n)
|
|||
#if 1
|
||||
/* draw polar plot */
|
||||
for (t = 0; t < TRACES_MAX; t++) {
|
||||
int c = trace[t].color;
|
||||
int c = config.trace_color[t];
|
||||
if (!trace[t].enabled || !trace[t].polar)
|
||||
continue;
|
||||
for (i = 1; i < 101; i++) {
|
||||
|
|
@ -1155,10 +1155,10 @@ cell_draw_marker_info(int m, int n, int w, int h)
|
|||
xpos -= m * CELLWIDTH;
|
||||
ypos -= n * CELLHEIGHT;
|
||||
trace_get_info(t, buf, sizeof buf);
|
||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color);
|
||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]);
|
||||
xpos += 84;
|
||||
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel][idx], frequencies[idx]);
|
||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color);
|
||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]);
|
||||
j++;
|
||||
}
|
||||
|
||||
|
|
@ -1233,7 +1233,7 @@ draw_cal_status(void)
|
|||
ili9341_fill(0, y, 10, 6*YSTEP, 0x0000);
|
||||
if (cal_status & CALSTAT_APPLY) {
|
||||
char c[3] = "C0";
|
||||
if (active == ¤t_config)
|
||||
if (active == ¤t_props)
|
||||
c[1] = '*';
|
||||
else
|
||||
c[1] += lastsaveid;
|
||||
|
|
|
|||
Loading…
Reference in a new issue