From c7af840f535455c52507d332021ec850004ef1a0 Mon Sep 17 00:00:00 2001 From: TT Date: Sun, 17 Nov 2019 10:54:39 +0900 Subject: [PATCH] feat: add feedback of lever mode --- ili9341.c | 9 +++++++++ nanovna.h | 7 +++++++ plot.c | 22 +++++++++++++++------- ui.c | 53 ++++++++++++++++++++++++----------------------------- 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/ili9341.c b/ili9341.c index b551df84..99b4627b 100644 --- a/ili9341.c +++ b/ili9341.c @@ -360,6 +360,15 @@ ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg) } } +void +ili9341_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool invert) +{ + if (invert) + ili9341_drawstring_5x7(str, x, y, bg, fg); + else + ili9341_drawstring_5x7(str, x, y, fg, bg); +} + void ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size) { diff --git a/nanovna.h b/nanovna.h index 49dac8d7..f127bb49 100644 --- a/nanovna.h +++ b/nanovna.h @@ -274,6 +274,7 @@ void ili9341_bulk(int x, int y, int w, int h); void ili9341_fill(int x, int y, int w, int h, int color); void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg); void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg); +void ili9341_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool inv); void ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size); void ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size); void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg); @@ -341,12 +342,18 @@ void clear_all_config_prop_data(void); * ui.c */ +// lever_mode +enum { + LM_MARKER, LM_SEARCH, LM_CENTER, LM_SPAN +}; + typedef struct { int8_t digit; /* 0~5 */ int8_t digit_mode; int8_t current_trace; /* 0..3 */ uint32_t value; // for editing at numeric input area uint32_t previous_value; + uint8_t lever_mode; } uistat_t; extern uistat_t uistat; diff --git a/plot.c b/plot.c index 354a842d..6ef28d7b 100644 --- a/plot.c +++ b/plot.c @@ -1535,7 +1535,7 @@ cell_draw_marker_info(int m, int n, int w, int h) ypos -= n * CELLHEIGHT; chsnprintf(buf, sizeof buf, "%d:", active_marker + 1); xpos += 5; - cell_drawstring_5x7(w, h, buf, xpos, ypos, 0xffff); + cell_drawstring_invert_5x7(w, h, buf, xpos, ypos, 0xffff, uistat.lever_mode == LM_MARKER); xpos += 14; if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { frequency_string(buf, sizeof buf, frequencies[idx]); @@ -1610,14 +1610,22 @@ draw_frequencies(void) } else if (frequency1 < 0) { int fcenter = frequency0; int fspan = -frequency1; - strcpy(buf, "CENTER "); - frequency_string(buf+7, 24-7, fcenter); + int x = OFFSETX; + strcpy(buf, "CENTER"); + ili9341_drawstring_5x7_inv(buf, x, 233, 0xffff, 0x0000, uistat.lever_mode == LM_CENTER); + x += 5 * 6; + strcpy(buf, " "); + frequency_string(buf+1, 24-1, fcenter); strcat(buf, " "); - ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000); - strcpy(buf, "SPAN "); - frequency_string(buf+5, 24-5, fspan); + ili9341_drawstring_5x7(buf, x, 233, 0xffff, 0x0000); + x = 205; + strcpy(buf, "SPAN"); + ili9341_drawstring_5x7_inv(buf, x, 233, 0xffff, 0x0000, uistat.lever_mode == LM_SPAN); + x += 5 * 4; + strcpy(buf, " "); + frequency_string(buf+1, 24-1, fspan); strcat(buf, " "); - ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000); + ili9341_drawstring_5x7(buf, x, 233, 0xffff, 0x0000); } else { int fcenter = frequency0; chsnprintf(buf, 24, "CW %d.%03d %03d MHz ", diff --git a/ui.c b/ui.c index 8c9bb71a..41215590 100644 --- a/ui.c +++ b/ui.c @@ -28,7 +28,8 @@ uistat_t uistat = { digit: 6, - current_trace: 0 + current_trace: 0, + lever_mode: LM_MARKER }; @@ -71,14 +72,9 @@ enum { KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY }; -enum { - LM_MARKER, LM_SEARCH, LM_CENTER, LM_SPAN -}; - uint8_t ui_mode = UI_NORMAL; uint8_t keypad_mode; int8_t selection = 0; -uint8_t lever_mode = LM_MARKER; typedef struct { uint8_t type; @@ -771,6 +767,7 @@ menu_stimulus_cb(int item) 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); @@ -779,7 +776,6 @@ menu_stimulus_cb(int item) ui_mode_keypad(item); ui_process_keypad(); } - lever_mode = item == 3 ? LM_SPAN : LM_CENTER; break; case 5: /* PAUSE */ toggle_sweep(); @@ -820,22 +816,22 @@ menu_marker_op_cb(int item) break; case 3: /* MARKERS->SPAN */ { - if (previous_marker == active_marker) - return; - int32_t freq2 = get_marker_frequency(previous_marker); - if (freq2 < 0) - return; - if (freq > freq2) { - freq2 = freq; - freq = get_marker_frequency(previous_marker); + if (previous_marker == -1 || active_marker == previous_marker) { + int32_t center = get_sweep_frequency(ST_CENTER); + int32_t span = center - freq; + if (span < 0) span = -span; + set_sweep_frequency(ST_SPAN, span * 2); + } else { + int32_t freq2 = get_marker_frequency(previous_marker); + if (freq2 < 0) + return; + if (freq > freq2) { + freq2 = freq; + freq = get_marker_frequency(previous_marker); + } + set_sweep_frequency(ST_START, freq); + set_sweep_frequency(ST_STOP, freq2); } - set_sweep_frequency(ST_START, freq); - set_sweep_frequency(ST_STOP, freq2); -#if 0 - int32_t span = (freq - freq2) * 2; - if (span < 0) span = -span; - set_sweep_frequency(ST_SPAN, span); -#endif } break; } @@ -873,7 +869,7 @@ menu_marker_search_cb(int item) break; } redraw_marker(active_marker, TRUE); - lever_mode = LM_SEARCH; + uistat.lever_mode = LM_SEARCH; } void @@ -918,7 +914,7 @@ menu_marker_sel_cb(int item) } redraw_marker(active_marker, TRUE); draw_menu(); - lever_mode = LM_MARKER; + uistat.lever_mode = LM_MARKER; } const menuitem_t menu_calop[] = { @@ -1720,7 +1716,7 @@ step_round(uint32_t v) { // decade step uint32_t x = 1; - for (x = 1; x * 10 < v; x *= 10) + for (x = 1; x*10 < v; x *= 10) ; // 1-2-5 step @@ -1735,13 +1731,12 @@ step_round(uint32_t v) static void lever_zoom_span(int status) { + uint32_t span = get_sweep_frequency(ST_SPAN); if (status & EVT_UP) { - uint32_t span = get_sweep_frequency(ST_SPAN); span = step_round(span - 1); set_sweep_frequency(ST_SPAN, span); } else if (status & EVT_DOWN) { - uint32_t span = get_sweep_frequency(ST_SPAN); - span = step_round(span); + span = step_round(span + 1); span = step_round(span * 3); set_sweep_frequency(ST_SPAN, span); } @@ -1768,7 +1763,7 @@ ui_process_normal(void) if (status & EVT_BUTTON_SINGLE_CLICK) { ui_mode_menu(); } else { - switch (lever_mode) { + 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;