From c6fc9a5d80e213fa4d264676fdc2f88c9c61b240 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Tue, 2 Mar 2021 22:20:19 +0300 Subject: [PATCH] Add define for MARKER_INVALID and TRACE_INVALID Remove obsolete marker search functions --- main.c | 8 ++--- nanovna.h | 8 ++--- plot.c | 96 ------------------------------------------------------- sa_core.c | 8 ++--- ui.c | 21 ++++-------- ui_sa.c | 4 +-- 6 files changed, 21 insertions(+), 124 deletions(-) diff --git a/main.c b/main.c index 3cb0565..95fe5b6 100644 --- a/main.c +++ b/main.c @@ -194,8 +194,8 @@ static THD_FUNCTION(Thread1, arg) redraw_request |= REDRAW_CELLS | REDRAW_BATTERY; if (uistat.marker_tracking) { - int i = marker_search(); - if (i != -1 && active_marker != -1) { + int i = marker_search_max(); + if (i != -1 && active_marker != MARKER_INVALID) { markers[active_marker].index = i; markers[active_marker].frequency = frequencies[i]; @@ -2025,7 +2025,7 @@ VNA_SHELL_FUNCTION(cmd_marker) } redraw_request |= REDRAW_MARKER; if (strcmp(argv[0], "off") == 0) { - active_marker = -1; + active_marker = MARKER_INVALID; for (t = 0; t < MARKERS_MAX; t++) markers[t].enabled = FALSE; return; @@ -2044,7 +2044,7 @@ VNA_SHELL_FUNCTION(cmd_marker) static const char cmd_marker_list[] = "on|off|peak"; switch (get_str_index(argv[1], cmd_marker_list)) { case 0: markers[t].enabled = TRUE; active_marker = t; return; - case 1: markers[t].enabled =FALSE; if (active_marker == t) active_marker = -1; return; + case 1: markers[t].enabled =FALSE; if (active_marker == t) active_marker = MARKER_INVALID; return; case 2: markers[t].enabled = TRUE; active_marker = t; int i = marker_search_max(); if (i == -1) i = 0; diff --git a/nanovna.h b/nanovna.h index 9753285..f95714a 100644 --- a/nanovna.h +++ b/nanovna.h @@ -107,6 +107,8 @@ #define TRACE_ACTUAL 2 #define TRACE_STORED 1 #define TRACE_TEMP 0 +#define TRACE_INVALID -1 + // #define age_t measured[TRACE_AGE] #define stored_t measured[TRACE_STORED] #define actual_t measured[TRACE_ACTUAL] @@ -672,6 +674,7 @@ typedef struct { } marker_t; #define MARKERS_MAX 4 +#define MARKER_INVALID -1 extern int8_t previous_marker; extern int8_t marker_tracking; @@ -696,11 +699,8 @@ void draw_cal_status(void); void marker_position(int m, int t, int *x, int *y); int search_nearest_index(int x, int y, int t); -void set_marker_search(int mode); -int marker_search(void); + int marker_search_max(void); -int marker_search_left(int from); -int marker_search_right(int from); int marker_search_left_max(int from); int marker_search_right_max(int from); int marker_search_left_min(int from); diff --git a/plot.c b/plot.c index 7fa3d03..fb772f8 100644 --- a/plot.c +++ b/plot.c @@ -1377,102 +1377,6 @@ marker_position(int m, int t, int *x, int *y) *y = CELL_Y(index); } -static int greater(int x, int y, int d) { return x - d > y; } -static int lesser(int x, int y, int d) { return x - d < y; } - -static int (*compare)(int x, int y, int d) = greater; - -int -marker_search(void) -{ - int i; - int found = 0; - - if (uistat.current_trace == -1) - return -1; - - int value = CELL_Y(trace_index[TRACE_ACTUAL][0]); - for (i = 0; i < sweep_points; i++) { - int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); - if ((*compare)(value, new_value, 0)) { - value = new_value; - found = i; - } - } - - return found; -} - -void -set_marker_search(int mode) -{ - compare = (mode == 0) ? greater : lesser; -} - -int -search_is_greater(void) -{ - return(compare == greater); -} - -#define MINMAX_DELTA 10 - -int -marker_search_left(int from) -{ - int i; - int found = -1; - if (uistat.current_trace == -1) - return -1; - - int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); - for (i = from - 1; i >= 0; i--) { - int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); - if ((*compare)(value, new_value, MINMAX_DELTA)) - break; - } - - for (; i >= 0; i--) { - int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); - if ((*compare)(new_value, value, -MINMAX_DELTA)) { - break; - } - if ((*compare)(value, new_value, 0)) { - found = i; - value = new_value; - } - } - return found; -} - -int -marker_search_right(int from) -{ - int i; - int found = -1; - - if (uistat.current_trace == -1) - return -1; - int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); - for (i = from + 1; i < sweep_points; i++) { - int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); - if ((*compare)(value, new_value, MINMAX_DELTA)) - break; - value = new_value; - } - for (; i < sweep_points; i++) { - int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); - if ((*compare)(new_value, value, -MINMAX_DELTA)) { - break; - } - if ((*compare)(value, new_value, 0)) { - found = i; - value = new_value; - } - } - return found; -} - int search_nearest_index(int x, int y, int t) { diff --git a/sa_core.c b/sa_core.c index 55e9e03..548d044 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3550,7 +3550,7 @@ marker_search_left_max(int from) { int i; int found = -1; - if (uistat.current_trace == -1) + if (uistat.current_trace == TRACE_INVALID) return -1; float value = actual_t[from]; @@ -3580,7 +3580,7 @@ marker_search_right_max(int from) int i; int found = -1; - if (uistat.current_trace == -1) + if (uistat.current_trace == TRACE_INVALID) return -1; float value = actual_t[from]; for (i = from + 1; i < sweep_points; i++) { @@ -3626,7 +3626,7 @@ marker_search_left_min(int from) { int i; int found = from; - if (uistat.current_trace == -1) + if (uistat.current_trace == TRACE_INVALID) return -1; int value_x10 = actual_t[from]*10; @@ -3656,7 +3656,7 @@ marker_search_right_min(int from) int i; int found = from; - if (uistat.current_trace == -1) + if (uistat.current_trace == TRACE_INVALID) return -1; int value_x10 = actual_t[from]*10; for (i = from + 1; i < sweep_points; i++) { diff --git a/ui.c b/ui.c index cbc78e5..4077eaa 100644 --- a/ui.c +++ b/ui.c @@ -858,7 +858,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb) break; case 3: /* MARKERS->SPAN */ { - if (previous_marker == -1 || active_marker == previous_marker) { + if (previous_marker == MARKER_INVALID || active_marker == previous_marker) { // if only 1 marker is active, keep center freq and make span the marker comes to the edge freq_t center = get_sweep_frequency(ST_CENTER); freq_t span = center > freq ? center - freq : freq - center; @@ -905,7 +905,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) { (void)item; int i = -1; - if (active_marker == -1) + if (active_marker == MARKER_INVALID) return; markers[active_marker].mtype &= ~M_TRACKING; switch (data) { @@ -915,13 +915,6 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) case 1: /* search right */ i = marker_search_right_min(markers[active_marker].index); break; -#if 0 - case 0: /* maximum */ - case 1: /* minimum */ - set_marker_search(data); - i = marker_search(); - break; -#endif case 2: /* search Left */ i = marker_search_left_max(markers[active_marker].index); break; @@ -950,7 +943,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) static UI_FUNCTION_ADV_CALLBACK(menu_marker_tracking_acb){ (void)item; (void)data; - if (active_marker == -1) return; + if (active_marker == MARKER_INVALID) return; if(b){ b->icon = markers[active_marker].mtype & M_TRACKING ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK; return; @@ -975,8 +968,8 @@ active_marker_select(int item) // used only to select an active marker from the { if (item == -1) { active_marker = previous_marker; - previous_marker = -1; - if (active_marker == -1) { + previous_marker = MARKER_INVALID; + if (active_marker == MARKER_INVALID) { choose_active_marker(); } } else { @@ -2391,7 +2384,7 @@ lever_move_marker(int status) } status = btn_wait_release(); } while (status != 0); - if (active_marker >= 0) + if (active_marker != MARKER_INVALID) redraw_marker(active_marker); } @@ -2399,7 +2392,7 @@ static void lever_search_marker(int status) { int i = -1; - if (active_marker >= 0) { + if (active_marker != MARKER_INVALID) { if (status & EVT_DOWN) i = marker_search_left_max(markers[active_marker].index); else if (status & EVT_UP) diff --git a/ui_sa.c b/ui_sa.c index da9dc02..a0fd4e1 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1154,7 +1154,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_marker_select_acb) static UI_FUNCTION_ADV_CALLBACK(menu_marker_modify_acb) { (void)item; - if (active_marker == -1) return; + if (active_marker == MARKER_INVALID) return; if(b){ if (markers[active_marker].enabled == M_ENABLED) { b->icon = BUTTON_ICON_NOCHECK; @@ -1303,7 +1303,7 @@ static void choose_active_marker(void) active_marker = i; return; } - active_marker = -1; + active_marker = MARKER_INVALID; } #ifdef __HARMONIC__