From 863691c554606713cd37072e06e0af58676448bb Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 22 Feb 2020 12:24:32 +0900 Subject: [PATCH 1/3] fix: adjust spaces frequency and marker values --- plot.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/plot.c b/plot.c index f5ef8ea..f580cf4 100644 --- a/plot.c +++ b/plot.c @@ -623,7 +623,7 @@ trace_get_value_string(int t, char *buf, int len, float array[POINTS_COUNT][2], v = logmag(coeff); break; case TRC_PHASE: - format = "%.3f"S_DEGREE; + format = "%.1f"S_DEGREE; v = phase(coeff); break; case TRC_DELAY: @@ -741,7 +741,7 @@ trace_get_info(int t, char *buf, int len) if (scale != 1.0) return chsnprintf(buf, len, "%s %.1fFS", name, scale); else - return chsnprintf(buf, len, name); + return chsnprintf(buf, len, "%s ", name); default: return chsnprintf(buf, len, "%s %F/", name, scale); } @@ -1584,7 +1584,7 @@ cell_draw_marker_info(int m, int n, int w, int h) cell_drawstring(w, h, buf, xpos, ypos); xpos += 67; if (uistat.marker_delta && mk != active_marker) - trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index); + trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index); else trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index); setForegroundColor(DEFAULT_FG_COLOR); @@ -1654,7 +1654,7 @@ cell_draw_marker_info(int m, int n, int w, int h) if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { //frequency_string(buf, sizeof buf, frequencies[idx], ""); - chsnprintf(buf, sizeof buf, "%16qHz", frequencies[idx]); + chsnprintf(buf, sizeof buf, "%qHz", frequencies[idx]); } else { chsnprintf(buf, sizeof buf, "%Fs (%Fm)", time_of_index(idx), distance_of_index(idx)); } @@ -1682,13 +1682,13 @@ draw_frequencies(void) char buf2[32];buf2[0]=0; if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { if (frequency0 < frequency1) { - chsnprintf(buf1, sizeof(buf1), " START %16qHz", frequency0); - chsnprintf(buf2, sizeof(buf2), "STOP %16qHz", frequency1); + chsnprintf(buf1, sizeof(buf1), " START %qHz", frequency0); + chsnprintf(buf2, sizeof(buf2), " STOP %qHz", frequency1); } else if (frequency0 > frequency1) { - chsnprintf(buf1, sizeof(buf1), " CENTER %16qHz", frequency0/2 + frequency1/2); - chsnprintf(buf2, sizeof(buf2), "SPAN %16qHz", frequency0 - frequency1); + chsnprintf(buf1, sizeof(buf1), " CENTER %qHz", frequency0/2 + frequency1/2); + chsnprintf(buf2, sizeof(buf2), " SPAN %qHz", frequency0 - frequency1); } else { - chsnprintf(buf1, sizeof(buf1), " CW %16qHz", frequency0); + chsnprintf(buf1, sizeof(buf1), " CW %qHz", frequency0); } } else { chsnprintf(buf1, sizeof(buf1), " START 0s"); @@ -1697,8 +1697,10 @@ draw_frequencies(void) setForegroundColor(DEFAULT_FG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR); ili9341_fill(0, 232, 320, 8, DEFAULT_BG_COLOR); - if (uistat.lever_mode == LM_SPAN || uistat.lever_mode == LM_CENTER) + if (uistat.lever_mode == LM_CENTER) buf1[0] = S_SARROW[0]; + if (uistat.lever_mode == LM_SPAN) + buf2[0] = S_SARROW[0]; ili9341_drawstring(buf1, OFFSETX, 232); ili9341_drawstring(buf2, 200, 232); } From fb3c9cf82ff2e354f1b560131c76c08e11518678 Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 22 Feb 2020 22:40:06 +0900 Subject: [PATCH 2/3] fix: adjust width of space and triangle --- Font5x7.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Font5x7.c b/Font5x7.c index 0a3a828..a69bcc7 100644 --- a/Font5x7.c +++ b/Font5x7.c @@ -493,7 +493,7 @@ const uint8_t x5x7_bits[127*7] = |** | |* | +--------+ */ - 0b10000000|CHAR5x7_WIDTH_5px, + 0b10000000|CHAR5x7_WIDTH_4px, 0b11000000, 0b11100000, 0b11110000, @@ -645,7 +645,7 @@ const uint8_t x5x7_bits[127*7] = | | | | +--------+ */ - 0b00000000|CHAR5x7_WIDTH_3px, + 0b00000000|CHAR5x7_WIDTH_4px, 0b00000000, 0b00000000, 0b00000000, From 93d1233d8b72d6c68a7dd3d8dd77b98e048e28c9 Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 22 Feb 2020 22:41:50 +0900 Subject: [PATCH 3/3] feat: change the operations to select lever mode --- main.c | 4 ++-- nanovna.h | 8 +++++++ plot.c | 12 ++++++----- ui.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/main.c b/main.c index 795d187..c8e6369 100644 --- a/main.c +++ b/main.c @@ -914,9 +914,9 @@ set_sweep_frequency(int type, uint32_t freq) break; case ST_CENTER: freq_mode_centerspan(); - uint32_t center = frequency0/2 + frequency1/2; + uint32_t center = FREQ_CENTER(); if (center != freq) { - uint32_t span = frequency0 - frequency1; + uint32_t span = FREQ_SPAN(); ensure_edit_config(); if (freq < START_MIN + span/2) { span = (freq - START_MIN) * 2; diff --git a/nanovna.h b/nanovna.h index a1b490c..badde52 100644 --- a/nanovna.h +++ b/nanovna.h @@ -371,6 +371,14 @@ extern properties_t current_props; #define velocity_factor current_props._velocity_factor #define marker_smith_format current_props._marker_smith_format +#define FREQ_IS_STARTSTOP() (frequency0 < frequency1) +#define FREQ_IS_CENTERSPAN() (frequency0 > frequency1) +#define FREQ_IS_CW() (frequency0 == frequency1) +#define FREQ_START() (frequency0) +#define FREQ_STOP() (frequency1) +#define FREQ_CENTER() (frequency0/2 + frequency1/2) +#define FREQ_SPAN() (frequency0 - frequency1) + int caldata_save(int id); int caldata_recall(int id); const properties_t *caldata_ref(int id); diff --git a/plot.c b/plot.c index f580cf4..901c248 100644 --- a/plot.c +++ b/plot.c @@ -1467,7 +1467,9 @@ draw_all_cells(bool flush_markmap) void draw_all(bool flush) { - if (redraw_request & REDRAW_CELLS) + if (redraw_request & REDRAW_MARKER) + markmap_upperarea(); + if (redraw_request & (REDRAW_CELLS | REDRAW_MARKER)) draw_all_cells(flush); if (redraw_request & REDRAW_FREQUENCY) draw_frequencies(); @@ -1681,12 +1683,12 @@ draw_frequencies(void) char buf1[32]; char buf2[32];buf2[0]=0; if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { - if (frequency0 < frequency1) { + if (FREQ_IS_STARTSTOP()) { chsnprintf(buf1, sizeof(buf1), " START %qHz", frequency0); chsnprintf(buf2, sizeof(buf2), " STOP %qHz", frequency1); - } else if (frequency0 > frequency1) { - chsnprintf(buf1, sizeof(buf1), " CENTER %qHz", frequency0/2 + frequency1/2); - chsnprintf(buf2, sizeof(buf2), " SPAN %qHz", frequency0 - frequency1); + } else if (FREQ_IS_CENTERSPAN()) { + chsnprintf(buf1, sizeof(buf1), " CENTER %qHz", FREQ_CENTER()); + chsnprintf(buf2, sizeof(buf2), " SPAN %qHz", FREQ_SPAN()); } else { chsnprintf(buf1, sizeof(buf1), " CW %qHz", frequency0); } diff --git a/ui.c b/ui.c index c27b354..d367ef6 100644 --- a/ui.c +++ b/ui.c @@ -439,6 +439,15 @@ enter_dfu(void) NVIC_SystemReset(); } +static void +select_lever_mode(int mode) +{ + if (uistat.lever_mode != mode) { + uistat.lever_mode = mode; + redraw_request |= REDRAW_FREQUENCY | REDRAW_MARKER; + } +} + // type of menu item enum { MT_NONE, @@ -625,7 +634,7 @@ menu_transform_cb(int item, uint8_t data) (void)item; (void)data; domain_mode ^= DOMAIN_TIME; - uistat.lever_mode = LM_MARKER; + select_lever_mode(LM_MARKER); draw_frequencies(); ui_mode_normal(); } @@ -692,7 +701,6 @@ menu_stimulus_cb(int item, uint8_t data) case 2: /* CENTER */ case 3: /* SPAN */ case 4: /* CW */ - uistat.lever_mode = item == 3 ? LM_SPAN : LM_CENTER; status = btn_wait_release(); if (status & EVT_BUTTON_DOWN_LONG) { ui_mode_numeric(item); @@ -803,7 +811,7 @@ menu_marker_search_cb(int item, uint8_t data) } draw_menu(); redraw_marker(active_marker, TRUE); - uistat.lever_mode = LM_SEARCH; + select_lever_mode(LM_SEARCH); } static void @@ -860,7 +868,6 @@ menu_marker_sel_cb(int item, uint8_t data) } redraw_marker(active_marker, TRUE); draw_menu(); - uistat.lever_mode = LM_MARKER; } const menuitem_t menu_calop[] = { @@ -1724,15 +1731,15 @@ lever_zoom_span(int status) } static void -lever_move_center(int status) +lever_move(int status, int mode) { - uint32_t center = get_sweep_frequency(ST_CENTER); + uint32_t center = get_sweep_frequency(mode); uint32_t span = get_sweep_frequency(ST_SPAN); span = step_round(span / 3); if (status & EVT_UP) { - set_sweep_frequency(ST_CENTER, center + span); + set_sweep_frequency(mode, center + span); } else if (status & EVT_DOWN) { - set_sweep_frequency(ST_CENTER, center - span); + set_sweep_frequency(mode, center - span); } } @@ -1747,8 +1754,15 @@ ui_process_normal(void) switch (uistat.lever_mode) { case LM_MARKER: lever_move_marker(status); break; case LM_SEARCH: lever_search_marker(status); break; - case LM_CENTER: lever_move_center(status); break; - case LM_SPAN: lever_zoom_span(status); break; + case LM_CENTER: + lever_move(status, FREQ_IS_STARTSTOP() ? ST_START : ST_CENTER); + break; + case LM_SPAN: + if (FREQ_IS_STARTSTOP()) + lever_move(status, ST_STOP); + else + lever_zoom_span(status); + break; } } } @@ -2120,7 +2134,8 @@ touch_pickup_marker(void) } // select trace uistat.current_trace = t; - + select_lever_mode(LM_MARKER); + // drag marker until release drag_marker(t, m); return TRUE; @@ -2131,6 +2146,27 @@ touch_pickup_marker(void) return FALSE; } +static int +touch_lever_mode_select(void) +{ + int touch_x, touch_y; + touch_position(&touch_x, &touch_y); + if (touch_y > HEIGHT) { + if (touch_x < 160) { + select_lever_mode(LM_CENTER); + } else { + select_lever_mode(LM_SPAN); + } + return TRUE; + } + + if (touch_y < 15) { + select_lever_mode(LM_MARKER); + return TRUE; + } + + return FALSE; + } static void ui_process_touch(void) @@ -2145,6 +2181,10 @@ void ui_process_touch(void) if (touch_pickup_marker()) { break; + } else if (touch_lever_mode_select()) { + draw_all(FALSE); + touch_wait_release(); + break; } touch_wait_release();