From 9fb0638deffa3a3b98ef41c7a857b053da23efd9 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 25 Mar 2020 09:48:55 +0100 Subject: [PATCH] Full screen mode menu --- nanovna.h | 9 +++ plot.c | 35 ++++++--- sa_core.c | 56 ++++++++----- ui.c | 84 ++++++++++++++------ ui_sa.c | 229 +++++++++++++++++++++++++++++++----------------------- 5 files changed, 260 insertions(+), 153 deletions(-) diff --git a/nanovna.h b/nanovna.h index 0984dc7..3074186 100644 --- a/nanovna.h +++ b/nanovna.h @@ -122,6 +122,13 @@ enum { enum { M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, }; + +#define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH ) +#define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH ) +#define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH ) +#define MODE_LOW(x) ((x) == M_LOW || (x) == M_GENLOW ) +#define MODE_SELECT(x) (MODE_HIGH(x) ? 1 : 0) + #define SWEEP_ENABLE 0x01 #define SWEEP_ONCE 0x02 extern int8_t sweep_mode; @@ -537,6 +544,7 @@ typedef struct uistat { uint8_t lever_mode; uint8_t marker_delta; uint8_t marker_tracking; + char text[20]; } uistat_t; extern uistat_t uistat; @@ -576,6 +584,7 @@ extern int settingStepDelay; extern int actualStepDelay; extern int settingMode; void update_rbw(uint32_t delta_f); +int GetActualRBW(void); #define byte uint8_t extern volatile int SI4432_Sel; // currently selected SI4432 diff --git a/plot.c b/plot.c index 481c45e..81f628a 100644 --- a/plot.c +++ b/plot.c @@ -1,5 +1,4 @@ -/* - * Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com +/* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com * All rights reserved. * * This is free software; you can redistribute it and/or modify @@ -796,12 +795,19 @@ static void trace_get_value_string( } else { dfreq = frequencies[i]; } - frequency_string(&buf2[1], sizeof(buf2) -1, dfreq); + if (GetActualRBW() < 10) + plot_printf(&buf2[1], sizeof(buf2) -1, "%3.3f" , (dfreq + 500) / 1000000.0); + else if (GetActualRBW() < 100) + plot_printf(&buf2[1], sizeof(buf2) -1, "%3.2f" , (dfreq + 5000) / 1000000.0); + else + plot_printf(&buf2[1], sizeof(buf2) -1, "%3.1f" , (dfreq + 50000) / 1000000.0); + +// frequency_string(&buf2[1], sizeof(buf2) -1, dfreq); v = logmag(&coeff[i]); if (v == -INFINITY) plot_printf(buf, len, "-INF"); else - plot_printf(buf, len, " %s %.2f", buf2, v - rlevel); + plot_printf(buf, len, "%s %.1f", buf2, v - rlevel); } #ifdef __VNA__ static int @@ -1817,26 +1823,35 @@ static void cell_draw_marker_info(int x0, int y0) continue; #if 1 int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; - int ypos = 1 + (j/2)*(13) - y0; +// int ypos = 1 + (j/2)*(13) - y0; + int ypos = 1 + (j/2)*(16) - y0; #else int xpos = 1 + CELLOFFSETX - x0; int ypos = 1 + j*(FONT_GET_HEIGHT*2+1) - y0; #endif int k = 0; - if (i == active_marker) + if (i == active_marker) { +// ili9341_set_foreground(DEFAULT_BG_COLOR); +// ili9341_set_background(marker_color[markers[i].mtype]); buf[k++] = '\033'; // Right arrow (?) - else + } else { +// ili9341_set_background(DEFAULT_BG_COLOR); +// ili9341_set_foreground(marker_color[markers[i].mtype]); buf[k++] = ' '; +// buf[k++] = ' '; + } buf[k++] = i+'1'; - buf[k++] = marker_letter[markers[i].mtype]; +// buf[k++] = marker_letter[markers[i].mtype]; buf[k++] = 0; + ili9341_set_background(DEFAULT_BG_COLOR); ili9341_set_foreground(marker_color[markers[i].mtype]); cell_drawstring_7x13(buf, xpos, ypos); +// cell_drawstring_size(buf, xpos, ypos, 2); trace_get_value_string( t, buf, sizeof buf, idx, measured[trace[t].channel], frequencies, sweep_points, ridx, markers[i].mtype); -// cell_drawstring_7x13(w, h, buf, xpos+2*7, ypos, config.trace_color[t]); - cell_drawstring_7x13(buf, xpos+4*7, ypos); + cell_drawstring_7x13(buf, xpos+3*7, ypos); +// cell_drawstring_size(buf, xpos+3*7, ypos, 2); j++; } } diff --git a/sa_core.c b/sa_core.c index b218a64..0b8d107 100644 --- a/sa_core.c +++ b/sa_core.c @@ -75,12 +75,14 @@ int settingSpur = 0; int settingAverage = 0; int settingShowStorage = 0; int settingSubtractStorage = 0; -int settingMode = 0; +int settingMode = M_LOW; int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; int extraVFO = false; int settingStepDelay = 0; +float rbw = 0; +float vbw = 0; uint32_t minFreq = 0; uint32_t maxFreq = 520000000; @@ -122,21 +124,31 @@ int GetMode(void) void SetMode(int m) { + if (settingMode == m) + return; settingMode = m; switch(m) { case M_LOW: + set_sweep_frequency(ST_START, (int32_t) 0); + set_sweep_frequency(ST_STOP, (int32_t) 300000000); + goto min_max_low; case M_GENLOW: + set_sweep_frequency(ST_CENTER, (int32_t) 10000000); + set_sweep_frequency(ST_SPAN, 0); + min_max_low: minFreq = 0; maxFreq = 520000000; - set_sweep_frequency(ST_START, (int32_t) 0); - set_sweep_frequency(ST_STOP, (int32_t) 300000000); break; case M_HIGH: - case M_GENHIGH: - minFreq = 260000000; - maxFreq = 960000000; set_sweep_frequency(ST_START, (int32_t) 300000000); set_sweep_frequency(ST_STOP, (int32_t) 960000000); + goto min_max_high; + case M_GENHIGH: + set_sweep_frequency(ST_CENTER, (int32_t) 300000000); + set_sweep_frequency(ST_SPAN, 0); + min_max_high: + minFreq = 240000000; + maxFreq = 960000000; break; } dirty = true; @@ -192,9 +204,9 @@ extern float peakLevel; void SetPowerLevel(int o) { if (o != 100) { - if (settingMode & 1) + if (settingMode == M_HIGH) config.high_level_offset = o - peakLevel - settingAttenuate + settingLevelOffset(); - else + else if (settingMode == M_LOW) config.low_level_offset = o - peakLevel - settingAttenuate + settingLevelOffset(); } else { @@ -206,10 +218,11 @@ void SetPowerLevel(int o) int settingLevelOffset(void) { - if (settingMode & 1) + if (settingMode == M_HIGH) return(config.high_level_offset); - dirty = true; - return(config.low_level_offset); + if (settingMode == M_LOW) + return(config.high_level_offset); + return(0); } void SetRBW(int v) @@ -224,6 +237,10 @@ int GetRBW(void) return(settingBandwidth); } +int GetActualRBW(void) +{ + return((int) rbw); +} void SetSpur(int v) { settingSpur = v; @@ -287,8 +304,6 @@ int temppeakIndex; #define BARSTART 24 -float rbw = 0; -float vbw = 0; int vbwSteps = 1; #if 0 @@ -586,7 +601,7 @@ void update_rbw(uint32_t delta_f) rbw = 2.6; if (rbw > 600) rbw = 600; - SI4432_Sel = (settingMode & 1); + SI4432_Sel = MODE_SELECT(settingMode); rbw = SI4432_SET_RBW(rbw); vbwSteps = ((int)(2 * vbw / rbw)); if (vbwSteps < 1) @@ -598,7 +613,7 @@ static int old_lf = -1; float perform(bool break_on_operation, int i, int32_t f, int extraV) { - long local_IF = ((settingMode & 1) == 0?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); + long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); if (i == 0 && dirty) { if (settingStepDelay == 0){ if (rbw < 10.0) @@ -636,11 +651,11 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) if (lf != old_lf) // only set on change setFreq (1, local_IF + lf); old_lf = lf; - float subRSSI = SI4432_RSSI(lf, (settingMode & 1))+settingLevelOffset()+settingAttenuate; + float subRSSI = SI4432_RSSI(lf, MODE_SELECT(settingMode))+settingLevelOffset()+settingAttenuate; if (RSSI < subRSSI) RSSI = subRSSI; t++; - if ((operation_requested && break_on_operation ) || (settingMode & 2 )) // output modes do not step. + if ((operation_requested && break_on_operation ) || (MODE_OUTPUT(settingMode))) // output modes do not step. subSteps = 0; // abort } while (subSteps-- > 0); return(RSSI); @@ -944,10 +959,9 @@ static void test_acquire(int i) { pause_sweep(); if (test_case[i].center < 300) - settingMode = 0; + settingMode = M_LOW; else - settingMode = 1; - + settingMode = M_HIGH; set_sweep_frequency(ST_CENTER, (int32_t)test_case[i].center * 1000000); set_sweep_frequency(ST_SPAN, (int32_t)test_case[i].span * 1000000); sweep(false); @@ -1174,7 +1188,7 @@ void self_test(void) set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0)); set_refer_output(0); - settingMode = 0; + settingMode = M_LOW; draw_cal_status(); menu_autosettings_cb(0); diff --git a/ui.c b/ui.c index da79dc3..615e017 100644 --- a/ui.c +++ b/ui.c @@ -1,5 +1,4 @@ -/* - * Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com +/* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com * All rights reserved. * * This is free software; you can redistribute it and/or modify @@ -31,6 +30,7 @@ uistat_t uistat = { lever_mode: LM_MARKER, marker_delta: FALSE, marker_tracking : FALSE, + text : "", }; #define NO_EVENT 0 @@ -433,8 +433,11 @@ enum { MT_SUBMENU, MT_CALLBACK, MT_CANCEL, + MT_TITLE, MT_CLOSE }; +#define MT_FORM 0x80 // Or with menu type to get large button with current value +#define MT_MASK(x) (0x7F & (x)) typedef void (*menuaction_cb_t)(int item, uint8_t data); @@ -1048,6 +1051,7 @@ const menuitem_t menu_top[] = { #define MENU_BUTTON_WIDTH 60 +#define MENU_FORM_WIDTH 290 #define MENU_BUTTON_HEIGHT 30 #define NUM_INPUT_HEIGHT 30 @@ -1055,7 +1059,7 @@ const menuitem_t menu_top[] = { #define MENU_STACK_DEPTH_MAX 4 const menuitem_t *menu_stack[MENU_STACK_DEPTH_MAX] = { - menu_top, NULL, NULL, NULL + menu_mode, NULL, NULL, NULL }; static void @@ -1063,7 +1067,7 @@ ensure_selection(void) { const menuitem_t *menu = menu_stack[menu_current_level]; int i; - for (i = 0; menu[i].type != MT_NONE; i++) + for (i = 0; MT_MASK(menu[i].type) != MT_NONE; i++) ; if (selection >= i) selection = i-1; @@ -1074,20 +1078,20 @@ menu_move_back(void) { if (menu_current_level == 0) return; + erase_menu_buttons(); menu_current_level--; ensure_selection(); - erase_menu_buttons(); draw_menu(); } static void menu_push_submenu(const menuitem_t *submenu) { + erase_menu_buttons(); if (menu_current_level < MENU_STACK_DEPTH_MAX-1) menu_current_level++; menu_stack[menu_current_level] = submenu; ensure_selection(); - erase_menu_buttons(); if (menu_is_form(submenu)) { redraw_frame(); area_width = 0; @@ -1264,6 +1268,7 @@ draw_keypad(void) ili9341_set_background(bg); int x = KP_GET_X(keypads[i].x); int y = KP_GET_Y(keypads[i].y); +// ili9341_fill(x, y, KP_WIDTH, KP_HEIGHT, DEFAULT_MENU_TEXT_COLOR); // black area around button, causes flicker.... ili9341_fill(x+2, y+2, KP_WIDTH-4, KP_HEIGHT-4, bg); ili9341_drawfont(keypads[i].c, x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2, @@ -1414,30 +1419,55 @@ static void draw_menu_buttons(const menuitem_t *menu) { int i = 0; + char text[30]; for (i = 0; i < 7; i++) { const char *l1, *l2; - if (menu[i].type == MT_NONE) + if (MT_MASK(menu[i].type) == MT_NONE) break; - if (menu[i].type == MT_BLANK) + if (MT_MASK(menu[i].type) == MT_BLANK) continue; int y = MENU_BUTTON_HEIGHT*i; - uint16_t bg = config.menu_normal_color; - uint16_t fg = DEFAULT_MENU_TEXT_COLOR; + uint16_t bg; + uint16_t fg; + if (MT_MASK(menu[i].type) == MT_TITLE) { + fg = config.menu_normal_color; + bg = DEFAULT_MENU_TEXT_COLOR; + } else { + bg = config.menu_normal_color; + fg = DEFAULT_MENU_TEXT_COLOR; + } // focus only in MENU mode but not in KEYPAD mode if (ui_mode == UI_MENU && i == selection) bg = config.menu_active_color; - ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); - - menu_item_modify_attribute(menu, i, &fg, &bg); + + uint16_t old_bg = bg; + int active_button_width; + menu_item_modify_attribute(menu, i, &fg, &bg); // before plot_printf to create status text + if (menu[i].type & MT_FORM) { + active_button_width = MENU_FORM_WIDTH; + if (MT_MASK(menu[i].type) == MT_CALLBACK) { // Only callback can have value + keypad_mode = menu[i].data; + fetch_numeric_target(); + } + plot_printf(text, sizeof text, menu[i].label, uistat.text); + } + else + active_button_width = MENU_BUTTON_WIDTH; + ili9341_fill(320-active_button_width, y, active_button_width, MENU_BUTTON_HEIGHT-2, old_bg); // Set button to unmodified background color ili9341_set_foreground(fg); ili9341_set_background(bg); + if (menu[i].type & MT_FORM) { + ili9341_fill(320-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); + ili9341_drawstring_size(text, 320-active_button_width+5, y+10, 2); + } else { if (menu_is_multiline(menu[i].label, &l1, &l2)) { - ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+5, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(l1, 320-MENU_BUTTON_WIDTH+5, y+7); - ili9341_drawstring(l2, 320-MENU_BUTTON_WIDTH+5, y+7+FONT_GET_HEIGHT+1); + ili9341_fill(320-active_button_width+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(l1, 320-active_button_width+5, y+7); + ili9341_drawstring(l2, 320-active_button_width+5, y+7+FONT_GET_HEIGHT+1); } else { - ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+8, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(menu[i].label, 320-MENU_BUTTON_WIDTH+5, y+10); + ili9341_fill(320-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(menu[i].label, 320-active_button_width+5, y+10); + } } } } @@ -1461,12 +1491,18 @@ menu_apply_touch(void) touch_position(&touch_x, &touch_y); for (i = 0; i < 7; i++) { - if (menu[i].type == MT_NONE) + if (MT_MASK(menu[i].type) == MT_NONE) break; - if (menu[i].type == MT_BLANK) + if (MT_MASK(menu[i].type == MT_BLANK) || MT_MASK(menu[i].type) == MT_TITLE) continue; int y = MENU_BUTTON_HEIGHT*i; - if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && 320-MENU_BUTTON_WIDTH < touch_x) { + int active_button_width; + if (menu[i].type & MT_FORM) + active_button_width = MENU_FORM_WIDTH; + else + active_button_width = MENU_BUTTON_WIDTH; + + if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && 320-active_button_width < touch_x) { menu_select_touch(i); return; } @@ -1486,7 +1522,8 @@ draw_menu(void) static void erase_menu_buttons(void) { - ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*7, DEFAULT_BG_COLOR); + ili9341_fill(area_width, 0, 320 - area_width, area_height, DEFAULT_BG_COLOR); +// ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*7, DEFAULT_BG_COLOR); } static void @@ -1649,7 +1686,8 @@ ui_mode_keypad(int _keypad_mode) ui_mode = UI_KEYPAD; area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; area_height = HEIGHT - 32; - draw_menu(); + if (!menu_is_form(menu_stack[menu_current_level])) + draw_menu(); draw_keypad(); draw_numeric_area_frame(); draw_numeric_input(""); diff --git a/ui_sa.c b/ui_sa.c index a009015..db92473 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -41,11 +41,14 @@ extern int settingAGC; // extern int settingSpeed; extern int settingStepDelay; + + enum { - KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE + KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE }; + #define KP_X(x) (48*(x) + 2 + (320-BUTTON_WIDTH-192)) #define KP_Y(y) (48*(y) + 2) @@ -166,27 +169,28 @@ int generator_enabled = false; extern const menuitem_t menu_lowoutputmode[]; extern const menuitem_t menu_highoutputmode[]; +extern const menuitem_t menu_top[]; static void menu_mode_cb(int item, uint8_t data) { (void)data; + SetMode(item-1); + draw_cal_status(); switch (item) { - case 4: // Change reference output, should not happen!!! - break; - default: - SetMode(item); - draw_cal_status(); - if (item == 2) { // Activate menu_lowoutputmode as input form - set_sweep_frequency(ST_SPAN, 0); - menu_push_submenu(menu_lowoutputmode); - } else if (item == 3) { // Activate menu_highoutputmode as input form - set_sweep_frequency(ST_SPAN, 0); - menu_push_submenu(menu_highoutputmode); - } else - ui_mode_normal(); // Exit menu after setting the mode + case 1: + menu_push_submenu(menu_top); + break; + case 2: + menu_push_submenu(menu_top); + break; + case 3: + menu_push_submenu(menu_lowoutputmode); + break; + case 4: + menu_push_submenu(menu_highoutputmode); break; } - + draw_cal_status(); } extern int dirty; @@ -260,24 +264,25 @@ static void menu_dfu_cb(int item, uint8_t data) } } -int menu_refer_value[]={-1,0,1,2,3,4,5,6}; -static void menu_refer_cb(int item, uint8_t data) +int menu_reffer_value[]={-1,0,1,2,3,4,5,6}; +char *menu_reffer_text[]={"OFF","30MHz","15MHz","10MHz","4MHz","3MHz","2MHz","1MHz"}; +static void menu_reffer_cb(int item, uint8_t data) { (void)data; //Serial.println(item); - set_refer_output(menu_refer_value[item]); + set_refer_output(menu_reffer_value[item]); menu_move_back(); - ui_mode_normal(); +// ui_mode_normal(); // Stay in menu mode draw_cal_status(); } -static void menu_refer_cb2(int item, uint8_t data) +static void menu_reffer_cb2(int item, uint8_t data) { (void)data; //Serial.println(item); - set_refer_output(menu_refer_value[item+5]); + set_refer_output(menu_reffer_value[item+5]); menu_move_back(); - ui_mode_normal(); + // ui_mode_normal(); // Stay in menu mode draw_cal_status(); } @@ -560,16 +565,18 @@ static const menuvalue_t menu_value[] = { // ===[MENU DEFINITION]========================================================= const menuitem_t menu_lowoutputmode[] = { - { MT_CALLBACK, KM_CENTER, "FREQUENCY", menu_lowoutputmode_cb}, - { MT_CALLBACK, KM_ATTENUATION,"LEVEL", menu_lowoutputmode_cb}, - { MT_CANCEL, 0, S_LARROW" BACK",NULL }, + { MT_FORM | MT_TITLE, 0, "LOW OUTPUT", NULL}, + { MT_FORM | MT_CALLBACK, KM_CENTER, "FREQ: %s", menu_lowoutputmode_cb}, + { MT_FORM | MT_CALLBACK, KM_ATTENUATION,"LEVEL: %s", menu_lowoutputmode_cb}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK",NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; const menuitem_t menu_highoutputmode[] = { - { MT_CALLBACK, KM_CENTER, "FREQUENCY", menu_highoutputmode_cb}, - { MT_CALLBACK, KM_DRIVE, "LEVEL", menu_highoutputmode_cb}, - { MT_CANCEL, 0, S_LARROW" BACK",NULL }, + { MT_FORM | MT_TITLE, 0, "HIGH OUTPUT", NULL}, + { MT_FORM | MT_CALLBACK, KM_CENTER, "FREQ: %s", menu_highoutputmode_cb}, + { MT_FORM | MT_CALLBACK, KM_DRIVE, "LEVEL", menu_highoutputmode_cb}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK",NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -615,22 +622,22 @@ static const menuitem_t menu_dBper[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_refer2[] = { - { MT_CALLBACK, 0, "3MHz" , menu_refer_cb2}, - { MT_CALLBACK, 0, "2MHz" , menu_refer_cb2}, - { MT_CALLBACK, 0, "1MHz" , menu_refer_cb2}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, +static const menuitem_t menu_reffer2[] = { + { MT_FORM | MT_CALLBACK, 0, "3MHz" , menu_reffer_cb2}, + { MT_FORM | MT_CALLBACK, 0, "2MHz" , menu_reffer_cb2}, + { MT_FORM | MT_CALLBACK, 0, "1MHz" , menu_reffer_cb2}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_refer[] = { - { MT_CALLBACK, 0, "OFF" , menu_refer_cb}, - { MT_CALLBACK, 0, "30MHz", menu_refer_cb}, - { MT_CALLBACK, 0, "15MHz", menu_refer_cb}, - { MT_CALLBACK, 0, "10MHz", menu_refer_cb}, - { MT_CALLBACK, 0, "4MHz" , menu_refer_cb}, - { MT_SUBMENU, 0, S_RARROW" MORE", menu_refer2}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, +static const menuitem_t menu_reffer[] = { + { MT_FORM | MT_CALLBACK, 0, "OFF" , menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "30MHz", menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "15MHz", menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "10MHz", menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "4MHz" , menu_reffer_cb}, + { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_reffer2}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -693,16 +700,6 @@ static const menuitem_t menu_dfu[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_mode[] = { - { MT_CALLBACK, 0, "\2LOW\0INPUT", menu_mode_cb}, - { MT_CALLBACK, 0, "\2HIGH\0INPUT",menu_mode_cb}, - { MT_CALLBACK, 0, "\2LOW\0OUTPUT", menu_mode_cb}, - { MT_CALLBACK, 0, "\2HIGH\0OUTPUT",menu_mode_cb}, - { MT_SUBMENU, 0, "\2REFER\0OUTPUT",menu_refer}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - static const menuitem_t menu_settings2[] = { // { MT_CALLBACK, 0, "TRACK", menu_settings2_cb}, @@ -738,14 +735,25 @@ static const menuitem_t menu_config[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_top[] = { - { MT_CALLBACK, 0, "AUTO", menu_autosettings_cb}, - { MT_SUBMENU, 0, "SCAN", menu_stimulus}, - { MT_SUBMENU, 0, "MARKER", menu_marker}, - { MT_SUBMENU, 0, "DISPLAY", menu_scale}, - { MT_SUBMENU, 0, "STORAGE", menu_storage}, - { MT_SUBMENU, 0, "MODE", menu_mode}, - { MT_SUBMENU, 0, "CONFIG", menu_config}, +static const menuitem_t menu_mode[] = { + { MT_FORM | MT_TITLE, 0, "MODE", NULL}, + { MT_FORM | MT_CALLBACK, 0, "LOW INPUT", menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "HIGH INPUT",menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "LOW OUTPUT", menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "HIGH OUTPUT",menu_mode_cb}, + { MT_FORM | MT_SUBMENU, 0, "CAL OUTPUT: %s",menu_reffer}, +// { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + +const menuitem_t menu_top[] = { + { MT_CALLBACK, 0, "AUTO", menu_autosettings_cb}, + { MT_SUBMENU, 0, "SCAN", menu_stimulus}, + { MT_SUBMENU, 0, "MARKER", menu_marker}, + { MT_SUBMENU, 0, "DISPLAY", menu_scale}, + { MT_SUBMENU, 0, "STORAGE", menu_storage}, + { MT_SUBMENU, 0, "CONFIG", menu_config}, + { MT_CANCEL, 0, S_LARROW" MODE",NULL}, { MT_NONE, 0, NULL, NULL } // sentinel, // MENUITEM_CLOSE, }; @@ -761,24 +769,29 @@ void frequency_string(char *buf, size_t len, int32_t freq); int menu_is_form(const menuitem_t *menu) { - return(menu == menu_lowoutputmode || - menu == menu_highoutputmode); + int i; + for (i = 0; MT_MASK(menu[i].type) != MT_NONE; i++) + if (menu[i].type & MT_FORM) + return (true); + return(false); } static void menu_item_modify_attribute( const menuitem_t *menu, int item, uint16_t *fg, uint16_t *bg) { if (menu == menu_mode) { - if (item == GetMode()){ + if (item == GetMode()+1) { *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; + } else if (item == 5) { + plot_printf(uistat.text, sizeof uistat.text, menu_reffer_text[get_refer_output()+1]); } - } else if (menu == menu_refer) { + } else if (menu == menu_reffer) { if (item < 5 && item == get_refer_output() + 1){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - } else if (menu == menu_refer2) { + } else if (menu == menu_reffer2) { if (item == get_refer_output() - 4){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; @@ -837,44 +850,46 @@ static void menu_item_modify_attribute( } } if (ui_mode == UI_MENU && menu_is_form(menu)) { -// if (item == 0) -// redraw_frame(); + // if (item == 0) + // redraw_frame(); if (item <= 1) { - area_width = 0; -// area_height = HEIGHT - 32; - int y = MENU_BUTTON_HEIGHT*item; - uint16_t bg = config.menu_normal_color; - uint16_t fg = DEFAULT_MENU_TEXT_COLOR; - // ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); - ili9341_set_foreground(fg); - ili9341_set_background(bg); - char buf[15]; - ili9341_fill(50+25, y, 170, MENU_BUTTON_HEIGHT-2, bg); - if (menu == menu_lowoutputmode) { - switch (item) { - case 0: - set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode - plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); - break; - case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); - break; - } - } - if (menu == menu_highoutputmode) { - switch (item) { - case 0: - set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode - frequency_string(buf, sizeof buf, frequency0); - break; - case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingDrive); - break; - } + area_width = 0; +#if 0 + // area_height = HEIGHT - 32; + int y = MENU_BUTTON_HEIGHT*item; + uint16_t bg = config.menu_normal_color; + uint16_t fg = DEFAULT_MENU_TEXT_COLOR; + // ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); + ili9341_set_foreground(fg); + ili9341_set_background(bg); + char buf[15]; + ili9341_fill(50+25, y, 170, MENU_BUTTON_HEIGHT-2, bg); + if (menu == menu_lowoutputmode) { + switch (item) { + case 0: + set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode + plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); + break; + case 1: + plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); + break; + } + } + if (menu == menu_highoutputmode) { + switch (item) { + case 0: + set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode + plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); + break; + case 1: + plot_printf(buf, sizeof buf, "%ddB", -10 - settingDrive); + break; + } + } + ili9341_drawstring_size(buf, 130, y+6, 2); +#endif } - ili9341_drawstring_size(buf, 130, y+6, 2); - } }else{ area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; } @@ -885,39 +900,53 @@ static void fetch_numeric_target(void) switch (keypad_mode) { case KM_START: uistat.value = get_sweep_frequency(ST_START); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_STOP: uistat.value = get_sweep_frequency(ST_STOP); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_CENTER: uistat.value = get_sweep_frequency(ST_CENTER); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SPAN: uistat.value = get_sweep_frequency(ST_SPAN); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_CW: uistat.value = get_sweep_frequency(ST_CW); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SCALE: uistat.value = get_trace_scale(uistat.current_trace) * 1000; + plot_printf(uistat.text, sizeof uistat.text, "%ddB/", uistat.value / 1000); break; case KM_REFPOS: uistat.value = get_trace_refpos(uistat.current_trace) * 1000; + plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value / 1000); break; case KM_ATTENUATION: uistat.value = settingAttenuate; + if (GetMode() == M_GENLOW) + uistat.value += 10; // compensation for dB offset during low output mode + plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_ACTUALPOWER: uistat.value = settingLevelOffset(); + plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_IF: uistat.value = frequency_IF; + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SAMPLETIME: uistat.value = settingStepDelay; + plot_printf(uistat.text, sizeof uistat.text, "%3duS", uistat.value); break; case KM_DRIVE: uistat.value = settingDrive; + plot_printf(uistat.text, sizeof uistat.text, "%3ddB", uistat.value); break; } @@ -962,6 +991,8 @@ set_numeric_value(void) set_trace_refpos(2, NGRIDY - uistat.value / get_trace_scale(0)); break; case KM_ATTENUATION: + if (GetMode() == M_GENLOW) + uistat.value -= 10; // compensation for dB offset during low output mode SetAttenuation(uistat.value); break; case KM_ACTUALPOWER: