From c259ca4727993c455802d7dafb350ec794aa056e Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 12 Apr 2020 18:36:58 +0200 Subject: [PATCH] Marker search repaired --- plot.c | 40 +++++++++++++++++++++++----------------- ui_sa.c | 7 ++++++- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/plot.c b/plot.c index 0f6e086..e02e6cd 100644 --- a/plot.c +++ b/plot.c @@ -1144,7 +1144,7 @@ marker_position(int m, int t, int *x, int *y) static int greater(int x, int y) { return x > y; } static int lesser(int x, int y) { return x < y; } -static int (*compare)(int x, int y) = lesser; +static int (*compare)(int x, int y) = greater; int marker_search(void) @@ -1157,9 +1157,9 @@ marker_search(void) int value = CELL_Y(trace_index[TRACE_ACTUAL][0]); for (i = 0; i < sweep_points; i++) { - index_t index = trace_index[TRACE_ACTUAL][i]; - if ((*compare)(value, CELL_Y(index))) { - value = CELL_Y(index); + int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); + if ((*compare)(value, new_value)) { + value = new_value; found = i; } } @@ -1173,30 +1173,36 @@ set_marker_search(int mode) compare = (mode == 0) ? greater : lesser; } +int +search_is_greater(void) +{ + return(compare == greater); +} + int marker_search_left(int from) { int i; int found = -1; -#define MINMAX_DELTA -10 +#define MINMAX_DELTA -5 if (uistat.current_trace == -1) return -1; int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); for (i = from - 1; i >= 0; i--) { - index_t index = trace_index[TRACE_ACTUAL][i]; - if ((*compare)(value - MINMAX_DELTA, CELL_Y(index))) + int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); + if ((*compare)(value + MINMAX_DELTA, new_value)) break; - value = CELL_Y(index); + value = new_value; } for (; i >= 0; i--) { - index_t index = trace_index[TRACE_ACTUAL][i]; - if ((*compare)(CELL_Y(index), value + MINMAX_DELTA)) { + int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); + if ((*compare)(new_value, value - MINMAX_DELTA)) { break; } found = i; - value = CELL_Y(index); + value = new_value; } return found; } @@ -1211,19 +1217,19 @@ marker_search_right(int from) return -1; int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); for (i = from + 1; i < sweep_points; i++) { - index_t index = trace_index[TRACE_ACTUAL][i]; - if ((*compare)(value, CELL_Y(index))) + int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); + if ((*compare)(value+MINMAX_DELTA, new_value)) break; - value = CELL_Y(index); + value = new_value; } for (; i < sweep_points; i++) { - index_t index = trace_index[TRACE_ACTUAL][i]; - if ((*compare)(CELL_Y(index), value)) { + int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); + if ((*compare)(new_value, value-MINMAX_DELTA)) { break; } found = i; - value = CELL_Y(index); + value = new_value; } return found; } diff --git a/ui_sa.c b/ui_sa.c index 705e227..396d3be 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -752,6 +752,7 @@ static void menu_marker_type_cb(int item, uint8_t data) markers[i].mtype &= ~M_REFERENCE; } markers[active_marker].mtype |= M_REFERENCE; + markers[active_marker].mtype &= ~M_DELTA; } else { if (data == M_DELTA && (markers[active_marker].mtype & M_REFERENCE)) markers[active_marker].mtype &= ~M_REFERENCE; @@ -1357,9 +1358,13 @@ static void menu_item_modify_attribute( } else if (menu == menu_marker_type && active_marker >= 0 && markers[active_marker].enabled == M_ENABLED) { if (data & markers[active_marker].mtype) mark = true; - else if (data==markers[active_marker].mtype) // This catches the M_NORMAL case + else if (item < 5 && data==markers[active_marker].mtype) // This catches the M_NORMAL case mark = true; } else if (menu == menu_marker_search) { + if (item == 0 && search_is_greater()) + mark = true; + if (item == 1 && !search_is_greater()) + mark = true; if (item == 4 && markers[active_marker].mtype & M_TRACKING) mark = true; } else if (menu == menu_marker_sel) {