From 5498d637513f2b34159acee85f031b0bce71fdf5 Mon Sep 17 00:00:00 2001 From: TT Date: Thu, 3 Nov 2016 21:56:56 +0900 Subject: [PATCH] make controlable marker with lever switch, test menu display --- dsp.c | 1 + halconf.h | 2 +- main.c | 27 ++++++----------- nanovna.h | 15 +++++++++ plot.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 106 insertions(+), 30 deletions(-) diff --git a/dsp.c b/dsp.c index 1b32ca2..9f287c7 100644 --- a/dsp.c +++ b/dsp.c @@ -134,6 +134,7 @@ void calclate_gamma(float *gamma) acc_ref += (float)rr*rr + (float)ri*ri; } rn = sqrtf(acc_ref / len) * 2e3 * len; + //rn = acc_ref; gamma[0] = -acc_r / rn; gamma[1] = -acc_i / rn; } diff --git a/halconf.h b/halconf.h index 2f19627..6643ad5 100644 --- a/halconf.h +++ b/halconf.h @@ -62,7 +62,7 @@ * @brief Enables the EXT subsystem. */ #if !defined(HAL_USE_EXT) || defined(__DOXYGEN__) -#define HAL_USE_EXT FALSE +#define HAL_USE_EXT TRUE #endif /** diff --git a/main.c b/main.c index 7c7a00b..a52c4d0 100644 --- a/main.c +++ b/main.c @@ -45,8 +45,7 @@ void scan_lcd(void); static MUTEX_DECL(mutex); - -static THD_WORKING_AREA(waThread1, 384); +static THD_WORKING_AREA(waThread1, 400); static THD_FUNCTION(Thread1, arg) { (void)arg; @@ -67,7 +66,7 @@ static THD_FUNCTION(Thread1, arg) chMtxLock(&mutex); scan_lcd(); chMtxUnlock(&mutex); - ui_process(); + //ui_process(); #endif } } @@ -401,6 +400,7 @@ void scan_lcd(void) ; palClearPad(GPIOC, GPIOC_LED); __disable_irq(); + /* calculate reflection coeficient */ calclate_gamma(measured[0][i]); __enable_irq(); @@ -409,29 +409,20 @@ void scan_lcd(void) while (wait_count) ; __disable_irq(); + /* calculate transmission coeficient */ calclate_gamma(measured[1][i]); __enable_irq(); delay = set_frequency(frequencies[(i+1)%sweep_points]); -#if 0 - sweep_plot(frequencies[i], first, measured[0][i], measured[1][i]); - first = FALSE; -#endif palSetPad(GPIOC, GPIOC_LED); + ui_process(); } -#if 0 - for (i = 0; i < sweep_points; i++) { - sweep_plot(frequencies[i], first, measured[0][i], measured[1][i]); - first = FALSE; - } -#endif -#if 0 - sweep_tail(); - polar_plot(measured); -#endif + if (cal_status & CALSTAT_APPLY) apply_error_term(); + plot_into_index(measured); + draw_cell_all(); } @@ -1096,6 +1087,8 @@ int main(void) i2sStart(&I2SD2, &i2sconfig); i2sStartExchange(&I2SD2); + ui_init(); + /* * Shell manager initialization. */ diff --git a/nanovna.h b/nanovna.h index ac6b0f2..a0c4c0f 100644 --- a/nanovna.h +++ b/nanovna.h @@ -70,10 +70,21 @@ void ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg); /* * plot.c */ + +#define OFFSETX 15 +#define OFFSETY 0 +#define WIDTH 291 +#define HEIGHT 233 + +extern int area_width; +extern int area_height; + void plot_init(void); void set_sweep(int32_t start, int stop); void redraw(void); +void force_draw_cells(void); +void redraw_marker(int marker); #define TRACES_MAX 4 @@ -174,3 +185,7 @@ extern config_t current_config; #define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0) + +void ui_init(void); +void ui_show(void); +void ui_hide(void); diff --git a/plot.c b/plot.c index 9d56ab7..8626614 100644 --- a/plot.c +++ b/plot.c @@ -11,11 +11,7 @@ void cell_draw_marker_info(int m, int n, int w, int h); void draw_frequencies(void); static inline void force_set_markmap(void); void frequency_string(char *buf, size_t len, uint32_t freq); - -#define OFFSETX 15 -#define OFFSETY 0 -#define WIDTH 291 -#define HEIGHT 233 +void markmap_all_markers(void); //#define GRID_COLOR 0x0863 uint16_t grid_color = 0x1084; @@ -500,9 +496,9 @@ void plot_into_index(float measured[2][101][2]) #endif mark_cells_from_index(); + markmap_all_markers(); } - void cell_drawline(int w, int h, int x0, int y0, int x1, int y1, int c) { @@ -665,6 +661,50 @@ cell_draw_markers(int m, int n, int w, int h) } } +void +markmap_marker(int marker) +{ + int t; + if (!markers[marker].enabled) + return; + for (t = 0; t < TRACES_MAX; t++) { + if (!trace[t].enabled) + continue; + uint32_t index = trace_index[t][markers[marker].index]; + int x = CELL_X(index); + int y = CELL_Y(index); + int m = x>>5; + int n = y>>5; + mark_map(m, n); + if ((x&31) < 6) + mark_map(m-1, n); + if ((x&31) > 32-6) + mark_map(m+1, n); + if ((y&31) < 12) { + mark_map(m, n-1); + if ((x&31) < 6) + mark_map(m-1, n-1); + if ((x&31) > 32-6) + mark_map(m+1, n-1); + } + } +} + +void +markmap_all_markers(void) +{ + int i; + for (i = 0; i < 4; i++) { + if (!markers[i].enabled) + continue; + markmap_marker(i); + } +} + + +int area_width = WIDTH; +int area_height = HEIGHT; + void draw_cell(int m, int n) { @@ -676,10 +716,10 @@ draw_cell(int m, int n) int i0, i1; int i; int t; - if (x0 + w > WIDTH) - w = WIDTH - x0; - if (y0 + h > HEIGHT) - h = HEIGHT - y0; + if (x0 + w > area_width) + w = area_width - x0; + if (y0 + h > area_height) + h = area_height - y0; PULSE; /* draw grid */ @@ -777,14 +817,41 @@ void draw_cell_all(void) { int m, n; - for (m = 0; m < (WIDTH+CELLWIDTH-1) / CELLWIDTH; m++) - for (n = 0; n < (HEIGHT+CELLHEIGHT-1) / CELLHEIGHT; n++) + for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++) + for (n = 0; n < (area_height+CELLHEIGHT-1) / CELLHEIGHT; n++) { if (is_mapmarked(m, n)) draw_cell(m, n); + //ui_process(); + } + + // keep current map for update swap_markmap(); + // clear map for next plotting clear_markmap(); } +void +redraw_marker(int marker) +{ + // mark map on new position of marker + markmap_marker(marker); + + // mark cells on marker info + markmap[current_mappage][0] = 0xffff; + + draw_cell_all(); +} + +void +force_draw_cells(void) +{ + int n, m; + for (m = 7; m <= 9; m++) + for (n = 0; n < (area_height+CELLHEIGHT-1) / CELLHEIGHT; n++) + draw_cell(m, n); +} + + void cell_drawchar_5x7(int w, int h, uint8_t ch, int x, int y, uint16_t fg) {