From 5ebb3330ffd56d4c16f729419cecae25995350d1 Mon Sep 17 00:00:00 2001 From: TT Date: Thu, 5 Jan 2017 09:04:28 +0900 Subject: [PATCH] add menu item delay (but not work) --- main.c | 46 ++++++++++++++++++++++++++-------------------- nanovna.h | 4 ++-- plot.c | 16 ++++++++-------- ui.c | 52 +++++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 77 insertions(+), 41 deletions(-) diff --git a/main.c b/main.c index 39315ba..6313370 100644 --- a/main.c +++ b/main.c @@ -323,6 +323,7 @@ config_t config = { /* menu_normal_color */ 0xffff, /* menu_active_color */ 0x7777, /* trace_colors[4] */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) }, + ///* touch_cal[4] */ { 620, 600, 160, 190 }, /* touch_cal[4] */ { 620, 600, 130, 180 }, /* checksum */ 0 }; @@ -336,6 +337,7 @@ properties_t current_props = { /* frequencies */ {}, /* cal_data */ {}, /* trace[4] */ { + /* enable, type, channel, polar, scale */ { 1, TRC_LOGMAG, 0, 0, 1.0 }, { 1, TRC_LOGMAG, 1, 0, 1.0 }, { 1, TRC_SMITH, 0, 1, 1.0 }, @@ -472,6 +474,7 @@ freq_mode_startstop(void) if (frequency1 <= 0) { int center = frequency0; int span = -frequency1; + ensure_edit_config(); frequency0 = center - span/2; frequency1 = center + span/2; } @@ -483,6 +486,7 @@ freq_mode_centerspan(void) if (frequency1 > 0) { int start = frequency0; int stop = frequency1; + ensure_edit_config(); frequency0 = (start + stop)/2; // center frequency1 = -(stop - start); // span } @@ -493,34 +497,36 @@ freq_mode_centerspan(void) #define STOP_MAX 300000000 void -set_sweep_frequency(int type, int frequency) +set_sweep_frequency(int type, float frequency) { + int32_t freq = frequency; switch (type) { case ST_START: - ensure_edit_config(); freq_mode_startstop(); if (frequency < START_MIN) - frequency = START_MIN; - if (frequency0 != frequency) { - frequency0 = frequency; + freq = START_MIN; + if (frequency0 != freq) { + ensure_edit_config(); + frequency0 = freq; update_frequencies(); } break; case ST_STOP: - ensure_edit_config(); freq_mode_startstop(); if (frequency > STOP_MAX) - frequency = STOP_MAX; - if (frequency1 != frequency) { - frequency1 = frequency; + freq = STOP_MAX; + if (frequency1 != freq) { + ensure_edit_config(); + frequency1 = freq; update_frequencies(); } break; case ST_CENTER: ensure_edit_config(); freq_mode_centerspan(); - if (frequency0 != frequency) { - frequency0 = frequency; + if (frequency0 != freq) { + ensure_edit_config(); + frequency0 = freq; int center = frequency0; int span = -frequency1; if (center-span/2 < START_MIN) { @@ -535,10 +541,10 @@ set_sweep_frequency(int type, int frequency) } break; case ST_SPAN: - ensure_edit_config(); freq_mode_centerspan(); - if (frequency1 != -frequency) { - frequency1 = -frequency; + if (frequency1 != -freq) { + ensure_edit_config(); + frequency1 = -freq; int center = frequency0; int span = -frequency1; if (center-span/2 < START_MIN) { @@ -553,9 +559,9 @@ set_sweep_frequency(int type, int frequency) } break; case ST_CW: - ensure_edit_config(); freq_mode_centerspan(); - if (frequency0 != frequency || frequency1 != 0) { + if (frequency0 != freq || frequency1 != 0) { + ensure_edit_config(); frequency0 = frequency; frequency1 = 0; update_frequencies(); @@ -938,7 +944,7 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[]) const char *trc_type_name[] = { - "LOGMAG", "PHASE", "SMITH", "ADMIT", "POLAR", "LINEAR", "SWR" + "LOGMAG", "PHASE", "DELAY", "SMITH", "POLAR", "LINEAR", "SWR" }; const char *trc_channel_name[] = { "CH0", "CH1" @@ -946,7 +952,7 @@ const char *trc_channel_name[] = { void set_trace_type(int t, int type) { - int polar = type == TRC_SMITH || type == TRC_ADMIT || type == TRC_POLAR; + int polar = type == TRC_SMITH || type == TRC_POLAR; int enabled = type != TRC_OFF; int force = FALSE; @@ -1064,8 +1070,8 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[]) set_trace_type(t, TRC_POLAR); } else if (strcmp(argv[1], "smith") == 0) { set_trace_type(t, TRC_SMITH); - } else if (strcmp(argv[1], "admit") == 0) { - set_trace_type(t, TRC_ADMIT); + } else if (strcmp(argv[1], "delay") == 0) { + set_trace_type(t, TRC_DELAY); } else if (strcmp(argv[1], "linear") == 0) { set_trace_type(t, TRC_LINEAR); } else if (strcmp(argv[1], "swr") == 0) { diff --git a/nanovna.h b/nanovna.h index 13ef804..77bb20c 100644 --- a/nanovna.h +++ b/nanovna.h @@ -55,7 +55,7 @@ enum { ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW }; -void set_sweep_frequency(int type, int frequency); +void set_sweep_frequency(int type, float frequency); float my_atof(const char *p); @@ -141,7 +141,7 @@ extern const uint32_t numfont20x24[][24]; #define TRACES_MAX 4 enum { - TRC_LOGMAG, TRC_PHASE, TRC_SMITH, TRC_ADMIT, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_OFF + TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_OFF }; extern const char *trc_type_name[]; diff --git a/plot.c b/plot.c index 129ff25..42537d4 100644 --- a/plot.c +++ b/plot.c @@ -490,7 +490,7 @@ trace_into_index(int x, int t, int i, float coeff[2]) v = 9 - swr(coeff); break; case TRC_SMITH: - case TRC_ADMIT: + //case TRC_ADMIT: case TRC_POLAR: cartesian_scale(coeff[0], coeff[1], &x, &y, trace[t].scale); return INDEX(x, y, i); @@ -605,7 +605,7 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequ case TRC_SMITH: gamma2imp(buf, len, coeff, frequency); break; - case TRC_ADMIT: + //case TRC_ADMIT: case TRC_POLAR: chsnprintf(buf, len, "%.2f %.2fj", coeff[0], coeff[1]); break; @@ -626,7 +626,7 @@ trace_get_info(int t, char *buf, int len) trace[t].channel, type, (int)(trace[t].scale*90)); break; case TRC_SMITH: - case TRC_ADMIT: + //case TRC_ADMIT: case TRC_POLAR: chsnprintf(buf, len, "CH%d %s %.1fFS", trace[t].channel, type, trace[t].scale); @@ -901,11 +901,11 @@ search_nearest_index(int x, int y, int t) int min_d = 1000; int i; for (i = 0; i < 101; i++) { - int dx = x - CELL_X(index[i]) - OFFSETX; - int dy = y - CELL_Y(index[i]) - OFFSETY; + int16_t dx = x - CELL_X(index[i]) - OFFSETX; + int16_t dy = y - CELL_Y(index[i]) - OFFSETY; if (dx < 0) dx = -dx; if (dy < 0) dy = -dy; - if (dx > 20 && dy > 20) + if (dx > 20 || dy > 20) continue; int d = dx*dx + dy*dy; if (d < min_d) { @@ -1007,8 +1007,8 @@ draw_cell(int m, int n) else { if (trace[t].type == TRC_SMITH) grid_mode |= GRID_SMITH; - else if (trace[t].type == TRC_ADMIT) - grid_mode |= GRID_ADMIT; + //else if (trace[t].type == TRC_ADMIT) + // grid_mode |= GRID_ADMIT; else grid_mode |= GRID_POLAR; } diff --git a/ui.c b/ui.c index a261959..e3fe5ab 100644 --- a/ui.c +++ b/ui.c @@ -248,6 +248,7 @@ int touch_check(void) if (stat) { last_touch_x = touch_measure_x(); last_touch_y = touch_measure_y(); + touch_prepare_sense(); } if (stat != last_touch_status) { @@ -400,6 +401,7 @@ menu_save_cb(int item) if (item < 0 || item >= 5) return; if (caldata_save(item) == 0) { + menu_move_back(); ui_mode_normal(); draw_cal_status(); } @@ -417,14 +419,40 @@ menu_trace_cb(int item) static void menu_format_cb(int item) { - set_trace_type(uistat.current_trace, item); + switch (item) { + case 0: + set_trace_type(uistat.current_trace, TRC_LOGMAG); + break; + case 1: + set_trace_type(uistat.current_trace, TRC_PHASE); + break; + case 2: + set_trace_type(uistat.current_trace, TRC_DELAY); + break; + case 3: + set_trace_type(uistat.current_trace, TRC_SMITH); + break; + case 4: + set_trace_type(uistat.current_trace, TRC_SWR); + break; + } + ui_mode_normal(); } static void menu_format2_cb(int item) { - menu_format_cb(item + 5); + switch (item) { + case 0: + set_trace_type(uistat.current_trace, TRC_POLAR); + break; + case 1: + set_trace_type(uistat.current_trace, TRC_LINEAR); + break; + } + + ui_mode_normal(); } static void @@ -590,13 +618,14 @@ const menuitem_t menu_trace[] = { { MT_CALLBACK, "1", menu_trace_cb }, { MT_CALLBACK, "2", menu_trace_cb }, { MT_CALLBACK, "3", menu_trace_cb }, + { MT_CALLBACK, "\2SINGLE\0TRACE", menu_single_trace_cb }, { MT_CANCEL, "BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; const menuitem_t menu_format2[] = { + { MT_CALLBACK, "POLAR", menu_format2_cb }, { MT_CALLBACK, "LINEAR", menu_format2_cb }, - { MT_CALLBACK, "SWR", menu_format2_cb }, { MT_CANCEL, "BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -604,9 +633,9 @@ const menuitem_t menu_format2[] = { const menuitem_t menu_format[] = { { MT_CALLBACK, "LOGMAG", menu_format_cb }, { MT_CALLBACK, "PHASE", menu_format_cb }, + { MT_CALLBACK, "DELAY", menu_format_cb }, { MT_CALLBACK, "SMITH", menu_format_cb }, - { MT_CALLBACK, "ADMIT", menu_format_cb }, - { MT_CALLBACK, "POLAR", menu_format_cb }, + { MT_CALLBACK, "SWR", menu_format_cb }, { MT_SUBMENU, "MORE", menu_format2 }, //{ MT_CALLBACK, "LINEAR", menu_format_cb }, //{ MT_CALLBACK, "SWR", menu_format_cb }, @@ -615,14 +644,13 @@ const menuitem_t menu_format[] = { }; const menuitem_t menu_channel[] = { - { MT_CALLBACK, "CH0", menu_channel_cb }, - { MT_CALLBACK, "CH1", menu_channel_cb }, + { MT_CALLBACK, "\2CH0\0REFLECT", menu_channel_cb }, + { MT_CALLBACK, "\2CH1\0THROUGH", menu_channel_cb }, { MT_CANCEL, "BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; const menuitem_t menu_display[] = { - { MT_CALLBACK, "\2SINGLE\0TRACE", menu_single_trace_cb }, { MT_SUBMENU, "TRACE", menu_trace }, { MT_SUBMENU, "FORMAT", menu_format }, { MT_CALLBACK, "SCALE", menu_scale_cb }, @@ -1196,9 +1224,11 @@ touch_pickup_marker(void) marker_position(m, t, &x, &y); if (sq_distance(x - touch_x, y - touch_y) < 400) { - active_marker = m; - redraw_marker(active_marker, TRUE); - + if (active_marker != m) { + active_marker = m; + redraw_marker(active_marker, TRUE); + } + // drag marker until release drag_marker(t, m); return TRUE; }