From 0c0d62e131006f8917d0fca85149c16b1632ce9f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 17 Dec 2020 13:27:50 +0100 Subject: [PATCH] THD info overlap bug solved --- plot.c | 34 +++++++++++++++------------------- si4432.c | 18 +++++++----------- ui_sa.c | 11 ++++------- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/plot.c b/plot.c index da169a1..fe07e07 100644 --- a/plot.c +++ b/plot.c @@ -2133,33 +2133,29 @@ static void cell_draw_marker_info(int x0, int y0) break; plot_printf(buf, sizeof buf, "DEVIATION:%6.1qHz", dev); goto show_computed; - } - } - if (i >= 2 && setting.measurement == M_THD) { - if (i == 2 && (markers[0].index << 5) > sweep_points ) { + } else if (setting.measurement == M_THD && markers[0].enabled && (markers[0].index << 5) > sweep_points ) { int old_unit = setting.unit; setting.unit = U_WATT; float p = index_to_value(markers[0].index); - int j = 2; + int h_i = 2; uint32_t f = markers[0].frequency; float h = 0.0; - while (f * j < frequencies[sweep_points-1]) { - if (search_maximum(1, f*j, 4*j) ) // use marker 1 for searching harmonics + while (f * h_i < frequencies[sweep_points-1]) { + if (search_maximum(1, f*h_i, 4*h_i) ) // use marker 1 for searching harmonics h += index_to_value(markers[1].index); - j++; + h_i++; } float thd = 100.0 * sqrt(h/p); setting.unit = old_unit; - + ili9341_set_foreground(marker_color(markers[0].mtype)); plot_printf(buf, sizeof buf, "THD: %4.1f%%", thd); - j = 1; +// j = 1; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(16) - y0; cell_drawstring_7x13(buf, xpos, ypos); // cell_drawstring(buf, xpos, ypos); break; } - break; } else if (i >= 2 && setting.measurement == M_OIP3 && markers[2].enabled && markers[3].enabled) { float il = index_to_value(markers[2].index); @@ -2202,14 +2198,6 @@ static void cell_draw_marker_info(int x0, int y0) for (t = TRACE_ACTUAL; t <= TRACE_ACTUAL; t++) { // Only show info on actual trace if (!trace[t].enabled) continue; -#if 1 - int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; -// int ypos = 1 + (j/2)*(13) - y0; - int ypos = 1 + (j/2)*(16) - y0; -#else - int xpos = 1 + CELLOFFSETX - x0; - int ypos = 1 + j*(FONT_GET_HEIGHT*2+1) - y0; -#endif int k = 0; if (i == active_marker) { // ili9341_set_foreground(LCD_BG_COLOR); @@ -2248,6 +2236,14 @@ static void cell_draw_marker_info(int x0, int y0) trace_get_value_string( t, &buf[k], (sizeof buf) - k, idx, measured[trace[t].channel], ridx, markers[i].mtype,markers[i].frequency, markers[ref_marker].frequency); +#if 1 + int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; +// int ypos = 1 + (j/2)*(13) - y0; + int ypos = 1 + (j/2)*(16) - y0; +#else + int xpos = 1 + CELLOFFSETX - x0; + int ypos = 1 + j*(FONT_GET_HEIGHT*2+1) - y0; +#endif if (/* strlen(buf)*7> WIDTH/2 && */active > 1) cell_drawstring(buf, xpos, ypos); else diff --git a/si4432.c b/si4432.c index 7735cf5..e9ce892 100644 --- a/si4432.c +++ b/si4432.c @@ -454,7 +454,6 @@ void SI4432_trigger_fill(int s, uint8_t trigger_lvl, int up_direction, int trigg register uint16_t t_mode; uint16_t data_level = T_LEVEL_UNDEF; - if (up_direction) t_mode = T_UP_MASK; else @@ -469,6 +468,9 @@ void SI4432_trigger_fill(int s, uint8_t trigger_lvl, int up_direction, int trigg rssi = shiftIn(); palSetPad(GPIOC, sel); age[i] = rssi; + i++; + if (i >= sweep_points) + i = 0; switch (waiting) { case ST_ARMING: if (i == sweep_points-1) { @@ -491,15 +493,12 @@ void SI4432_trigger_fill(int s, uint8_t trigger_lvl, int up_direction, int trigg waiting = ST_FILLING; switch (trigger_mode) { case T_PRE: // Trigger at the begin of the scan - buf_index = i - 1; - if (buf_index < 0) - buf_index += sweep_points; + buf_index = i; + goto fill_rest; break; case T_POST: // Trigger at the end of the scan buf_index = i; - if (buf_index >= sweep_points) - buf_index -= sweep_points; - goto store; + goto done; break; case T_MID: // Trigger in the middle of the scan buf_index = i + sweep_points/2; @@ -510,13 +509,10 @@ void SI4432_trigger_fill(int s, uint8_t trigger_lvl, int up_direction, int trigg } break; case ST_FILLING: -store: if (i == buf_index) goto done; } - i++; - if (i >= sweep_points) - i = 0; +fill_rest: if (t) my_microsecond_delay(t); }while(1); diff --git a/ui_sa.c b/ui_sa.c index c2c6e0d..e4d9167 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1143,17 +1143,14 @@ static UI_FUNCTION_ADV_CALLBACK(menu_trigger_acb) setting.trigger_mode += 1; if (setting.trigger_mode > T_MID) setting.trigger_mode = T_PRE; - data = setting.trigger_mode; - goto done; - } else - if (data != T_DONE) { - done: + set_trigger(setting.trigger_mode); + } else if (data != T_DONE) { set_trigger(data); // menu_move_back(); ui_mode_normal(); - draw_menu(); - completed = true; } + draw_menu(); + completed = true; } #if 0