Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,7 @@ static void shell_init_connection(void) {
* Set I/O stream (SDU1 or SD1) for shell
*/
PREPARE_STREAM;
shell_reset_console();
}

#else
Expand Down
9 changes: 8 additions & 1 deletion nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ extern uint16_t graph_bottom;

// Marker start drag distance (can be bigger for various display resolution)
#define MARKER_PICKUP_DISTANCE 20
// Trigger line start drag distance (can be bigger for various display resolution)
#define DRAG_TRIGGER_DISTANCE 10

// Smith/polar chart
//#define P_CENTER_X (CELLOFFSETX + WIDTH/2)
Expand Down Expand Up @@ -969,6 +971,7 @@ void redraw_frame(void);
void request_to_draw_cells_behind_menu(void);
void request_to_draw_cells_behind_numeric_input(void);
void redraw_marker(int marker);
void redraw_trigger(int band);
void markmap_all_markers(void);
void plot_into_index(measurement_t measured);
void draw_frequencies(void);
Expand All @@ -980,6 +983,10 @@ void draw_cal_status(void);

int distance_to_index(int8_t t, uint16_t idx, int16_t x, int16_t y);
int search_nearest_index(int x, int y, int t);
int search_nearest_trigger(int x, int y);

float pos_to_trigger_value(int y);
bool is_multiband_trigger(void);

int marker_search_max(int m);
int marker_search_left_max(int m);
Expand Down Expand Up @@ -1606,7 +1613,7 @@ extern volatile uint8_t abort_enabled;

// lever_mode
enum lever_mode {
LM_MARKER, LM_SEARCH, LM_CENTER, LM_SPAN, LM_EDELAY
LM_MARKER, LM_SEARCH, LM_CENTER, LM_SPAN, LM_TRIGGER
};

// marker smith value format
Expand Down
198 changes: 136 additions & 62 deletions plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ to_dBm(const float v)
return logf(v/(sqrtf(50.0)))*(20.0/logf(10.0)) + 30.0;
case U_VPP:
// return log10f(v/(sqrtf(50.0)))* 20.0 + 30.0;
return logf((v/2.828)/(sqrtf(50.0)))*(20.0/logf(10.0)) + 30.0;
return logf(v/(2.828*sqrtf(50.0)))*(20.0/logf(10.0)) + 30.0;
case U_WATT:
// return log10f(v*1000.0)* 10.0;
return logf(v*1000.0)*(10.0/logf(10.0));
Expand Down Expand Up @@ -503,13 +503,19 @@ trace_into_index_y_array(index_y_t *y, float *array, int points)
if (mult) value = fast_expf(value*mult);
value = ref - value * scale;
int v = value;
if (v < 0) v = 0;
else if (v > max) v = max;
if (v < 0) v = 0;
else if (v >= max) v = max-1;
y[i] = v;
}
return;
}

static index_y_t trace_into_index_y(float level) {
index_y_t tp;
trace_into_index_y_array(&tp, &level, 1);
return tp;
}

static inline void
swap_markmap(void)
{
Expand Down Expand Up @@ -583,43 +589,50 @@ markmap_upperarea(void)
#endif
}

static uint16_t get_trigger_level(
#ifdef __BANDS__
int x
#else
void
#endif
){
index_y_t trigger;
#ifdef TINYSA4
if (setting.trigger_trace != 255)
setting.trigger_level = measured[setting.trigger_trace][x];
#endif
#ifdef __BANDS__
else if (!setting.draw_line && setting.multi_band && !setting.multi_trace) {
int b = getBand(x);
setting.trigger_level = setting.bands[b].level;
}
// Triggers draw in multiband mode
bool is_multiband_trigger(void) {
if (setting.multi_band && !setting.multi_trace
#ifdef __DRAW_LINE__
&& !setting.draw_line
#endif
) return true;
return false;
}

// Mark band trigger area for redraw
static void markmap_band_trigger(int band) {
band_t *b = &setting.bands[band];
if (!b->enabled) return;
int tp = trace_into_index_y(b->level);
int x1 = trace_index_x[b->start_index == 0 ? b->start_index : b->start_index - 1];
int x2 = trace_index_x[b->stop_index];
invalidate_rect(x1, tp, x2, tp);
}
#endif
trace_into_index_y_array(&trigger, &setting.trigger_level, 1);
return trigger;

// Mark trigger area or line for redraw
static void markmap_trigger(void) {
int tp = trace_into_index_y(setting.trigger_level);
markmap[current_mappage][tp/CELLWIDTH] = (map_t)0xFFFFFFFF;
}

static inline void
markmap_trigger_area(void){
// Mark all trigger lines area for redraw
static void markmap_trigger_area(void) {
#ifdef __BANDS__
uint16_t tp = get_trigger_level(0);
#else
uint16_t tp = get_trigger_level();
if (is_multiband_trigger()) {
for (int band = 0; band < BANDS_MAX; band++)
markmap_band_trigger(band);
} else
#endif
markmap[current_mappage][tp/CELLWIDTH] = (map_t)0xFFFFFFFF;
markmap_trigger();
}

//
// in most cases _compute_outcode clip calculation not give render line speedup
//
static inline void
cell_drawline(int x0, int y0, int x1, int y1, int c)
cell_drawline(int x0, int y0, int x1, int y1, pixel_t c)
{
if (x0 < 0 && x1 < 0) return;
if (y0 < 0 && y1 < 0) return;
Expand Down Expand Up @@ -654,6 +667,24 @@ cell_drawline(int x0, int y0, int x1, int y1, int c)
}
}

static void
cell_draw_hline(int x0, int x1, int y, pixel_t c) {
if ((uint32_t)y >= CELLHEIGHT) return;
// if (x1 < x0) SWAP(x0, x1);
if (x0 < 0) x0 = 0;
if (x1 > CELLWIDTH) x1 = CELLWIDTH;
for (;x0 < x1; x0++) cell_buffer[y * CELLWIDTH + x0] = c;
}

static void
cell_draw_vline(int y0, int y1, int x, pixel_t c) {
if ((uint32_t)x >= CELLWIDTH) return;
// if (y1 < y0) SWAP(y0, y1);
if (y0 < 0) y0 = 0;
if (y1 > CELLHEIGHT) y1 = CELLHEIGHT;
for (;y0 < y1; y0++) cell_buffer[y0 * CELLWIDTH + x] = c;
}

// Give a little speedup then draw rectangular plot (50 systick on all calls, all render req 700 systick)
// Write more difficult algoritm for seach indexes not give speedup
static int
Expand Down Expand Up @@ -1150,50 +1181,42 @@ draw_cell(int m, int n)
#ifdef __CHANNEL_POWER__
if (setting.measurement == M_CP||setting.measurement == M_SNR) {
c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR);
for (x = 0; x < w; x++)
if (x+x0 == WIDTH/3 || x+x0 == 2*WIDTH/3 ) {
for (y = 0; y < h; y++) cell_buffer[y * CELLWIDTH + x] = c;
}
}
#endif
#ifdef __BANDS__
if (setting.multi_band && !setting.multi_trace) {
c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR);
for (x = 0; x < w; x++) {
int idx1 = ((x+x0) * sweep_points) / WIDTH;
int idx2 = ((x+x0+1) * sweep_points) / WIDTH;
if (getBand(idx1) != getBand(idx2) && idx2 < WIDTH-2) {
for (y = 0; y < h; y++) cell_buffer[y * CELLWIDTH + x] = c;
}
}
cell_draw_vline(0, h, 1*WIDTH/3 - x0, c);
cell_draw_vline(0, h, 2*WIDTH/3 - x0, c);
}
#endif
// PULSE;
#endif
// Draw trigger line
if ((setting.trigger != T_AUTO

// Draw trigger and band splitter lines
bool draw_trigger = (setting.trigger != T_AUTO
#ifdef __TRIGGER_TRACE__
&& setting.trigger_trace == 255
#endif
)
);
c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR);
#ifdef __BANDS__
if (setting.multi_band && !setting.multi_trace) {
for (int band = 0; band < BANDS_MAX; band++) {
band_t *b = &setting.bands[band];
if (!b->enabled) continue;
// Get start and stop band display position
int x1 = trace_index_x[b->start_index == 0 ? 0 : b->start_index - 1] - x0;
int x2 = trace_index_x[b->stop_index ] - x0;
cell_draw_vline(0, h, x2, c); // Draw vertical band splitter
if (draw_trigger) // Draw trigger line
cell_draw_hline(x1, x2, trace_into_index_y(b->level) - y0, c);
}
draw_trigger = false; // triggers draw in multi-band mode
}
#endif
// Draw line or single trigger line
if (draw_trigger
#ifdef __DRAW_LINE__
|| setting.draw_line
#endif
) {
c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR);
#ifndef __BANDS__
int tp = get_trigger_level() - y0;
if (tp>=0 && tp < h)
#endif
for (x = 0; x < w; x++) {
#ifdef __BANDS__
int tp = get_trigger_level(x + x0 - CELLOFFSETX) - y0;
if (tp>=0 && tp < h)
#endif
if ((uint32_t)(x + x0 - CELLOFFSETX) <= WIDTH + CELLOFFSETX)
cell_buffer[tp * CELLWIDTH + x] = c;
}
}
) cell_draw_hline(0, w, trace_into_index_y(setting.trigger_level) - y0, c);

#if 1
// Only right cells
if (m >= (GRID_X_TEXT)/CELLWIDTH)
Expand Down Expand Up @@ -1369,6 +1392,57 @@ draw_all(bool flush)
redraw_request = 0;
}

//
// Call this function then need fast draw trigger line
// Used in ui.c for leveler move trigger (not added yet), drag trigger and etc.
void redraw_trigger(int band) {
(void)band;
#ifdef __BANDS__
if (is_multiband_trigger())
markmap_band_trigger(band);
else
#endif
markmap_trigger();
draw_all_cells(TRUE);
redraw_request|= REDRAW_CAL_STATUS | REDRAW_AREA; // Force redraw cal after
}

// Convert y display position to value in dBm
float pos_to_trigger_value(int y) {
if (y < 0) y = 0;
if (y > area_height) y = area_height;
return to_dBm(get_trace_refpos() - get_trace_scale() * (float)(y * NGRIDY) / area_height);
}

// Search nearest trigger line on screen
int search_nearest_trigger(int x, int y) {
if ((setting.trigger == T_AUTO // Not in auto mode
#ifdef __TRIGGER_TRACE__
|| setting.trigger_trace != 255 // Not in Trigger trace mode
#endif
)
#ifdef __DRAW_LINE__
&& !setting.draw_line // Allow in draw line mode
#endif
) return -1;
#ifdef __BANDS__
if (is_multiband_trigger()) {
for (int band = 0; band < BANDS_MAX; band++) {
band_t *b = &setting.bands[band];
if (!b->enabled) continue;
int x1 = trace_index_x[b->start_index];
int x2 = trace_index_x[b->stop_index ];
if (x < x1 || x > x2) continue;
int tl = trace_into_index_y(b->level) + DRAG_TRIGGER_DISTANCE - y;
if ((uint32_t)tl < 2 * DRAG_TRIGGER_DISTANCE) return band;
}
return -1;
}
#endif
int tl = trace_into_index_y(setting.trigger_level) + DRAG_TRIGGER_DISTANCE - y;
if ((uint32_t)tl < 2 * DRAG_TRIGGER_DISTANCE) return 0;
return -1;
}

//
// Call this function then need fast draw marker and marker info
Expand Down
3 changes: 1 addition & 2 deletions sa_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ void set_trigger_level(float trigger_level)
#ifdef __TRIGGER_TRACE__
setting.trigger_trace = 255;
#endif
redraw_request |= REDRAW_TRIGGER | REDRAW_CAL_STATUS | REDRAW_AREA;
redraw_request |= REDRAW_TRIGGER | REDRAW_CAL_STATUS;
//dirty = true; // No HW update required, only status panel refresh
}

Expand All @@ -2066,7 +2066,6 @@ void set_trigger(int trigger)
setting.trigger_direction = trigger;
} else if (trigger == T_DONE) {
pause_sweep(); // Trigger once so pause after this sweep has completed!!!!!!!
redraw_request |= REDRAW_CAL_STATUS; // Show status change setting.trigger = trigger;
setting.trigger = trigger;
} else {
sweep_mode = SWEEP_ENABLE;
Expand Down
Loading