diff --git a/dsp.c b/dsp.c index 9f287c7..a4862d4 100644 --- a/dsp.c +++ b/dsp.c @@ -133,8 +133,8 @@ void calclate_gamma(float *gamma) acc_i += (float)(s0 * ri); acc_ref += (float)rr*rr + (float)ri*ri; } - rn = sqrtf(acc_ref / len) * 2e3 * len; - //rn = acc_ref; + //rn = sqrtf(acc_ref / len) * 2e3 * len; + rn = acc_ref / 10; gamma[0] = -acc_r / rn; gamma[1] = -acc_i / rn; } diff --git a/flash.c b/flash.c index 0120250..10d034a 100644 --- a/flash.c +++ b/flash.c @@ -64,6 +64,8 @@ const uint32_t saveareas[] = #define FLASH_PAGESIZE 0x800 +int16_t lastsaveid = 0; + int caldata_save(int id) @@ -98,6 +100,8 @@ caldata_save(int id) /* after saving data, make active configuration points to flash */ active = (config_t*)saveareas[id]; + lastsaveid = id; + return 0; } @@ -118,6 +122,7 @@ caldata_recall(int id) /* active configuration points to save data on flash memory */ active = src; + lastsaveid = id; /* duplicated saved data onto sram to be able to modify marker/trace */ memcpy(dst, src, sizeof(config_t)); diff --git a/main.c b/main.c index f3b0363..2b6202c 100644 --- a/main.c +++ b/main.c @@ -368,7 +368,7 @@ ensure_edit_config(void) if (active == ¤t_config) return; - memcpy(¤t_config, active, sizeof(config_t)); + //memcpy(¤t_config, active, sizeof(config_t)); active = ¤t_config; } @@ -742,15 +742,19 @@ static void cmd_cal(BaseSequentialStream *chp, int argc, char *argv[]) } cal_status |= CALSTAT_APPLY; + draw_cal_status(); return; } else if (strcmp(cmd, "on") == 0) { cal_status |= CALSTAT_APPLY; + draw_cal_status(); return; } else if (strcmp(cmd, "off") == 0) { cal_status &= ~CALSTAT_APPLY; + draw_cal_status(); return; } else if (strcmp(cmd, "reset") == 0) { cal_status = 0; + draw_cal_status(); return; } else if (strcmp(cmd, "data") == 0) { chprintf(chp, "%f %f\r\n", cal_data[CAL_LOAD][0][0], cal_data[CAL_LOAD][0][1]); @@ -776,6 +780,7 @@ static void cmd_save(BaseSequentialStream *chp, int argc, char *argv[]) if (id < 0 || id >= SAVEAREA_MAX) goto usage; caldata_save(id); + draw_cal_status(); return; usage: @@ -796,13 +801,14 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[]) if (caldata_recall(id) == 0) { // success set_sweep(freq_start, freq_stop); + draw_cal_status(); } resume_sweep(); return; usage: - chprintf(chp, "save {id}\r\n"); + chprintf(chp, "recall {id}\r\n"); } diff --git a/nanovna.h b/nanovna.h index e72af06..f3fc1bc 100644 --- a/nanovna.h +++ b/nanovna.h @@ -136,6 +136,8 @@ void trace_get_info(int t, char *buf, int len); void plot_into_index(float measured[2][101][2]); void draw_cell_all(void); +void draw_cal_status(void); + /* * main.c @@ -191,13 +193,14 @@ typedef struct { #define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */ +extern int16_t lastsaveid; extern config_t *active; extern config_t current_config; #define freq_start active->_freq_start #define freq_stop active->_freq_stop #define sweep_points active->_sweep_points -#define cal_status active->_cal_status +#define cal_status current_config._cal_status #define frequencies active->_frequencies #define cal_data active->_cal_data diff --git a/plot.c b/plot.c index 831bba4..c8944f2 100644 --- a/plot.c +++ b/plot.c @@ -993,23 +993,64 @@ void draw_frequencies(void) { char buf[24]; - chsnprintf(buf, 24, "START%3d.%03d %03d MHz", + chsnprintf(buf, 24, "START %d.%03d %03d MHz ", (int)(fstart / 1000000), (int)((fstart / 1000) % 1000), (int)(fstart % 1000)); ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); - chsnprintf(buf, 24, "STOP %3d.%03d %03d MHz", + chsnprintf(buf, 24, "STOP %d.%03d %03d MHz", (int)(fstop / 1000000), (int)((fstop / 1000) % 1000), (int)(fstop % 1000)); ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); } +void +draw_cal_status(void) +{ + int x = 0; + int y = 100; +#define YSTEP 7 + ili9341_fill(0, y, 10, 6*YSTEP, 0x0000); + if (cal_status & CALSTAT_APPLY) { + char c[3] = "C0"; + if (active == ¤t_config) + c[1] = '*'; + else + c[1] += lastsaveid; + + ili9341_drawstring_5x7(c, x, y, 0xffff, 0x0000); + y += YSTEP; + if (cal_status & CALSTAT_ED) { + ili9341_drawstring_5x7("D", x, y, 0xffff, 0x0000); + y += YSTEP; + } + if (cal_status & CALSTAT_ER) { + ili9341_drawstring_5x7("R", x, y, 0xffff, 0x0000); + y += YSTEP; + } + if (cal_status & CALSTAT_ES) { + ili9341_drawstring_5x7("S", x, y, 0xffff, 0x0000); + y += YSTEP; + } + if (cal_status & CALSTAT_ET) { + ili9341_drawstring_5x7("T", x, y, 0xffff, 0x0000); + y += YSTEP; + } + if (cal_status & CALSTAT_EX) { + ili9341_drawstring_5x7("X", x, y, 0xffff, 0x0000); + y += YSTEP; + } + } +} + + void redraw(void) { ili9341_fill(0, 0, 320, 240, 0); draw_frequencies(); + draw_cal_status(); } void