mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Merge branch 'lever-ops'
This commit is contained in:
commit
e6693f1f25
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
3
main.c
3
main.c
|
|
@ -834,6 +834,9 @@ void
|
|||
set_sweep_frequency(int type, int32_t freq)
|
||||
{
|
||||
int cal_applied = cal_status & CALSTAT_APPLY;
|
||||
// negative value indicate overflow, do nothing
|
||||
if (freq < 0)
|
||||
return;
|
||||
switch (type) {
|
||||
case ST_START:
|
||||
freq_mode_startstop();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
22
plot.c
22
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 ",
|
||||
|
|
|
|||
145
ui.c
145
ui.c
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
uistat_t uistat = {
|
||||
digit: 6,
|
||||
current_trace: 0
|
||||
current_trace: 0,
|
||||
lever_mode: LM_MARKER
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -766,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);
|
||||
|
|
@ -814,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;
|
||||
}
|
||||
|
|
@ -867,6 +869,7 @@ menu_marker_search_cb(int item)
|
|||
break;
|
||||
}
|
||||
redraw_marker(active_marker, TRUE);
|
||||
uistat.lever_mode = LM_SEARCH;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -911,6 +914,7 @@ menu_marker_sel_cb(int item)
|
|||
}
|
||||
redraw_marker(active_marker, TRUE);
|
||||
draw_menu();
|
||||
uistat.lever_mode = LM_MARKER;
|
||||
}
|
||||
|
||||
const menuitem_t menu_calop[] = {
|
||||
|
|
@ -1665,6 +1669,92 @@ ui_mode_normal(void)
|
|||
ui_mode = UI_NORMAL;
|
||||
}
|
||||
|
||||
static void
|
||||
lever_move_marker(int status)
|
||||
{
|
||||
do {
|
||||
if (active_marker >= 0 && markers[active_marker].enabled) {
|
||||
if ((status & EVT_DOWN) && markers[active_marker].index > 0) {
|
||||
markers[active_marker].index--;
|
||||
markers[active_marker].frequency = frequencies[markers[active_marker].index];
|
||||
redraw_marker(active_marker, FALSE);
|
||||
}
|
||||
if ((status & EVT_UP) && markers[active_marker].index < 100) {
|
||||
markers[active_marker].index++;
|
||||
markers[active_marker].frequency = frequencies[markers[active_marker].index];
|
||||
redraw_marker(active_marker, FALSE);
|
||||
}
|
||||
}
|
||||
status = btn_wait_release();
|
||||
} while (status != 0);
|
||||
if (active_marker >= 0)
|
||||
redraw_marker(active_marker, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
lever_search_marker(int status)
|
||||
{
|
||||
if (active_marker >= 0) {
|
||||
if (status & EVT_DOWN) {
|
||||
int i = marker_search_left(markers[active_marker].index);
|
||||
if (i != -1)
|
||||
markers[active_marker].index = i;
|
||||
} else if (status & EVT_UP) {
|
||||
int i = marker_search_right(markers[active_marker].index);
|
||||
if (i != -1)
|
||||
markers[active_marker].index = i;
|
||||
}
|
||||
redraw_marker(active_marker, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// ex. 10942 -> 10000
|
||||
// 6791 -> 5000
|
||||
// 341 -> 200
|
||||
static uint32_t
|
||||
step_round(uint32_t v)
|
||||
{
|
||||
// decade step
|
||||
uint32_t x = 1;
|
||||
for (x = 1; x*10 < v; x *= 10)
|
||||
;
|
||||
|
||||
// 1-2-5 step
|
||||
if (x * 2 > v)
|
||||
return x;
|
||||
else if (x * 5 > v)
|
||||
return x * 2;
|
||||
else
|
||||
return x * 5;
|
||||
}
|
||||
|
||||
static void
|
||||
lever_zoom_span(int status)
|
||||
{
|
||||
uint32_t span = get_sweep_frequency(ST_SPAN);
|
||||
if (status & EVT_UP) {
|
||||
span = step_round(span - 1);
|
||||
set_sweep_frequency(ST_SPAN, span);
|
||||
} else if (status & EVT_DOWN) {
|
||||
span = step_round(span + 1);
|
||||
span = step_round(span * 3);
|
||||
set_sweep_frequency(ST_SPAN, span);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
lever_move_center(int status)
|
||||
{
|
||||
uint32_t center = get_sweep_frequency(ST_CENTER);
|
||||
uint32_t span = get_sweep_frequency(ST_SPAN);
|
||||
span = step_round(span / 3);
|
||||
if (status & EVT_UP) {
|
||||
set_sweep_frequency(ST_CENTER, center + span);
|
||||
} else if (status & EVT_DOWN) {
|
||||
set_sweep_frequency(ST_CENTER, center - span);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ui_process_normal(void)
|
||||
{
|
||||
|
|
@ -1673,23 +1763,12 @@ ui_process_normal(void)
|
|||
if (status & EVT_BUTTON_SINGLE_CLICK) {
|
||||
ui_mode_menu();
|
||||
} else {
|
||||
do {
|
||||
if (active_marker >= 0 && markers[active_marker].enabled) {
|
||||
if ((status & EVT_DOWN) && markers[active_marker].index > 0) {
|
||||
markers[active_marker].index--;
|
||||
markers[active_marker].frequency = frequencies[markers[active_marker].index];
|
||||
redraw_marker(active_marker, FALSE);
|
||||
}
|
||||
if ((status & EVT_UP) && markers[active_marker].index < 100) {
|
||||
markers[active_marker].index++;
|
||||
markers[active_marker].frequency = frequencies[markers[active_marker].index];
|
||||
redraw_marker(active_marker, FALSE);
|
||||
}
|
||||
}
|
||||
status = btn_wait_release();
|
||||
} while (status != 0);
|
||||
if (active_marker >= 0)
|
||||
redraw_marker(active_marker, TRUE);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue