Skip to content

Commit

Permalink
feat: add marker tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
edy555 committed Jan 18, 2020
1 parent 2d8be20 commit 18a1ca4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
8 changes: 8 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ static THD_FUNCTION(Thread1, arg)
if (completed) {
plot_into_index(measured);
redraw_request |= REDRAW_CELLS;

if (marker_tracking) {
int i = marker_search();
if (i != -1 && active_marker != -1) {
markers[active_marker].index = i;
redraw_request |= REDRAW_MARKER;
}
}
}
}

Expand Down
12 changes: 4 additions & 8 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ typedef struct {
uint32_t frequency;
} marker_t;

//extern marker_t markers[4];
//extern int active_marker;
extern int8_t previous_marker;
extern int8_t marker_tracking;

void plot_init(void);
void update_grid(void);
Expand All @@ -244,7 +244,8 @@ void markmap_all_markers(void);

void marker_position(int m, int t, int *x, int *y);
int search_nearest_index(int x, int y, int t);
int marker_search(int mode);
void set_marker_search(int mode);
int marker_search(void);
int marker_search_left(int from);
int marker_search_right(int from);

Expand Down Expand Up @@ -311,7 +312,6 @@ typedef struct {
int8_t _active_marker;
uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TD_FUNC m: DOMAIN_MODE */
uint8_t _marker_smith_format;

uint8_t _reserved[50];
int32_t checksum;
} properties_t;
Expand All @@ -324,8 +324,6 @@ extern int16_t lastsaveid;
extern properties_t *active_props;
extern properties_t current_props;

extern int8_t previous_marker;

#define frequency0 current_props._frequency0
#define frequency1 current_props._frequency1
#define sweep_points current_props._sweep_points
Expand Down Expand Up @@ -380,8 +378,6 @@ void ui_init(void);
void ui_show(void);
void ui_hide(void);

extern uint8_t operation_requested;

void touch_start_watchdog(void);
void touch_position(int *x, int *y);
void handle_touch_interrupt(void);
Expand Down
21 changes: 13 additions & 8 deletions plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ format_smith_value(char *buf, int len, const float coeff[2], uint32_t frequency)

case MS_RX:
n = string_value_with_prefix(buf, len, zr, S_OHM[0]);
buf[n++] = ' ';
if (zi >= 0)
buf[n++] = ' ';
string_value_with_prefix(buf+n, len-n, zi, 'j');
break;

Expand Down Expand Up @@ -1161,19 +1162,14 @@ 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;

int8_t marker_tracking = false;

int
marker_search(int mode)
marker_search(void)
{
int i;
int found = 0;

if (mode == 0)
compare = greater;
else
compare = lesser;

if (uistat.current_trace == -1)
return -1;

Expand All @@ -1189,6 +1185,15 @@ marker_search(int mode)
return found;
}

void
set_marker_search(int mode)
{
if (mode == 0)
compare = greater;
else
compare = lesser;
}

int
marker_search_left(int from)
{
Expand Down
14 changes: 12 additions & 2 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ menu_marker_search_cb(int item)
switch (item) {
case 0: /* maximum */
case 1: /* minimum */
i = marker_search(item);
set_marker_search(item);
i = marker_search();
if (i != -1)
markers[active_marker].index = i;
draw_menu();
Expand All @@ -879,6 +880,10 @@ menu_marker_search_cb(int item)
markers[active_marker].index = i;
draw_menu();
break;
case 4: /* tracking */
marker_tracking = !marker_tracking;
draw_menu();
break;
}
redraw_marker(active_marker, TRUE);
uistat.lever_mode = LM_SEARCH;
Expand Down Expand Up @@ -1085,7 +1090,7 @@ const menuitem_t menu_marker_search[] = {
{ MT_CALLBACK, "MINIMUM", menu_marker_search_cb },
{ MT_CALLBACK, "\2SEARCH\0" S_LARROW" LEFT", menu_marker_search_cb },
{ MT_CALLBACK, "\2SEARCH\0" S_RARROW" RIGHT", menu_marker_search_cb },
//{ MT_CALLBACK, "TRACKING", menu_marker_search_cb },
{ MT_CALLBACK, "TRACKING", menu_marker_search_cb },
{ MT_CANCEL, S_LARROW" BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
Expand Down Expand Up @@ -1419,6 +1424,11 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
*fg = 0xffff;
}
}
} else if (menu == menu_marker_search) {
if (item == 4 && marker_tracking) {
*bg = 0x0000;
*fg = 0xffff;
}
} else if (menu == menu_marker_smith) {
if (marker_smith_format == item) {
*bg = 0x0000;
Expand Down

0 comments on commit 18a1ca4

Please sign in to comment.