Skip to content

Commit

Permalink
feat: add feedback of lever mode
Browse files Browse the repository at this point in the history
  • Loading branch information
edy555 committed Nov 17, 2019
1 parent b909ccb commit c7af840
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 36 deletions.
9 changes: 9 additions & 0 deletions ili9341.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 15 additions & 7 deletions plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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 ",
Expand Down
53 changes: 24 additions & 29 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

uistat_t uistat = {
digit: 6,
current_trace: 0
current_trace: 0,
lever_mode: LM_MARKER
};


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit c7af840

Please sign in to comment.