diff --git a/nanovna.h b/nanovna.h index 31ba7f8..cf34dc6 100644 --- a/nanovna.h +++ b/nanovna.h @@ -514,6 +514,7 @@ 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); diff --git a/sa_core.c b/sa_core.c index 573d3f8..81e2c84 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2277,9 +2277,9 @@ marker_search_left_max(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from - 1; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { value = new_value; found = i; @@ -2288,7 +2288,7 @@ marker_search_left_max(int from) } for (; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { value = new_value; found = i; @@ -2306,9 +2306,9 @@ marker_search_right_max(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from + 1; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { // follow down value = new_value; found = i; @@ -2316,7 +2316,7 @@ marker_search_right_max(int from) break; // past the minimum } for (; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { // follow up value = new_value; found = i; @@ -2326,6 +2326,22 @@ marker_search_right_max(int from) return found; } +int marker_search_max(void) +{ + int i = 0; + int found = 0; + + float value = actual_t[i]; + for (; i < sweep_points; i++) { + int new_value = actual_t[i]; + if (new_value > value) { // follow up + value = new_value; + found = i; + } + } + return found; +} + #define MINMAX_DELTA 10 @@ -2337,9 +2353,9 @@ marker_search_left_min(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from - 1; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { value = new_value; // follow up // found = i; @@ -2348,7 +2364,7 @@ marker_search_left_min(int from) } for (; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { value = new_value; // follow down found = i; @@ -2366,9 +2382,9 @@ marker_search_right_min(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from + 1; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { // follow up value = new_value; // found = i; @@ -2376,7 +2392,7 @@ marker_search_right_min(int from) break; // past the maximum } for (; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { // follow down value = new_value; found = i; diff --git a/ui.c b/ui.c index 99a0639..ca42e1a 100644 --- a/ui.c +++ b/ui.c @@ -809,8 +809,8 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) int i = -1; if (active_marker == -1) return; - if (data < 4) - markers[active_marker].mtype &= ~M_TRACKING; +// if (data < 4) +// markers[active_marker].mtype &= ~M_TRACKING; switch (data) { case 0: /* search Left */ i = marker_search_left_min(markers[active_marker].index); @@ -831,12 +831,14 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) case 3: /* search right */ i = marker_search_right_max(markers[active_marker].index); break; - case 4: /* tracking */ - markers[active_marker].mtype ^= M_TRACKING; + case 4: /* peak search */ + i = marker_search_max(); break; } - if (i != -1) + if (i != -1) { markers[active_marker].index = i; + markers[active_marker].frequency = frequencies[i]; + } draw_menu(); redraw_marker(active_marker); select_lever_mode(LM_SEARCH); @@ -2091,8 +2093,10 @@ lever_search_marker(int status) i = marker_search_left(markers[active_marker].index); else if (status & EVT_UP) i = marker_search_right(markers[active_marker].index); - if (i != -1) + if (i != -1) { markers[active_marker].index = i; + markers[active_marker].frequency = frequencies[i]; + } redraw_marker(active_marker); } } diff --git a/ui_sa.c b/ui_sa.c index d44b13d..e7f1a79 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1406,7 +1406,7 @@ static const menuitem_t menu_reflevel[] = { }; const menuitem_t menu_marker_search[] = { - //{ MT_CALLBACK, "OFF", menu_marker_search_cb }, + { MT_CALLBACK, 4, "PEAK\n SEARCH", menu_marker_search_cb }, { MT_CALLBACK, 0, "MIN\n" S_LARROW" LEFT", menu_marker_search_cb }, { MT_CALLBACK, 1, "MIN\n" S_RARROW" RIGHT", menu_marker_search_cb }, { MT_CALLBACK, 2, "MAX\n" S_LARROW" LEFT", menu_marker_search_cb },