mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
feat: add lever operations (center, span, search)
This commit is contained in:
parent
e6035a5d96
commit
b909ccb716
3
main.c
3
main.c
|
|
@ -834,6 +834,9 @@ void
|
||||||
set_sweep_frequency(int type, int32_t freq)
|
set_sweep_frequency(int type, int32_t freq)
|
||||||
{
|
{
|
||||||
int cal_applied = cal_status & CALSTAT_APPLY;
|
int cal_applied = cal_status & CALSTAT_APPLY;
|
||||||
|
// negative value indicate overflow, do nothing
|
||||||
|
if (freq < 0)
|
||||||
|
return;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ST_START:
|
case ST_START:
|
||||||
freq_mode_startstop();
|
freq_mode_startstop();
|
||||||
|
|
|
||||||
118
ui.c
118
ui.c
|
|
@ -71,9 +71,14 @@ enum {
|
||||||
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY
|
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 ui_mode = UI_NORMAL;
|
||||||
uint8_t keypad_mode;
|
uint8_t keypad_mode;
|
||||||
int8_t selection = 0;
|
int8_t selection = 0;
|
||||||
|
uint8_t lever_mode = LM_MARKER;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
|
@ -774,6 +779,7 @@ menu_stimulus_cb(int item)
|
||||||
ui_mode_keypad(item);
|
ui_mode_keypad(item);
|
||||||
ui_process_keypad();
|
ui_process_keypad();
|
||||||
}
|
}
|
||||||
|
lever_mode = item == 3 ? LM_SPAN : LM_CENTER;
|
||||||
break;
|
break;
|
||||||
case 5: /* PAUSE */
|
case 5: /* PAUSE */
|
||||||
toggle_sweep();
|
toggle_sweep();
|
||||||
|
|
@ -867,6 +873,7 @@ menu_marker_search_cb(int item)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
redraw_marker(active_marker, TRUE);
|
redraw_marker(active_marker, TRUE);
|
||||||
|
lever_mode = LM_SEARCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -911,6 +918,7 @@ menu_marker_sel_cb(int item)
|
||||||
}
|
}
|
||||||
redraw_marker(active_marker, TRUE);
|
redraw_marker(active_marker, TRUE);
|
||||||
draw_menu();
|
draw_menu();
|
||||||
|
lever_mode = LM_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
const menuitem_t menu_calop[] = {
|
const menuitem_t menu_calop[] = {
|
||||||
|
|
@ -1665,6 +1673,93 @@ ui_mode_normal(void)
|
||||||
ui_mode = UI_NORMAL;
|
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)
|
||||||
|
{
|
||||||
|
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 * 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
|
static void
|
||||||
ui_process_normal(void)
|
ui_process_normal(void)
|
||||||
{
|
{
|
||||||
|
|
@ -1673,23 +1768,12 @@ ui_process_normal(void)
|
||||||
if (status & EVT_BUTTON_SINGLE_CLICK) {
|
if (status & EVT_BUTTON_SINGLE_CLICK) {
|
||||||
ui_mode_menu();
|
ui_mode_menu();
|
||||||
} else {
|
} else {
|
||||||
do {
|
switch (lever_mode) {
|
||||||
if (active_marker >= 0 && markers[active_marker].enabled) {
|
case LM_MARKER: lever_move_marker(status); break;
|
||||||
if ((status & EVT_DOWN) && markers[active_marker].index > 0) {
|
case LM_SEARCH: lever_search_marker(status); break;
|
||||||
markers[active_marker].index--;
|
case LM_CENTER: lever_move_center(status); break;
|
||||||
markers[active_marker].frequency = frequencies[markers[active_marker].index];
|
case LM_SPAN: lever_zoom_span(status); break;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue