diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index c2188e1..62b33d2 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/main.c b/main.c index 3c7d3df..9f8f42b 100644 --- a/main.c +++ b/main.c @@ -1180,35 +1180,36 @@ VNA_SHELL_FUNCTION(cmd_scan) static void update_marker_index(void) { - int m; - int i; + int m, idx; + freq_t fstart = get_sweep_frequency(ST_START); + freq_t fstop = get_sweep_frequency(ST_STOP); for (m = 0; m < MARKERS_MAX; m++) { if (!markers[m].enabled) continue; freq_t f = markers[m].frequency; - freq_t fstart = get_sweep_frequency(ST_START); - freq_t fstop = get_sweep_frequency(ST_STOP); - if (f < fstart) { - markers[m].index = 0; - markers[m].frequency = fstart; - } else if (f >= fstop) { - markers[m].index = sweep_points-1; - markers[m].frequency = fstop; - } else { - for (i = 0; i < sweep_points-1; i++) { - if (frequencies[i] <= f && f < frequencies[i+1]) { - markers[m].index = f < (frequencies[i] / 2 + frequencies[i + 1] / 2) ? i : i + 1; - markers[m].frequency = frequencies[markers[m].index ]; - break; - } - } + if (f == 0) idx = markers[m].index; // Not need update index in no freq + else if (f < fstart) idx = 0; + else if (f >= fstop) idx = sweep_points-1; + else { // Search frequency index for marker frequency +#if 1 + for (idx = 1; idx < sweep_points; idx++) { + if (frequencies[idx] <= f) continue; + if (f < (frequencies[idx-1]/2 + frequencies[idx]/2)) idx--; // Correct closest idx + break; + } +#else + float r = ((float)(f - fstart))/(fstop - fstart); + idx = r * (sweep_points-1); +#endif } + markers[m].index = idx; + markers[m].frequency = frequencies[idx]; } } void set_marker_frequency(int m, freq_t f) { - if (m < 0 || !markers[m].enabled) + if (m == MARKER_INVALID || !markers[m].enabled) return; int i = 1; markers[m].mtype &= ~M_TRACKING; diff --git a/nanovna.h b/nanovna.h index ba5c8d8..b023015 100644 --- a/nanovna.h +++ b/nanovna.h @@ -896,13 +896,8 @@ typedef struct setting int decay; // KM_DECAY < 1000000 int attack; // KM_ATTACK < 20000 -#ifdef TINYSA4 - int32_t slider_position; - int64_t slider_span; -#else - int32_t slider_position; - int32_t slider_span; -#endif + freq_t slider_span; + int16_t slider_position; uint32_t rbw_x10; uint32_t vbw_x10; diff --git a/ui.c b/ui.c index 629d7d2..7214681 100644 --- a/ui.c +++ b/ui.c @@ -152,8 +152,7 @@ static void leave_ui_mode(void); static void erase_menu_buttons(void); static void ui_process_keypad(void); static void choose_active_marker(void); -static void menu_move_back(void); -static void menu_move_back_and_leave_ui(void); +static void menu_move_back(bool leave_ui); static void menu_push_submenu(const menuitem_t *submenu); //static const menuitem_t menu_marker_type[]; @@ -501,7 +500,6 @@ show_version(void) do {shift>>=1; y+=5;} while (shift&1); ili9341_drawstring(info_about[i++], x, y+=5); } - char buf[96]; #ifdef TINYSA4 extern const char *states[]; #define ENABLE_THREADS_COMMAND @@ -519,6 +517,7 @@ extern const char *states[]; #else uint32_t stklimit = 0U; #endif + char buf[96]; plot_printf(buf, sizeof(buf), "%08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s", stklimit, (uint32_t)tp->ctx.sp, max_stack_use, (uint32_t)tp, (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], @@ -541,6 +540,7 @@ extern const char *states[]; #ifdef __USE_RTC__ uint32_t tr = rtc_get_tr_bin(); // TR read first uint32_t dr = rtc_get_dr_bin(); // DR read second + char buf[96]; plot_printf(buf, sizeof(buf), "Time: 20%02d/%02d/%02d %02d:%02d:%02d" " (LS%c)", RTC_DR_YEAR(dr), RTC_DR_MONTH(dr), @@ -628,7 +628,7 @@ menu_caldone_cb(int item, uint8_t data) (void)data; cal_done(); draw_cal_status(); - menu_move_back(); + menu_move_back(false); menu_push_submenu(menu_save); } @@ -647,7 +647,7 @@ menu_cal2_cb(int item, uint8_t data) } draw_menu(); draw_cal_status(); - //menu_move_back(); + //menu_move_back(false); } static void @@ -655,7 +655,7 @@ menu_recall_cb(int item, uint8_t data) { (void)item; caldata_recall(data); - menu_move_back(); + menu_move_back(false); ui_mode_normal(); update_grid(); draw_cal_status(); @@ -687,7 +687,7 @@ menu_config_save_cb(int item, uint8_t data) (void)item; (void)data; config_save(); - menu_move_back(); + menu_move_back(false); ui_mode_normal(); } @@ -704,7 +704,7 @@ menu_save_cb(int item, uint8_t data) { (void)item; if (caldata_save(data) == 0) { - menu_move_back(); + menu_move_back(false); ui_mode_normal(); draw_cal_status(); } @@ -760,7 +760,7 @@ menu_channel_cb(int item, uint8_t data) { (void)item; set_trace_channel(uistat.current_trace, data); - menu_move_back(); + menu_move_back(false); ui_mode_normal(); } @@ -863,7 +863,7 @@ menu_stimulus_cb(int item, uint8_t data) break; case 5: /* PAUSE */ toggle_sweep(); - //menu_move_back(); + //menu_move_back(false); //ui_mode_normal(); draw_menu(); break; @@ -938,7 +938,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb) break; #endif } - menu_move_back_and_leave_ui(); + menu_move_back(true); redraw_request |= REDRAW_CAL_STATUS; //redraw_all(); } @@ -1306,7 +1306,7 @@ ensure_selection(void) } static void -menu_move_back(void) +menu_move_back(bool leave_ui) { if (menu_current_level == 0) return; @@ -1316,26 +1316,11 @@ menu_move_back(void) selection = 0; ensure_selection(); - if (current_menu_is_form()) { - redraw_frame(); - area_width = 0; - } else { -// redraw_frame(); - redraw_request |= REDRAW_AREA | REDRAW_FREQUENCY | REDRAW_CAL_STATUS | REDRAW_BATTERY; - area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; - } -} - -static void -menu_move_back_and_leave_ui(void) -{ - if (menu_current_level == 0) + if (leave_ui){ + ui_mode_normal(); return; - menu_current_level--; - if (selection >= 0) - selection = 0; - ensure_selection(); - ui_mode_normal(); + } + ui_mode_menu(); } static void @@ -1345,21 +1330,7 @@ menu_push_submenu(const menuitem_t *submenu) if (menu_current_level < MENU_STACK_DEPTH_MAX-1) menu_current_level++; menu_stack[menu_current_level] = submenu; - if (selection >= 0) - selection = 0; - ensure_selection(); - if (menu_is_form(submenu)) { - redraw_frame(); - area_width = 0; - } else { -// redraw_frame(); -// request_to_redraw_grid(); - area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; - } - if (ui_mode != UI_MENU){ - draw_menu(); // Draw menu only on enter menu mode - ui_mode = UI_MENU; // Only needed for auto mode setting - } + ui_mode_menu(); } void @@ -1405,7 +1376,7 @@ menu_invoke(int item) break; case MT_CANCEL: - menu_move_back(); + menu_move_back(false); break; case MT_CALLBACK: { @@ -1431,7 +1402,6 @@ menu_invoke(int item) case MT_KEYPAD: uistat.auto_center_marker = false; if (menu->type & MT_FORM) { - area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; redraw_frame(); // Remove form numbers } kp_help_text = (char *)menu->reference; @@ -1937,12 +1907,6 @@ draw_menu_buttons(const menuitem_t *menu) goto draw_slider; } } -#if 0 - if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK && menu[i].reference == menu_sdrive_acb) { - local_slider_positions = ((menu_drive_value[setting.lo_drive] + 38 ) * (MENU_FORM_WIDTH-8)) / 51 + OFFSETX+4; - goto draw_slider; - } -#endif // ili9341_drawstring_size(button.text, text_offs, y+(button_height-2*FONT_GET_HEIGHT)/2-local_text_shift, 2); ili9341_drawstring_10x14(button.text, text_offs, y+(button_height-wFONT_GET_HEIGHT)/2-local_text_shift); } else { @@ -1989,7 +1953,7 @@ void set_keypad_value(int v) void check_frequency_slider(freq_t slider_freq) { - if ( (maxFreq - minFreq) < setting.slider_span ) { + if ( (maxFreq - minFreq) < (freq_t)setting.slider_span) { setting.slider_span = maxFreq - minFreq; // absolute mode with max step size } freq_t half_span = setting.slider_span >> 1; @@ -2124,6 +2088,7 @@ menu_select_touch(int i, int pos) if (dt > BUTTON_DOWN_LONG_TICKS || do_exit) { selection = -1; draw_menu(); +// redraw_request = 0; // reset all (not need update after) return; } if (menu_is_form(menu) && MT_MASK(menu[i].type) == MT_KEYPAD && keypad == KM_LOWOUTLEVEL) { @@ -2353,15 +2318,20 @@ set_numeric_value(void) void ui_mode_menu(void) { - if (ui_mode == UI_MENU) - return; - +// if (ui_mode == UI_MENU) +// return; ui_mode = UI_MENU; - /* narrowen plotting area */ - area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; - area_height = AREA_HEIGHT_NORMAL; ensure_selection(); + if (current_menu_is_form()) { + redraw_frame(); + area_width = 0; + area_height = 0; + } else { + area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; + area_height = AREA_HEIGHT_NORMAL; + } draw_menu(); + redraw_request|=REDRAW_BATTERY|REDRAW_CAL_STATUS; } static void @@ -2373,19 +2343,12 @@ ui_mode_keypad(int _keypad_mode) // keypads array keypad_mode = _keypad_mode; keypads = keypads_mode_tbl[_keypad_mode].keypad_type; - int i; - for (i = 0; keypads[i+1].c >= 0; i++) - ; - keypads_last_index = i; ui_mode = UI_KEYPAD; - area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; - area_height = HEIGHT - NUM_INPUT_HEIGHT; if (!current_menu_is_form()) draw_menu(); draw_keypad(); draw_numeric_area_frame(); - draw_numeric_input(""); } void @@ -2404,26 +2367,24 @@ lever_move_marker(int status) { uint16_t step = 1<<2; do { - if (active_marker >= 0 && markers[active_marker].enabled) { + if (active_marker != MARKER_INVALID && markers[active_marker].enabled) { + int idx = (int)markers[active_marker].index; if (status & EVT_DOWN) { - markers[active_marker].index -= step>>2; - if (markers[active_marker].index < 0) - markers[active_marker].index = 0 ; + idx -= step>>2; + if (idx < 0) idx = 0 ; } if (status & EVT_UP) { - markers[active_marker].index += step>>2; - if (markers[active_marker].index > sweep_points-1) - markers[active_marker].index = sweep_points-1 ; + idx += step>>2; + if (idx > sweep_points-1) idx = sweep_points-1 ; } - markers[active_marker].frequency = frequencies[markers[active_marker].index]; + markers[active_marker].index = idx; + markers[active_marker].frequency = frequencies[idx]; redraw_marker(active_marker); markers[active_marker].mtype &= ~M_TRACKING; // Disable tracking when dragging marker step++; } status = btn_wait_release(); } while (status != 0); - if (active_marker != MARKER_INVALID) - redraw_marker(active_marker); } static void @@ -2726,6 +2687,9 @@ ui_process_keypad(void) { int status; kp_index = 0; + int keypads_last_index; + for (keypads_last_index = 0; keypads[keypads_last_index+1].c >= 0; keypads_last_index++) + ; while (TRUE) { status = btn_check(); if (status & (EVT_UP|EVT_DOWN)) { @@ -2761,7 +2725,7 @@ ui_process_keypad(void) ui_mode_menu(); //Reactivate menu after keypad selection = -1; ensure_selection(); - redraw_request = REDRAW_BATTERY; // Only redraw battery +// redraw_request|= REDRAW_BATTERY; // Only redraw battery } else { ui_mode_normal(); // request_to_redraw_grid(); diff --git a/ui_sa.c b/ui_sa.c index b2b7bf9..bd1c2c7 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -254,8 +254,6 @@ typedef struct { static const keypads_t *keypads; -static uint8_t keypads_last_index; - // 7 8 9 G // 4 5 6 M // 1 2 3 k @@ -544,12 +542,12 @@ static UI_FUNCTION_ADV_CALLBACK(menu_mode_acb) case 0: // if (setting.mode != M_LOW) // set_mode(M_LOW); - menu_move_back_and_leave_ui(); + menu_move_back(true); break; case 1: // if (setting.mode != M_HIGH) // set_mode(M_HIGH); - menu_move_back_and_leave_ui(); + menu_move_back(true); break; case 2: menu_push_submenu(menu_lowoutputmode); @@ -572,7 +570,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_load_preset_acb) if (data == 0) reset_settings(setting.mode); // Restore factory defaults } - menu_move_back_and_leave_ui(); + menu_move_back(true); } static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb) @@ -589,7 +587,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb) data = 0; } caldata_save(data); - menu_move_back_and_leave_ui(); + menu_move_back(true); } @@ -612,7 +610,7 @@ UI_FUNCTION_CALLBACK(menu_autosettings_cb) // SetPowerLevel(100); // Reset set_clear_storage(); dirty = true; - // menu_move_back(); // stay in input menu + // menu_move_back(true); // stay in input menu ui_mode_normal(); // draw_cal_status(); } @@ -623,7 +621,7 @@ static UI_FUNCTION_CALLBACK(menu_calibrate_cb) switch (item) { case 1: sweep_mode = SWEEP_CALIBRATE; - menu_move_back_and_leave_ui(); + menu_move_back(true); break; case 2: reset_calibration(); @@ -639,7 +637,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_scanning_speed_acb) return; } set_step_delay(data); -// menu_move_back(); +// menu_move_back(false); ui_mode_normal(); } @@ -659,7 +657,7 @@ static UI_FUNCTION_CALLBACK(menu_config_cb) break; case CONFIG_MENUITEM_SELFTEST: sweep_mode = 0; // Suspend sweep to save time - menu_move_back_and_leave_ui(); + menu_move_back(true); setting.test = 0; setting.test_argument = 0; sweep_mode = SWEEP_SELFTEST; @@ -697,7 +695,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_modulation_acb) set_level_sweep(0); } set_modulation(data); - menu_move_back(); + menu_move_back(false); // ui_mode_normal(); // Stay in menu mode // draw_cal_status(); } @@ -729,7 +727,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_reffer_acb) } //Serial.println(item); set_refer_output((int)data - 1); - menu_move_back(); + menu_move_back(false); // ui_mode_normal(); // Stay in menu mode // draw_cal_status(); } @@ -755,7 +753,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_lo_drive_acb) } //Serial.println(item); set_lo_drive(data); - menu_move_back(); + menu_move_back(false); // ui_mode_normal(); // draw_cal_status(); } @@ -770,7 +768,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_mixer_drive_acb) } //Serial.println(item); set_lo_drive(data); - menu_move_back(); + menu_move_back(false); // ui_mode_normal(); // draw_cal_status(); } @@ -815,7 +813,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb) toggle_spur(); } else toggle_mirror_masking(); - // menu_move_back(); + // menu_move_back(false); ui_mode_normal(); } #endif @@ -830,7 +828,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_extra_lna_acb) return; } toggle_extra_lna(); - // menu_move_back(); + // menu_move_back(false); ui_mode_normal(); } @@ -843,7 +841,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_adf_out_acb) return; } toggle_high_out_adf4350(); - // menu_move_back(); + // menu_move_back(false); ui_mode_normal(); } @@ -869,7 +867,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) b->icon = data == setting.measurement ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; return; } - menu_move_back(); + menu_move_back(false); #ifdef __MEASURE__ switch(data) { case M_OFF: // Off @@ -1043,7 +1041,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_atten_acb) return; } set_auto_attenuation(); - menu_move_back_and_leave_ui(); + menu_move_back(true); } static UI_FUNCTION_ADV_CALLBACK(menu_atten_high_acb) @@ -1055,7 +1053,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_atten_high_acb) } setting.auto_attenuation = false; set_attenuation(data); - menu_move_back_and_leave_ui(); + menu_move_back(true); } static UI_FUNCTION_ADV_CALLBACK(menu_reflevel_acb) @@ -1067,7 +1065,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_reflevel_acb) return; } set_auto_reflevel(true); - menu_move_back_and_leave_ui(); + menu_move_back(true); } static UI_FUNCTION_ADV_CALLBACK(menu_storage_acb) @@ -1128,7 +1126,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_average_acb) return; } set_average(data); - menu_move_back_and_leave_ui(); + menu_move_back(true); } extern const menuitem_t menu_marker_modify[]; @@ -1184,7 +1182,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_marker_modify_acb) } markmap_all_markers(); // redraw_marker(active_marker, TRUE); -// menu_move_back(); +// menu_move_back(false); } static UI_FUNCTION_CALLBACK(menu_marker_delete_cb) @@ -1194,7 +1192,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_delete_cb) if (active_marker>=0){ markers[active_marker].enabled = false; markmap_all_markers(); - menu_move_back(); + menu_move_back(false); } } @@ -1218,7 +1216,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_rbw_acb) return; } set_RBW(rbwsel_x10[data]); - menu_move_back_and_leave_ui(); + menu_move_back(true); } static UI_FUNCTION_ADV_CALLBACK(menu_unit_acb) @@ -1229,7 +1227,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_unit_acb) return; } set_unit(data); - menu_move_back_and_leave_ui(); + menu_move_back(true); } #if 0 @@ -1245,7 +1243,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_scale_per_acb) return; } set_scale(menu_scale_per_value[data]); - menu_move_back_and_leave_ui(); + menu_move_back(true); } #endif @@ -1270,7 +1268,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_trigger_acb) set_trigger(setting.trigger_mode); } else if (data != T_DONE) { set_trigger(data); -// menu_move_back(); +// menu_move_back(false); ui_mode_normal(); } completed = true; @@ -1413,8 +1411,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_pause_acb) return; } toggle_sweep(); -// menu_move_back(); -// ui_mode_normal(); +// menu_move_back(true); // draw_cal_status(); } @@ -1428,8 +1425,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_send_display_acb) return; } auto_capture = ! auto_capture; -// menu_move_back(); -// ui_mode_normal(); +// menu_move_back(true); // draw_cal_status(); } #endif @@ -2481,7 +2477,7 @@ void menu_move_top(void) { while (menu_current_level > 0) - menu_move_back(); + menu_move_back(false); }