diff --git a/main.c b/main.c index 1f321d8..2529b5f 100644 --- a/main.c +++ b/main.c @@ -124,6 +124,7 @@ const char *info_about[]={ bool dirty = true; bool completed = false; +uint8_t enable_after_complete = 0; #ifdef TINYSA4 static THD_WORKING_AREA(waThread1, 1124); @@ -192,7 +193,12 @@ static THD_FUNCTION(Thread1, arg) ui_process(); // Process collected data, calculate trace coordinates and plot only if scan // completed - if ((redraw_request & (CLEAR_ACTUAL | CLEAR_STORED | CLEAR_TEMP) ) || completed) { + if (completed) { + // Enable traces at sweep complete for redraw + if (enable_after_complete){ + TRACE_ENABLE(enable_after_complete); + enable_after_complete = 0; + } // START_PROFILE; // Prepare draw graphics, cache all lines, mark screen cells for redraw plot_into_index(measured); @@ -219,6 +225,12 @@ static THD_FUNCTION(Thread1, arg) #pragma GCC push_options #pragma GCC optimize ("Os") +void enableTracesAtComplete(uint8_t mask){ + // Disable this traces + TRACE_DISABLE(mask); + enable_after_complete|=mask; + redraw_request|=REDRAW_AREA; +} int is_paused(void) @@ -1050,12 +1062,7 @@ config_t config = { //properties_t current_props; //properties_t *active_props = ¤t_props; -// NanoVNA Default settings -static const trace_t def_trace[TRACES_MAX] = {//enable, type, channel, reserved, scale, refpos - [TRACE_TEMP] = { 0}, //Temp - [TRACE_STORED] = { 0}, //Stored - [TRACE_ACTUAL] = { 1} //Actual -}; + static const marker_t def_markers[MARKERS_MAX] = { { M_ENABLED, M_REFERENCE | M_TRACKING, 30, 0 }, @@ -1085,7 +1092,7 @@ void load_LCD_properties(void) setting.trace_scale = 10.0; setting.trace_refpos = 0; setting.waterfall = W_OFF; - memcpy(setting._trace, def_trace, sizeof(def_trace)); + setting._traces = TRACE_ACTUAL_FLAG; memcpy(setting._markers, def_markers, sizeof(def_markers)); #ifdef __LIMITS__ memset(setting.limits, 0, sizeof(setting.limits)); @@ -1879,7 +1886,7 @@ VNA_SHELL_FUNCTION(cmd_trace) int t; if (argc == 0) { for (t = 0; t < TRACES_MAX; t++) { - if (trace[t].enabled) { + if (IS_TRACE_ENABLE(t)) { const char *type = unit_string[setting.unit]; // get_trace_typename(t); const char *channel = trc_channel_name[t]; float scale = get_trace_scale(); diff --git a/nanovna.h b/nanovna.h index 6888111..cb667d5 100644 --- a/nanovna.h +++ b/nanovna.h @@ -641,10 +641,6 @@ float value(float); float index_to_value(const int i); float marker_to_value(const int i); -typedef struct trace { - uint8_t enabled; -} trace_t; - #define FREQ_MODE_START_STOP 0x0 #define FREQ_MODE_CENTER_SPAN 0x1 #define FREQ_MODE_DOTTED_GRID 0x2 @@ -738,6 +734,22 @@ enum { M_DISABLED = false, M_ENABLED = true }; + +// Flags/macros for enable/disable traces +#define TRACE_ACTUAL_FLAG (1<<(TRACE_ACTUAL)) +#define TRACE_STORED_FLAG (1<<(TRACE_STORED)) +#define TRACE_TEMP_FLAG (1<<(TRACE_TEMP)) + +#define TRACE_ENABLE(t_mask) {setting._traces|= (t_mask);} +#define TRACE_DISABLE(t_mask) {setting._traces&=~(t_mask);} + +#define IS_TRACES_ENABLED(t_mask) (setting._traces&(t_mask)) +#define IS_TRACE_ENABLE(t) (setting._traces&(1<<(t))) +#define IS_TRACE_DISABLE(t) !(setting._traces&(1<<(t))) + +// Enable trace for show only after sweep complete (disable it at call) +void enableTracesAtComplete(uint8_t mask); + typedef struct { uint8_t enabled; uint8_t mtype; @@ -797,9 +809,6 @@ int marker_search_right_min(int from); #define REDRAW_BATTERY (1<<4) #define REDRAW_AREA (1<<5) #define REDRAW_TRIGGER (1<<6) -#define CLEAR_ACTUAL (1<<7) -#define CLEAR_STORED (1<<8) -#define CLEAR_TEMP (1<<9) extern uint16_t redraw_request; /* @@ -995,6 +1004,7 @@ typedef struct setting uint8_t test; // current test number uint8_t harmonic; // used harmonic number 1...5 uint8_t fast_speedup; // 0 - 20 + uint8_t _traces; // enabled traces flags uint16_t linearity_step; // range equal POINTS_COUNT uint16_t _sweep_points; @@ -1039,7 +1049,6 @@ typedef struct setting #define FREQUENCY_SHIFT 100000000 // 100MHz upconversion maximum float trace_scale; float trace_refpos; - trace_t _trace[TRACES_MAX]; marker_t _markers[MARKERS_MAX]; #ifdef __LIMITS__ limit_t limits[LIMITS_MAX]; @@ -1191,7 +1200,6 @@ extern int16_t lastsaveid; #define cal_data active_props->_cal_data #define electrical_delay current_props._electrical_delay #endif -#define trace setting._trace #define markers setting._markers #define active_marker setting._active_marker #ifdef __VNA__ diff --git a/plot.c b/plot.c index d3ccbe2..a3626b6 100644 --- a/plot.c +++ b/plot.c @@ -487,10 +487,8 @@ mark_cells_from_index(void) map_t *map = &markmap[current_mappage][0]; index_x_t *index_x = trace_index_x; for (t = 0; t < TRACES_MAX; t++) { - if (!trace[t].enabled) + if (IS_TRACE_DISABLE(t)) continue; - if ((CLEAR_ACTUAL << t ) & redraw_request ) - continue; // dirty, do not draw index_y_t *index_y = trace_index_y[t]; int m0 = index_x[0] / CELLWIDTH; int n0 = index_y[0] / CELLHEIGHT; @@ -772,7 +770,7 @@ markmap_marker(int marker) { if (!markers[marker].enabled) return; - if (!trace[TRACE_ACTUAL].enabled) + if (IS_TRACE_DISABLE(TRACE_ACTUAL)) return; int idx = markers[marker].index; int x = trace_index_x[idx] - X_MARKER_OFFSET; @@ -823,11 +821,8 @@ plot_into_index(measurement_t measured) // START_PROFILE trace_into_index_x_array(trace_index_x, sweep_points); for (t = 0; t < TRACES_MAX; t++) { - if (!trace[t].enabled) + if (IS_TRACE_DISABLE(t)) continue; - if ((CLEAR_ACTUAL << t ) & redraw_request ) { - continue; // dirty, do not draw - } trace_into_index_y_array(trace_index_y[t], measured[t], sweep_points); } // STOP_PROFILE @@ -885,11 +880,10 @@ draw_cell(int m, int n) c = GET_PALTETTE_COLOR(LCD_GRID_COLOR); // Generate grid type list uint32_t trace_type = 0; - for (t = 0; t < TRACES_MAX; t++) { - if (trace[t].enabled) { - trace_type |= RECTANGULAR_GRID_MASK; - } - } + + if (IS_TRACES_ENABLED(TRACE_ACTUAL_FLAG|TRACE_STORED_FLAG|TRACE_TEMP_FLAG)) + trace_type |= RECTANGULAR_GRID_MASK; + // Draw rectangular plot (40 system ticks for all screen calls) if (trace_type & RECTANGULAR_GRID_MASK) { for (x = 0; x < w; x++) { @@ -948,10 +942,8 @@ draw_cell(int m, int n) index_x_t *index_x = trace_index_x; search_index_range_x(x0, x0 + w, &i0, &i1); for (t = 0; t < TRACES_MAX; t++) { - if (!trace[t].enabled) + if (IS_TRACE_DISABLE(t)) continue; - if ((CLEAR_ACTUAL << t ) & redraw_request ) - continue; // dirty, do not draw c = GET_PALTETTE_COLOR(LCD_TRACE_1_COLOR + t); index_y_t *index_y = trace_index_y[t]; @@ -972,7 +964,7 @@ draw_cell(int m, int n) // draw marker symbols on each trace (<10 system ticks for all screen calls) #if 1 for (int t = TRACE_ACTUAL; t <= TRACE_STORED; t++ ) { - if (trace[t].enabled) { + if (IS_TRACE_ENABLE(t)) { for (i = 0; i < MARKERS_MAX; i++) { if (!markers[i].enabled) continue; @@ -1560,7 +1552,7 @@ static void cell_draw_marker_info(int x0, int y0) if (!markers[i].enabled) continue; for (t = TRACE_ACTUAL; t <= TRACE_STORED; t++) { // Only show info on actual trace - if (!trace[t].enabled) + if (IS_TRACE_DISABLE(t)) continue; if (markers[i].mtype & M_STORED) { if (t == TRACE_ACTUAL) diff --git a/sa_core.c b/sa_core.c index 4eafa23..d4e3504 100644 --- a/sa_core.c +++ b/sa_core.c @@ -250,8 +250,7 @@ void reset_settings(int m) setting.fast_speedup = 0; setting.trigger_level = -150.0; setting.linearity_step = 0; - trace[TRACE_STORED].enabled = false; - trace[TRACE_TEMP].enabled = false; + TRACE_DISABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); // setting.refer = -1; // do not reset reffer when switching modes setting.mute = true; #ifdef __SPUR__ @@ -453,7 +452,7 @@ void set_measurement(int m) setting.measurement = m; #ifdef __LINEARITY__ if (m == M_LINEARITY) { - trace[TRACE_STORED].enabled = true; + TRACE_ENABLE(TRACE_STORED_FLAG); for (int j = 0; j < setting._sweep_points; j++) stored_t[j] = -150; setting.linearity_step = 0; @@ -519,12 +518,10 @@ void toggle_debug_avoid(void) debug_avoid = !debug_avoid; if (debug_avoid) { setting.show_stored = true; - trace[TRACE_STORED].enabled = true; - trace[TRACE_TEMP].enabled = true; + TRACE_ENABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); } else { setting.show_stored = false; - trace[TRACE_STORED].enabled = false; - trace[TRACE_TEMP].enabled = false; + TRACE_DISABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); } dirty = true; } @@ -867,10 +864,10 @@ void limits_update(void) while (j < sweep_points) stored_t[j++] = old_level; setting.show_stored = true; - trace[TRACE_STORED].enabled = true; + TRACE_ENABLE(TRACE_STORED_FLAG); } else { setting.show_stored = false; - trace[TRACE_STORED].enabled = false; + TRACE_DISABLE(TRACE_STORED_FLAG); } } #endif @@ -880,7 +877,7 @@ void set_storage(void) for (int i=0; i