From ec3cc7a8595b516d14251a014a9cd86bf7a3616d Mon Sep 17 00:00:00 2001 From: gullradriel <3157857+gullradriel@users.noreply.github.com> Date: Sat, 10 Jun 2023 17:17:02 +0200 Subject: [PATCH] Looking spectrum tune (#1143) * finely tuned spectrum and marker precision, all modes * hidding buttons when mode is not supported * removing on show hide since widget implementation is buggy. Fine tuned values using signal generator to get around the corners --------- Co-authored-by: GullCode --- .../application/apps/ui_looking_glass_app.cpp | 41 +++++++++---------- .../application/apps/ui_looking_glass_app.hpp | 2 + 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/firmware/application/apps/ui_looking_glass_app.cpp b/firmware/application/apps/ui_looking_glass_app.cpp index d047cb623..5d99c2cc8 100644 --- a/firmware/application/apps/ui_looking_glass_app.cpp +++ b/firmware/application/apps/ui_looking_glass_app.cpp @@ -38,7 +38,7 @@ GlassView::~GlassView() { void GlassView::get_max_power(const ChannelSpectrum& spectrum, uint8_t bin, uint8_t& max_power) { if (mode == LOOKING_GLASS_SINGLEPASS) { - // analog audio app like view + // <20MHz spectrum mode if (bin < 120) { if (spectrum.db[SPEC_NB_BINS - 120 + bin] > max_power) max_power = spectrum.db[SPEC_NB_BINS - 120 + bin]; @@ -47,15 +47,13 @@ void GlassView::get_max_power(const ChannelSpectrum& spectrum, uint8_t bin, uint max_power = spectrum.db[bin - 120]; } } else { - // view is made in multiple pass, use original bin picking - // FAST mode: center 12 bins are ignored in fast mode , (DC spike is blanked) leftmost and rightmost 2 bins are ignored - // SLOW mode: leftmost 'offset' bins are ignored + // FAST or SLOW mode if (bin < 120) { - if (spectrum.db[SPEC_NB_BINS - offset - 120 + bin] > max_power) - max_power = spectrum.db[SPEC_NB_BINS - offset - 120 + bin]; + if (spectrum.db[134 + bin] > max_power) + max_power = spectrum.db[134 + bin]; } else { - if (spectrum.db[offset + bin - 120] > max_power) - max_power = spectrum.db[offset + bin - 120]; + if (spectrum.db[bin - 118] > max_power) + max_power = spectrum.db[bin - 118]; } } } @@ -66,7 +64,7 @@ rf::Frequency GlassView::get_freq_from_bin_pos(uint8_t pos) { // starting from the middle, minus 8 ignored bin on each side. Since pos is [-120,120] after the (pos - 120), it's divided by SCREEN_W(240)/2 => 120 freq_at_pos = f_center_ini + ((pos - 120) * ((looking_glass_range - ((16 * looking_glass_range) / SPEC_NB_BINS)) / 2)) / (SCREEN_W / 2); } else - freq_at_pos = f_min + (pos * looking_glass_range) / SCREEN_W; + freq_at_pos = f_min + (2 * offset * each_bin_size) + (pos * looking_glass_range) / SCREEN_W; return freq_at_pos; } @@ -150,7 +148,7 @@ void GlassView::add_spectrum_pixel(uint8_t power) { } bool GlassView::process_bins(uint8_t* powerlevel) { - bins_Hz_size += each_bin_size; // add the ignored DC spike to "pixel fulfilled bag of Hz" + bins_Hz_size += each_bin_size; // add pixel to fulfilled bag of Hz if (bins_Hz_size >= marker_pixel_step) // new pixel fullfilled { if (*powerlevel > min_color_power) @@ -223,29 +221,30 @@ void GlassView::on_range_changed() { if (looking_glass_range <= LOOKING_GLASS_SLICE_WIDTH_MAX) { // if the view is done in one pass, show it like in analog_audio_app mode = LOOKING_GLASS_SINGLEPASS; - offset = 0; + offset = 2; bin_length = SCREEN_W; ignore_dc = 0; looking_glass_bandwidth = looking_glass_range; looking_glass_sampling_rate = looking_glass_bandwidth; each_bin_size = looking_glass_bandwidth / SCREEN_W; looking_glass_step = looking_glass_bandwidth; - f_center_ini = f_min + (looking_glass_bandwidth / 2); // Initial center frequency for sweep + f_center_ini = f_min + (looking_glass_bandwidth / 2); // Initial center frequency for sweep + portapack::display.fill_rectangle({17 * 8, 4 * 16, 2 * 8, 16}, Color::black()); // Clear old marker and whole marker rectangle btw } else { // view is made in multiple pass, use original bin picking mode = scan_type.selected_index_value(); - if (mode == LOOKING_GLASS_FASTSCAN) { - offset = 8; - ignore_dc = SPEC_NB_BINS - SCREEN_W - offset; - bin_length = SCREEN_W; - } else { // if( mode == LOOKING_GLASS_SLOWSCAN ) - offset = 132; - bin_length = 80; - ignore_dc = 0; - } looking_glass_bandwidth = LOOKING_GLASS_SLICE_WIDTH_MAX; looking_glass_sampling_rate = LOOKING_GLASS_SLICE_WIDTH_MAX; each_bin_size = LOOKING_GLASS_SLICE_WIDTH_MAX / SPEC_NB_BINS; + if (mode == LOOKING_GLASS_FASTSCAN) { + offset = 2; + ignore_dc = 4; + bin_length = SCREEN_W; + } else { // if( mode == LOOKING_GLASS_SLOWSCAN ) + offset = 2; + bin_length = 80; + ignore_dc = 0; + } looking_glass_step = (bin_length + ignore_dc) * each_bin_size; f_center_ini = f_min - (offset * each_bin_size) + (looking_glass_bandwidth / 2); // Initial center frequency for sweep } diff --git a/firmware/application/apps/ui_looking_glass_app.hpp b/firmware/application/apps/ui_looking_glass_app.hpp index 3475c26bc..f56d8b15b 100644 --- a/firmware/application/apps/ui_looking_glass_app.hpp +++ b/firmware/application/apps/ui_looking_glass_app.hpp @@ -86,6 +86,8 @@ class GlassView : public View { bool process_bins(uint8_t* powerlevel); void on_channel_spectrum(const ChannelSpectrum& spectrum); void do_timers(); + int64_t next_mult_of(int64_t num, int64_t multiplier); + void adjust_range(int64_t* f_min, int64_t* f_max, int64_t width); void on_range_changed(); void on_lna_changed(int32_t v_db); void on_vga_changed(int32_t v_db);