From d84a212a3bf6dfe140d63473fb84952369fc1d9b Mon Sep 17 00:00:00 2001 From: TT Date: Thu, 1 Dec 2016 01:08:13 +0900 Subject: [PATCH] add channel menu, narrow and ensure selection, reverse marker moving direction --- Makefile | 2 +- main.c | 16 ++++++++++++---- nanovna.h | 1 + ui.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index a3adad2..1b155b7 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ endif # Stack size to the allocated to the Cortex-M main/exceptions stack. This # stack is used for processing interrupts and exceptions. ifeq ($(USE_EXCEPTIONS_STACKSIZE),) - USE_EXCEPTIONS_STACKSIZE = 0x280 + USE_EXCEPTIONS_STACKSIZE = 0x200 endif # diff --git a/main.c b/main.c index 9d3c034..d4ab073 100644 --- a/main.c +++ b/main.c @@ -46,7 +46,7 @@ void scan_lcd(void); static MUTEX_DECL(mutex); -static THD_WORKING_AREA(waThread1, 400); +static THD_WORKING_AREA(waThread1, 440); static THD_FUNCTION(Thread1, arg) { (void)arg; @@ -513,7 +513,7 @@ eterm_copy(int dst, int src) } -struct open_model { +const struct open_model { float c0; float c1; float c2; @@ -829,7 +829,7 @@ const char *trc_type_name[] = { "LOGMAG", "PHASE", "SMITH", "ADMIT", "POLAR", "LINEAR", "SWR" }; const char *trc_channel_name[] = { - "S11", "S21" + "CH0", "CH1" }; void set_trace_type(int t, int type) @@ -856,6 +856,14 @@ void set_trace_type(int t, int type) force_set_markmap(); } +void set_trace_channel(int t, int channel) +{ + if (trace[t].channel != channel) { + trace[t].channel = channel; + force_set_markmap(); + } +} + static float my_atof(const char *p) { @@ -1109,7 +1117,7 @@ static void cmd_stat(BaseSequentialStream *chp, int argc, char *argv[]) -#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(400) +#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(440) static THD_WORKING_AREA(waThread2, SHELL_WA_SIZE); static const ShellCommand commands[] = diff --git a/nanovna.h b/nanovna.h index 4543959..990c0c5 100644 --- a/nanovna.h +++ b/nanovna.h @@ -123,6 +123,7 @@ typedef struct { //extern trace_t trace[TRACES_MAX]; void set_trace_type(int t, int type); +void set_trace_channel(int t, int channel); // marker diff --git a/ui.c b/ui.c index 7b80e0f..c019c03 100644 --- a/ui.c +++ b/ui.c @@ -245,6 +245,18 @@ static void menu_format2_cb(int item) { menu_format_cb(item + 5); + ui_status = FALSE; + ui_hide(); +} + +static void +menu_channel_cb(int item) +{ + if (item < 0 || item >= 2) + return; + set_trace_channel(uistat.current_trace, item); + ui_status = FALSE; + ui_hide(); } static void @@ -324,10 +336,18 @@ const menuitem_t menu_format[] = { { MT_NONE, NULL, NULL } // sentinel }; +const menuitem_t menu_channel[] = { + { MT_CALLBACK, "0", menu_channel_cb }, + { MT_CALLBACK, "1", menu_channel_cb }, + { MT_CANCEL, "BACK", NULL }, + { MT_NONE, NULL, NULL } // sentinel +}; + const menuitem_t menu_display[] = { { MT_SUBMENU, "TRACE", menu_trace }, { MT_SUBMENU, "FORMAT", menu_format }, { MT_SUBMENU, "SCALE", menu_format }, + { MT_SUBMENU, "CHANNEL", menu_channel }, { MT_CANCEL, "BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -366,11 +386,23 @@ const menuitem_t *menu_stack[4] = { menu_top, NULL, NULL, NULL }; +static void +ensure_selection(void) +{ + const menuitem_t *menu = menu_stack[menu_current_level]; + int i; + for (i = 0; menu[i].type != MT_NONE; i++) + ; + if (selection >= i) + selection = i-1; +} + static void menu_move_back(void) { if (menu_current_level == 0) return; menu_current_level--; + ensure_selection(); erase_buttons(); } @@ -379,6 +411,7 @@ static void menu_move_top(void) if (menu_current_level == 0) return; menu_current_level = 0; + ensure_selection(); erase_buttons(); } @@ -412,6 +445,7 @@ void menu_invoke(int selection) break; menu_current_level++; menu_stack[menu_current_level] = (const menuitem_t*)menu->reference; + erase_buttons(); selection = 0; break; } @@ -503,22 +537,24 @@ ui_process(void) ui_show(); } else { if (ui_status) { - if (status & EVT_UP) { + if (status & EVT_UP + && menu_stack[menu_current_level][selection+1].type != MT_NONE) { selection++; draw_buttons(); } - if (status & EVT_DOWN) { + if (status & EVT_DOWN + && selection > 0) { selection--; draw_buttons(); } } else { do { if (active_marker >= 0 && markers[active_marker].enabled) { - if ((status & EVT_UP) && markers[active_marker].index > 0) { + if ((status & EVT_DOWN) && markers[active_marker].index > 0) { markers[active_marker].index--; redraw_marker(active_marker, FALSE); } - if ((status & EVT_DOWN) && markers[active_marker].index < 100) { + if ((status & EVT_UP) && markers[active_marker].index < 100) { markers[active_marker].index++; redraw_marker(active_marker, FALSE); }