fixing PR comments (#991)

* cleanings, factorisation, indentation.
This commit is contained in:
gullradriel 2023-05-15 10:50:21 +02:00 committed by GitHub
parent 22430fb8d4
commit 1a829707f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1580 additions and 1631 deletions

File diff suppressed because it is too large Load Diff

View File

@ -49,37 +49,37 @@ namespace ui {
void focus() override;
const Style style_grey { // recon
const Style style_grey { // recon
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::grey(),
};
const Style style_white { // recon
const Style style_white { // recon
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::white(),
};
const Style style_yellow { //Found signal
const Style style_yellow { //found signal
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::yellow(),
};
const Style style_green { //Found signal
const Style style_green { //Found signal
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::green(),
};
const Style style_red { //erasing freq
const Style style_red { //erasing freq
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::red(),
};
const Style style_blue { // quick recon, wait == 0
const Style style_blue { // quick recon, wait == 0
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::blue(),
@ -92,7 +92,7 @@ namespace ui {
private:
NavigationView& nav_;
void audio_output_start();
void audio_output_start();
bool check_sd_card();
size_t change_mode( freqman_index_t mod_type);
void show_max( bool refresh_display = false );
@ -106,6 +106,9 @@ namespace ui {
void recon_redraw();
void handle_retune();
void handle_coded_squelch(const uint32_t value);
bool ReconSetupLoadStrings( const std::string &source, std::string &input_file , std::string &output_file , uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , int32_t &recon_squelch_level , uint32_t &recon_match_mode , int32_t &wait , int32_t &volume );
bool ReconSetupSaveStrings( const std::string &dest, const std::string &input_file , const std::string &output_file , uint32_t recon_lock_duration , uint32_t recon_lock_nb_match , int32_t recon_squelch_level , uint32_t recon_match_mode , int32_t wait , int32_t volume );
bool ReconSaveFreq( const std::string &freq_file_path , size_t index , bool warn_if_exists );
jammer::jammer_range_t frequency_range { false, 0, MAX_UFREQ }; //perfect for manual recon task too...
int32_t squelch { 0 };
@ -127,16 +130,16 @@ namespace ui {
bool load_hamradios = { true };
bool update_ranges = { true };
bool fwd = { true };
bool recon = true ;
bool recon = true ;
uint32_t recon_lock_nb_match = { 3 };
uint32_t recon_lock_duration = { RECON_DEF_LOCK_DURATION };
uint32_t recon_lock_duration = { RECON_MIN_LOCK_DURATION };
uint32_t recon_match_mode = { RECON_MATCH_CONTINUOUS };
bool scanner_mode { false };
bool manual_mode { false };
bool sd_card_mounted = false ;
int32_t volume = 40 ;
int32_t stepper = 0 ;
int32_t index_stepper = 0 ;
int32_t stepper = 0 ;
int32_t index_stepper = 0 ;
int64_t freq = 0 ;
uint32_t step = 0 ;
freqman_index_t def_modulation = 0 ;
@ -146,9 +149,22 @@ namespace ui {
freqman_entry last_entry = { } ;
bool entry_has_changed = false ;
uint32_t freq_lock { 0 };
int64_t minfreq = 0 ;
int64_t minfreq = 0 ;
int64_t maxfreq = 0 ;
bool has_looped = false ;
int8_t status = -1 ; // 0 recon , 1 locking , 2 locked
int32_t last_timer = -1 ;
int8_t last_db = -127 ;
uint16_t last_nb_match = 999 ;
uint16_t last_freq_lock = 999 ;
size_t last_list_size = 0 ;
int8_t last_rssi_min = -127 ;
int8_t last_rssi_med = -127 ;
int8_t last_rssi_max = -127 ;
int32_t last_index = -1 ;
int32_t last_squelch_index = -1 ;
int64_t last_freq = 0 ;
std::string freq_file_path = { } ;
Labels labels
{
@ -183,7 +199,7 @@ namespace ui {
{ 3 * 8, 1 * 16 },
6,
{ }
};
};
NumberField field_squelch {
{ 12 * 8, 1 * 16 },
@ -196,7 +212,7 @@ namespace ui {
NumberField field_wait {
{ 20 * 8, 1 * 16 },
5,
{ -(10000-STATS_UPDATE_INTERVAL) , (10000-STATS_UPDATE_INTERVAL) },
{ -RECON_MAX_LOCK_DURATION , RECON_MAX_LOCK_DURATION },
STATS_UPDATE_INTERVAL,
' ',
};
@ -204,8 +220,8 @@ namespace ui {
NumberField field_lock_wait {
{ 26 * 8, 1 * 16 },
4,
{ RECON_DEF_LOCK_DURATION , (10000-RECON_DEF_LOCK_DURATION) },
RECON_DEF_LOCK_DURATION,
{ RECON_MIN_LOCK_DURATION , RECON_MAX_LOCK_DURATION },
STATS_UPDATE_INTERVAL,
' ',
};
@ -223,24 +239,19 @@ namespace ui {
};
Text desc_cycle {
{0, 4 * 16, SCREEN_W , 16 },
{0, 4 * 16, SCREEN_W , 16 },
};
/* BigFrequency big_display { //Show frequency in glamour
{ 4, 7 * 16 - 8 , 28 * 8, 52 },
0
}; */
Text big_display { //Show frequency in text mode
Text big_display { //Show frequency in text mode
{ 0, 5 * 16 , 23 * 8, 16 },
};
Text freq_stats { //Show frequency stats in text mode
Text freq_stats { //Show frequency stats in text mode
{ 0, 6 * 16 , 23 * 8, 16 },
};
// TIMER: 9999
Text text_timer { //Show frequency stats in text mode
Text text_timer { //Show frequency stats in text mode
{ 0, 7 * 16 , 11 * 8, 16 },
};
@ -266,7 +277,7 @@ namespace ui {
"RECON"
};
Text file_name { //Show file used
Text file_name { //show file used
{ 0 , 8 * 16 + 6 , SCREEN_W - 7 * 8, 16 },
};
@ -351,7 +362,7 @@ namespace ui {
}
};
// app save settings
std::app_settings settings { };
std::app_settings settings { };
std::app_settings::AppSettings app_settings { };
};

View File

@ -34,133 +34,6 @@ using namespace portapack;
namespace ui {
bool ReconSetupLoadStrings( std::string source, std::string &input_file , std::string &output_file , uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , int32_t &recon_squelch_level , uint32_t &recon_match_mode , int32_t &wait , int32_t &volume )
{
File settings_file;
size_t length, file_position = 0;
char * pos;
char * line_start;
char * line_end;
char file_data[257];
uint32_t it = 0 ;
uint32_t nb_params = RECON_SETTINGS_NB_PARAMS ;
std::string params[ RECON_SETTINGS_NB_PARAMS ];
bool check_sd_card = (sd_card::status() == sd_card::Status::Mounted) ? true : false ;
if( check_sd_card )
{
auto result = settings_file.open( source );
if( !result.is_valid() )
{
while( it < nb_params )
{
// Read a 256 bytes block from file
settings_file.seek(file_position);
memset(file_data, 0, 257);
auto read_size = settings_file.read(file_data, 256);
if (read_size.is_error())
break ;
file_position += 256;
// Reset line_start to beginning of buffer
line_start = file_data;
pos=line_start;
while ((line_end = strstr(line_start, "\x0A"))) {
length = line_end - line_start - 1 ;
params[ it ] = string( pos , length );
it ++ ;
line_start = line_end + 1;
pos=line_start ;
if (line_start - file_data >= 256)
break;
if( it >= nb_params )
break ;
}
if (read_size.value() != 256)
break; // End of file
// Restart at beginning of last incomplete line
file_position -= (file_data + 256 - line_start);
}
}
}
if( it < nb_params )
{
/* bad number of params, signal defaults */
input_file = "RECON" ;
output_file = "RECON_RESULTS" ;
recon_lock_duration = RECON_DEF_LOCK_DURATION ;
recon_lock_nb_match = RECON_DEF_NB_MATCH ;
recon_squelch_level = -14 ;
recon_match_mode = RECON_MATCH_CONTINUOUS ;
wait = RECON_DEF_WAIT_DURATION ;
volume = 40 ;
return false ;
}
if( it > 0 )
input_file = params[ 0 ];
else
input_file = "RECON" ;
if( it > 1 )
output_file= params[ 1 ];
else
output_file = "RECON_RESULTS" ;
if( it > 2 )
recon_lock_duration = strtoll( params[ 2 ].c_str() , nullptr , 10 );
else
recon_lock_duration = RECON_DEF_LOCK_DURATION ;
if( it > 3 )
recon_lock_nb_match = strtoll( params[ 3 ].c_str() , nullptr , 10 );
else
recon_lock_nb_match = RECON_DEF_NB_MATCH ;
if( it > 4 )
recon_squelch_level = strtoll( params[ 4 ].c_str() , nullptr , 10 );
else
recon_squelch_level = -14 ;
if( it > 5 )
recon_match_mode = strtoll( params[ 5 ].c_str() , nullptr , 10 );
else
recon_match_mode = RECON_MATCH_CONTINUOUS ;
if( it > 6 )
wait = strtoll( params[ 6 ].c_str() , nullptr , 10 );
else
wait = RECON_DEF_WAIT_DURATION ;
if( it > 8 )
volume = strtoll( params[ 8 ].c_str() , nullptr , 10 );
else
volume = 40 ;
return true ;
}
bool ReconSetupSaveStrings( std::string dest, std::string input_file , std::string output_file , uint32_t recon_lock_duration , uint32_t recon_lock_nb_match , int32_t recon_squelch_level , uint32_t recon_match_mode , int32_t wait , int32_t volume )
{
File settings_file;
auto result = settings_file.create( dest );
if( result.is_valid() )
return false ;
settings_file.write_line( input_file );
settings_file.write_line( output_file );
settings_file.write_line( to_string_dec_uint( recon_lock_duration ) );
settings_file.write_line( to_string_dec_uint( recon_lock_nb_match ) );
settings_file.write_line( to_string_dec_int( recon_squelch_level ) );
settings_file.write_line( to_string_dec_uint( recon_match_mode ) );
settings_file.write_line( to_string_dec_int( wait ) );
settings_file.write_line( to_string_dec_int( volume ) );
return true ;
}
ReconSetupViewMain::ReconSetupViewMain( NavigationView &nav , Rect parent_rect , std::string input_file , std::string output_file ) : View( parent_rect ) , _input_file { input_file } , _output_file { output_file }
{
hidden(true);
@ -180,8 +53,8 @@ namespace ui {
checkbox_continuous.set_value( persistent_memory::recon_continuous() );
checkbox_clear_output.set_value( persistent_memory::recon_clear_output() );
text_input_file.set( _input_file );
button_output_file.set_text( _output_file );
text_input_file.set( _input_file );
button_output_file.set_text( _output_file );
button_load_freqs.on_select = [this, &nav](Button&) {
auto open_view = nav.push<FileLoadView>(".TXT");
@ -205,7 +78,7 @@ namespace ui {
std::string str_file_path = new_file_path.string();
if (str_file_path.find(dir_filter) != string::npos) { // assert file from the FREQMAN folder
_output_file = new_file_path.stem().string();
button_output_file.set_text( _output_file );
button_output_file.set_text( _output_file );
} else {
nav.display_modal("LOAD ERROR", "A valid file from\nFREQMAN directory is\nrequired.");
}

View File

@ -35,7 +35,7 @@
// 1Mhz helper
#ifdef OneMHz
#undef OneMHz
#undef OneMHz
#endif
#define OneMHz 1000000
@ -43,12 +43,15 @@
#define RECON_MATCH_CONTINUOUS 0
#define RECON_MATCH_SPARSE 1
// statistics update interval (change here if it's evolving) in ms
// statistics update interval in ms (change here if the statistics API is changing it's pace)
#define STATS_UPDATE_INTERVAL 100
// maximum lock duration
#define RECON_MAX_LOCK_DURATION 9900
// default number of match to have a lock
#define RECON_DEF_NB_MATCH 3
#define RECON_DEF_LOCK_DURATION 100 // have to be >= and a multiple of STATS_UPDATE_INTERVAL
#define RECON_MIN_LOCK_DURATION 100 // have to be >= and a multiple of STATS_UPDATE_INTERVAL
#define RECON_DEF_WAIT_DURATION 1000 // will be incremented/decremented by STATS_UPDATE_INTERVAL steps
// screen size helper
@ -60,9 +63,6 @@
namespace ui {
bool ReconSetupLoadStrings( std::string source, std::string &input_file , std::string &output_file , uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , int32_t &recon_squelch_level , uint32_t &recon_match_mode , int32_t &wait , int32_t &volume );
bool ReconSetupSaveStrings( std::string dest, const std::string input_file , const std::string output_file , const uint32_t recon_lock_duration , const uint32_t recon_lock_nb_match , int32_t recon_squelch_level , uint32_t recon_match_mode , int32_t wait , int32_t volume );
class ReconSetupViewMain : public View {
public:
ReconSetupViewMain( NavigationView& nav, Rect parent_rect , std::string input_file , std::string output_file );
@ -88,7 +88,7 @@ namespace ui {
};
Button button_output_file {
{ 1 * 8 , 5 * 16 - 2, 18 * 8, 22 },
"RECON_RESULTS"
"RECON_RESULTS"
};
Checkbox checkbox_autosave_freqs {
@ -117,7 +117,7 @@ namespace ui {
class ReconSetupViewMore : public View {
public:
ReconSetupViewMore( NavigationView& nav, Rect parent_rect , const uint32_t _recon_lock_duration , const uint32_t _recon_lock_nb_match , const uint32_t _recon_match_mode );
ReconSetupViewMore( NavigationView& nav, Rect parent_rect , uint32_t _recon_lock_duration , uint32_t _recon_lock_nb_match , uint32_t _recon_match_mode );
void Save( uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , uint32_t &recon_match_mode );
@ -125,9 +125,9 @@ namespace ui {
private:
const uint32_t _recon_lock_duration = STATS_UPDATE_INTERVAL ;
const uint32_t _recon_lock_nb_match = RECON_DEF_NB_MATCH ;
const uint32_t _recon_match_mode = RECON_MATCH_CONTINUOUS ;
uint32_t _recon_lock_duration = STATS_UPDATE_INTERVAL ;
uint32_t _recon_lock_nb_match = RECON_DEF_NB_MATCH ;
uint32_t _recon_match_mode = RECON_MATCH_CONTINUOUS ;
Checkbox checkbox_load_freqs {
{ 1 * 8, 12 },
@ -159,10 +159,10 @@ namespace ui {
NumberField field_recon_lock_duration {
{ 1 * 8, 132 }, // position X , Y
4, // number of displayed digits (even empty)
{ STATS_UPDATE_INTERVAL , 10000-STATS_UPDATE_INTERVAL }, // range of number
STATS_UPDATE_INTERVAL, // rotary encoder increment
' ', // filling character
false // can loop
{ -RECON_MAX_LOCK_DURATION , RECON_MAX_LOCK_DURATION }, // range of number
STATS_UPDATE_INTERVAL, // rotary encoder increment
' ', // filling character
false // can loop
};
Text text_recon_lock_nb {
{ 1 * 8 , 162 , 25 * 8 , 22 },
@ -189,7 +189,7 @@ namespace ui {
class ReconSetupView : public View {
public:
ReconSetupView( NavigationView& nav , std::string _input_file , std::string _output_file , const uint32_t _recon_lock_duration , const uint32_t _recon_lock_nb_match , const uint32_t _recon_match_mode );
ReconSetupView( NavigationView& nav , std::string _input_file , std::string _output_file , uint32_t _recon_lock_duration , uint32_t _recon_lock_nb_match , uint32_t _recon_match_mode );
std::function<void( std::vector<std::string> messages )> on_changed { };