Merge pull request #887 from gullradriel/looking-glass-fix

Peak view entry menu and functionnalities
This commit is contained in:
Brumi-2021 2023-04-10 23:10:19 +02:00 committed by GitHub
commit aa20bff2b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 183 additions and 87 deletions

View File

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2020 euquiq * Copyright (C) 2020 euquiq
* Copyright (C) 2023 gullradriel, Nilorea Studio Inc.
* *
* This file is part of PortaPack. * This file is part of PortaPack.
* *
@ -49,35 +50,66 @@ namespace ui
receiver_model.set_vga(v_db); receiver_model.set_vga(v_db);
} }
void GlassView::reset_live_view( bool clear_screen )
{
max_freq_hold = 0 ;
max_freq_power = -1000 ;
if( clear_screen )
{
// only clear screen in peak mode
if( live_frequency_view == 2 )
{
display.fill_rectangle( { { 0 , 108 + 16 } , { 240 , 320 - (108 + 16) } } , { 0 , 0 , 0 } );
}
}
}
void GlassView::add_spectrum_pixel(int16_t color) void GlassView::add_spectrum_pixel(int16_t color)
{ {
static uint64_t last_max_freq = 0 ;
spectrum_row[pixel_index] = spectrum_rgb3_lut[color] ; spectrum_row[pixel_index] = spectrum_rgb3_lut[color] ;
spectrum_data[pixel_index] = ( live_frequency_integrate * spectrum_data[pixel_index] + color ) / (live_frequency_integrate + 1); // smoothing spectrum_data[pixel_index] = ( live_frequency_integrate * spectrum_data[pixel_index] + color ) / (live_frequency_integrate + 1); // smoothing
pixel_index ++ ; pixel_index ++ ;
if (pixel_index == 240) // got an entire waterfall line if (pixel_index == 240) // got an entire waterfall line
{ {
if( live_frequency_view ) if( live_frequency_view > 0 )
{ {
constexpr int rssi_sample_range = 256; constexpr int rssi_sample_range = 256;
//constexpr float rssi_voltage_min = 0.4; constexpr float rssi_voltage_min = 0.4;
constexpr float rssi_voltage_max = 2.2; constexpr float rssi_voltage_max = 2.2;
constexpr float adc_voltage_max = 3.3; constexpr float adc_voltage_max = 3.3;
//constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max; constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
constexpr int raw_min = 0 ;
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max; constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
constexpr int raw_delta = raw_max - raw_min; constexpr int raw_delta = raw_max - raw_min;
const range_t<int> y_max_range { 0 , 320 - 108 }; const range_t<int> y_max_range { 0 , 320 - ( 108 + 16 ) };
//drawing //drawing and keeping track of max freq
//display.fill_rectangle( { { 0 , 108 } , { 240 , 320 - 108 } } , { 0 , 0 , 0 } );
for( uint16_t xpos = 0 ; xpos < 240 ; xpos ++ ) for( uint16_t xpos = 0 ; xpos < 240 ; xpos ++ )
{ {
int16_t point = y_max_range.clip( ( ( spectrum_data[ xpos ] - raw_min ) * ( 320 - 108 ) ) / raw_delta ); // save max powerwull freq
if( spectrum_data[ xpos ] > max_freq_power )
{
max_freq_power = spectrum_data[ xpos ];
max_freq_hold = f_min + ( (f_max - f_min) * xpos) / 240 ;
}
int16_t point = y_max_range.clip( ( ( spectrum_data[ xpos ] - raw_min ) * ( 320 - ( 108 + 16 ) ) ) / raw_delta );
uint8_t color_gradient = (point * 255) / 212 ; uint8_t color_gradient = (point * 255) / 212 ;
display.fill_rectangle( { { xpos , 108 } , { 1 , 320 - point } } , { 0 , 0 , 0 } ); // clear if not in peak view
if( live_frequency_view != 2 )
{
display.fill_rectangle( { { xpos , 108 + 16 } , { 1 , 320 - point } } , { 0 , 0 , 0 } );
}
display.fill_rectangle( { { xpos , 320 - point } , { 1 , point } } , { color_gradient , 0 , uint8_t( 255 - color_gradient ) } ); display.fill_rectangle( { { xpos , 320 - point } , { 1 , point } } , { color_gradient , 0 , uint8_t( 255 - color_gradient ) } );
} }
if( last_max_freq != max_freq_hold )
{
last_max_freq = max_freq_hold ;
freq_stats.set( "MAX:"+to_string_short_freq( max_freq_hold ) );
}
PlotMarker(field_marker.value());
} }
else else
{ {
@ -155,6 +187,7 @@ namespace ui
void GlassView::on_range_changed() void GlassView::on_range_changed()
{ {
reset_live_view( false );
f_min = field_frequency_min.value(); f_min = field_frequency_min.value();
f_max = field_frequency_max.value(); f_max = field_frequency_max.value();
search_span = f_max - f_min; search_span = f_max - f_min;
@ -195,10 +228,15 @@ namespace ui
pos -= f_min; pos -= f_min;
pos = pos / marker_pixel_step; // Real pixel pos = pos / marker_pixel_step; // Real pixel
portapack::display.fill_rectangle({0, 100, 240, 8}, Color::black()); // Clear old marker and whole marker rectangle btw uint8_t shift_y = 0 ;
portapack::display.fill_rectangle({(int)pos - 2, 100, 5, 3}, Color::red()); // Red marker top if( live_frequency_view > 0 )
portapack::display.fill_rectangle({(int)pos - 1, 103, 3, 3}, Color::red()); // Red marker middle {
portapack::display.fill_rectangle({(int)pos, 106, 1, 2}, Color::red()); // Red marker bottom shift_y = 16 ;
}
portapack::display.fill_rectangle({0, 100 + shift_y, 240, 8}, Color::black()); // Clear old marker and whole marker rectangle btw
portapack::display.fill_rectangle({(int)pos - 2, 100 + shift_y, 5, 3}, Color::red()); // Red marker top
portapack::display.fill_rectangle({(int)pos - 1, 103 + shift_y, 3, 3}, Color::red()); // Red marker middle
portapack::display.fill_rectangle({(int)pos, 106 + shift_y, 1, 2}, Color::red()); // Red marker bottom
} }
GlassView::GlassView( GlassView::GlassView(
@ -220,7 +258,10 @@ namespace ui
&range_presets, &range_presets,
&field_marker, &field_marker,
&text_marker_pm, &text_marker_pm,
&field_trigger}); &field_trigger,
&button_jump,
&button_rst,
&freq_stats});
load_Presets(); // Load available presets from TXT files (or default) load_Presets(); // Load available presets from TXT files (or default)
@ -228,6 +269,7 @@ namespace ui
field_frequency_min.set_step( steps ); field_frequency_min.set_step( steps );
field_frequency_min.on_change = [this](int32_t v) field_frequency_min.on_change = [this](int32_t v)
{ {
reset_live_view( true );
int32_t steps_ = steps ; int32_t steps_ = steps ;
if( steps_ < 24 ) if( steps_ < 24 )
steps_ = 24 ; steps_ = 24 ;
@ -261,6 +303,7 @@ namespace ui
field_frequency_max.set_step( steps ); field_frequency_max.set_step( steps );
field_frequency_max.on_change = [this](int32_t v) field_frequency_max.on_change = [this](int32_t v)
{ {
reset_live_view( true );
int32_t steps_ = steps ; int32_t steps_ = steps ;
if( steps_ < 24 ) if( steps_ < 24 )
steps_ = 24 ; steps_ = 24 ;
@ -293,12 +336,14 @@ namespace ui
field_lna.set_value(receiver_model.lna()); field_lna.set_value(receiver_model.lna());
field_lna.on_change = [this](int32_t v) field_lna.on_change = [this](int32_t v)
{ {
reset_live_view( true );
this->on_lna_changed(v); this->on_lna_changed(v);
}; };
field_vga.set_value(receiver_model.vga()); field_vga.set_value(receiver_model.vga());
field_vga.on_change = [this](int32_t v_db) field_vga.on_change = [this](int32_t v_db)
{ {
reset_live_view( true );
this->on_vga_changed(v_db); this->on_vga_changed(v_db);
}; };
@ -314,26 +359,45 @@ namespace ui
view_config.on_change = [this](size_t n, OptionsField::value_t v) view_config.on_change = [this](size_t n, OptionsField::value_t v)
{ {
(void)n; (void)n;
live_frequency_view = v ; // clear between changes
if( v ) reset_live_view( true );
{ if( v == 0 )
display.scroll_disable();
level_integration.hidden( false );
}
else
{ {
live_frequency_view = 0 ;
level_integration.hidden( true ); level_integration.hidden( true );
set_dirty(); freq_stats.hidden( true );
button_jump.hidden( true );
button_rst.hidden( true );
display.scroll_set_area(109, 319); // Restart scroll on the correct coordinates display.scroll_set_area(109, 319); // Restart scroll on the correct coordinates
} }
// clear between changes else if( v == 1 )
display.fill_rectangle( { { 0 , 108 } , { 240 , 320 - 108 } } , { 0 , 0 , 0 } ); {
display.fill_rectangle( { { 0 , 108 } , { 240 , 24 } } , { 0 , 0 , 0 } );
live_frequency_view = 1 ;
display.scroll_disable();
level_integration.hidden( false );
freq_stats.hidden( false );
button_jump.hidden( false );
button_rst.hidden( false );
}
else if( v == 2 )
{
display.fill_rectangle( { { 0 , 108 } , { 240 , 24 } } , { 0 , 0 , 0 } );
live_frequency_view = 2 ;
display.scroll_disable();
level_integration.hidden( false );
freq_stats.hidden( false );
button_jump.hidden( false );
button_rst.hidden( false );
}
set_dirty();
}; };
view_config.set_selected_index(0); //default spectrum view_config.set_selected_index(0); //default spectrum
level_integration.on_change = [this](size_t n, OptionsField::value_t v) level_integration.on_change = [this](size_t n, OptionsField::value_t v)
{ {
(void)n; (void)n;
reset_live_view( true );
live_frequency_integrate = v ; live_frequency_integrate = v ;
}; };
level_integration.set_selected_index(2); //default integration of ( 3 * old value + new_value ) / 4 level_integration.set_selected_index(2); //default integration of ( 3 * old value + new_value ) / 4
@ -341,6 +405,7 @@ namespace ui
filter_config.set_selected_index(0); filter_config.set_selected_index(0);
filter_config.on_change = [this](size_t n, OptionsField::value_t v) { filter_config.on_change = [this](size_t n, OptionsField::value_t v) {
(void)n; (void)n;
reset_live_view( true );
min_color_power = v; min_color_power = v;
}; };
@ -373,6 +438,17 @@ namespace ui
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, v); baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, v);
}; };
button_jump.on_select = [this](Button&) {
receiver_model.set_tuning_frequency(max_freq_hold); // Center tune rx in marker freq.
receiver_model.set_frequency_step(MHZ_DIV); // Preset a 1 MHz frequency step into RX -> AUDIO
nav_.pop();
nav_.push<AnalogAudioView>(); // Jump into audio view
};
button_rst.on_select = [this](Button&) {
reset_live_view( true );
};
display.scroll_set_area(109, 319); display.scroll_set_area(109, 319);
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value()); // trigger: baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value()); // trigger:
// Discord User jteich: WidebandSpectrum::on_message to set the trigger value. In WidebandSpectrum::execute , // Discord User jteich: WidebandSpectrum::on_message to set the trigger value. In WidebandSpectrum::execute ,

View File

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2020 euquiq * Copyright (C) 2020 euquiq
* Copyright (C) 2023 gullradriel, Nilorea Studio Inc.
* *
* This file is part of PortaPack. * This file is part of PortaPack.
* *
@ -36,7 +37,9 @@
namespace ui namespace ui
{ {
#define LOOKING_GLASS_SLICE_WIDTH 20000000 // Each slice bandwidth 20 MHz #define LOOKING_GLASS_SLICE_WIDTH 19999920 // Each slice bandwidth 20 MHz and a multiple of 240
// since we are using LOOKING_GLASS_SLICE_WIDTH/240 as the each_bin_size
// it should also be a multiple of 2 since we are using LOOKING_GLASS_SLICE_WIDTH / 2 as centering freq
#define MHZ_DIV 1000000 #define MHZ_DIV 1000000
#define X2_MHZ_DIV 2000000 #define X2_MHZ_DIV 2000000
@ -72,6 +75,7 @@ namespace ui
void on_range_changed(); void on_range_changed();
void on_lna_changed(int32_t v_db); void on_lna_changed(int32_t v_db);
void on_vga_changed(int32_t v_db); void on_vga_changed(int32_t v_db);
void reset_live_view( bool clear_screen );
void add_spectrum_pixel(int16_t color); void add_spectrum_pixel(int16_t color);
void PlotMarker(rf::Frequency pos); void PlotMarker(rf::Frequency pos);
void load_Presets(); void load_Presets();
@ -93,8 +97,10 @@ namespace ui
ChannelSpectrumFIFO* fifo { nullptr }; ChannelSpectrumFIFO* fifo { nullptr };
uint8_t max_power = 0; uint8_t max_power = 0;
int32_t steps = 250 ; // default of 250 Mhz steps int32_t steps = 250 ; // default of 250 Mhz steps
bool live_frequency_view = false ; uint8_t live_frequency_view = 0 ;
int16_t live_frequency_integrate = 3 ; int16_t live_frequency_integrate = 3 ;
uint64_t max_freq_hold = 0 ;
int16_t max_freq_power = -1000 ;
Labels labels{ Labels labels{
{{0, 0}, "MIN: MAX: LNA VGA ", Color::light_grey()}, {{0, 0}, "MIN: MAX: LNA VGA ", Color::light_grey()},
@ -132,41 +138,6 @@ namespace ui
{7 * 8, 1 * 16, 4 * 8, 16}, {7 * 8, 1 * 16, 4 * 8, 16},
""}; ""};
OptionsField steps_config{
{ 14 * 8, 4 * 16},
4,
{
{"1", 1},
{"50", 50},
{"100", 100},
{"250", 250},
{"500", 500},
}};
OptionsField view_config{
{ 19 * 8, 4 * 16},
7,
{
{"SPCTR-V", false },
{"LEVEL-V", true },
}};
OptionsField level_integration{
{ 27 * 8, 4 * 16},
2,
{
{"x1", 1 },
{"x2", 2 },
{"x3", 3 },
{"x4", 4 },
{"x5", 5 },
{"x6", 6 },
{"x7", 7 },
{"x8", 8 },
{"x9", 9 },
}};
OptionsField filter_config{ OptionsField filter_config{
{19 * 8, 1 * 16}, {19 * 8, 1 * 16},
4, 4,
@ -204,6 +175,55 @@ namespace ui
2, 2,
' '}; ' '};
OptionsField steps_config{
{ 14 * 8, 4 * 16},
4,
{
{"1", 1},
{"50", 50},
{"100", 100},
{"250", 250},
{"500", 500},
}};
OptionsField view_config{
{ 19 * 8, 4 * 16},
7,
{
{"SPCTR-V", 0 },
{"LEVEL-V", 1 },
{"PEAK-V" , 2 },
}};
OptionsField level_integration{
{ 27 * 8, 4 * 16},
2,
{
{"x1", 1 },
{"x2", 2 },
{"x3", 3 },
{"x4", 4 },
{"x5", 5 },
{"x6", 6 },
{"x7", 7 },
{"x8", 8 },
{"x9", 9 },
}};
Button button_jump {
{ 240 - 4 * 8 , 5 * 16 , 4 * 8, 16 },
"JMP"
};
Button button_rst {
{ 240 - 9 * 8 , 5 * 16 , 4 * 8, 16 },
"RST"
};
Text freq_stats{
{0 * 8, 5 * 16 , 240 - 10 * 8 , 8 },
""
};
MessageHandlerRegistration message_handler_spectrum_config { MessageHandlerRegistration message_handler_spectrum_config {
Message::ID::ChannelSpectrumConfig, Message::ID::ChannelSpectrumConfig,