Added and fixed go to index

This commit is contained in:
GullCode 2023-03-26 15:11:27 +02:00
parent 3d13ee828e
commit 17f30b6f26
2 changed files with 126 additions and 124 deletions

View File

@ -68,6 +68,10 @@ namespace ui {
_stepper = v; _stepper = v;
} }
void ReconThread::set_index_stepper( const int64_t v){
_index_stepper = v;
}
void ReconThread::set_lock_duration( const uint32_t v ){ void ReconThread::set_lock_duration( const uint32_t v ){
_lock_duration = v; _lock_duration = v;
} }
@ -152,7 +156,6 @@ namespace ui {
int64_t minfreq = 0 ; int64_t minfreq = 0 ;
int64_t maxfreq = 0 ; int64_t maxfreq = 0 ;
bool has_looped = false ; bool has_looped = false ;
bool entry_has_changed = false ;
RetuneMessage message { }; RetuneMessage message { };
if( frequency_list_[ 0 ] . step >= 0 ) if( frequency_list_[ 0 ] . step >= 0 )
@ -196,22 +199,17 @@ namespace ui {
last_entry . modulation = -1 ; last_entry . modulation = -1 ;
last_entry . bandwidth = -1 ; last_entry . bandwidth = -1 ;
last_entry . step = -1 ; last_entry . step = -1 ;
int16_t last_index = -1 ;
bool restart_recon = false; //Flag whenever scanning is restarting after a pause bool restart_recon = false; //Flag whenever scanning is restarting after a pause
int16_t last_index = -1 ;
while( !chThdShouldTerminate() && frequency_list_.size() > 0 ) { while( !chThdShouldTerminate() && frequency_list_.size() > 0 ) {
if( !_freq_delete )
{
if( _recon || _stepper != 0 || last_index != frequency_index )
{
if( _freq_lock == 0 || _stepper != 0 || last_index != frequency_index ) //normal recon (not performing freq_lock)
{
if( !restart_recon || _stepper != 0 || last_index != frequency_index )
{
last_index = frequency_index ;
has_looped = false ; has_looped = false ;
entry_has_changed = false ; entry_has_changed = false ;
if( !_freq_delete )
{
if( _recon || _stepper != 0 || _index_stepper != 0 || last_index !=frequency_index )
{
last_index = frequency_index ;
if( last_entry . frequency_a != freq ) if( last_entry . frequency_a != freq )
{ {
last_entry . frequency_a = freq ; last_entry . frequency_a = freq ;
@ -220,7 +218,6 @@ namespace ui {
message.range = frequency_index ; message.range = frequency_index ;
EventDispatcher::send_message(message); EventDispatcher::send_message(message);
} }
// Set modulation if any // Set modulation if any
if( last_entry . modulation != frequency_list_[ frequency_index ] . modulation && frequency_list_[ frequency_index ] . modulation >= 0 ) if( last_entry . modulation != frequency_list_[ frequency_index ] . modulation && frequency_list_[ frequency_index ] . modulation >= 0 )
{ {
@ -245,6 +242,10 @@ namespace ui {
EventDispatcher::send_message(message); EventDispatcher::send_message(message);
step = freqman_entry_get_step_value( last_entry . step ); step = freqman_entry_get_step_value( last_entry . step );
} }
if( _freq_lock == 0 || _stepper != 0 ) //normal recon (not performing freq_lock)
{
if( !restart_recon || _stepper != 0 )
{
/* we are doing a range */ /* we are doing a range */
if( frequency_list_[ frequency_index ] . type == RANGE ) { if( frequency_list_[ frequency_index ] . type == RANGE ) {
@ -357,13 +358,29 @@ namespace ui {
frequency_index = frequency_list_.size() - 1 ; frequency_index = frequency_list_.size() - 1 ;
} }
} }
} }
else else
{ {
restart_recon = false ; restart_recon = false ;
} }
} }
}
else
{
restart_recon = true ;
}
if( _index_stepper != 0 )
{
if( _index_stepper > 0 )
frequency_index ++ ;
if( _index_stepper < 0 )
frequency_index -- ;
if( frequency_index < 0 )
frequency_index = frequency_list_.size() - 1 ;
if( (unsigned)frequency_index >= frequency_list_.size() )
frequency_index = 0 ;
entry_has_changed = true ;
}
// reload entry if changed // reload entry if changed
if( entry_has_changed ){ if( entry_has_changed ){
switch( frequency_list_[ frequency_index ] . type ){ switch( frequency_list_[ frequency_index ] . type ){
@ -373,11 +390,11 @@ namespace ui {
case RANGE: case RANGE:
minfreq = frequency_list_[ frequency_index ] . frequency_a ; minfreq = frequency_list_[ frequency_index ] . frequency_a ;
maxfreq = frequency_list_[ frequency_index ] . frequency_b ; maxfreq = frequency_list_[ frequency_index ] . frequency_b ;
if( ( _fwd && _stepper == 0 ) || _stepper > 0 ) if( ( _fwd && _stepper == 0 ) || _stepper > 0 || _index_stepper > 0 )
{ {
freq = minfreq ; freq = minfreq ;
} }
else if( ( !_fwd && _stepper == 0 ) || _stepper < 0 ) else if( ( !_fwd && _stepper == 0 ) || _stepper < 0 || _index_stepper < 0 )
{ {
freq = maxfreq ; freq = maxfreq ;
} }
@ -385,11 +402,11 @@ namespace ui {
case HAMRADIO: case HAMRADIO:
minfreq = frequency_list_[ frequency_index ] . frequency_a ; minfreq = frequency_list_[ frequency_index ] . frequency_a ;
maxfreq = frequency_list_[ frequency_index ] . frequency_b ; maxfreq = frequency_list_[ frequency_index ] . frequency_b ;
if( ( _fwd && _stepper == 0 ) || _stepper > 0 ) if( ( _fwd && _stepper == 0 ) || _stepper > 0 || _index_stepper > 0 )
{ {
freq = minfreq ; freq = minfreq ;
} }
else if( ( !_fwd && _stepper == 0 ) || _stepper < 0 ) else if( ( !_fwd && _stepper == 0 ) || _stepper < 0 || _index_stepper < 0 )
{ {
freq = maxfreq ; freq = maxfreq ;
} }
@ -399,7 +416,6 @@ namespace ui {
} }
} }
// send a pause message with the right freq // send a pause message with the right freq
if( has_looped && !_continuous ) if( has_looped && !_continuous )
{ {
@ -411,11 +427,9 @@ namespace ui {
} }
if( _stepper < 0 ) _stepper ++ ; if( _stepper < 0 ) _stepper ++ ;
if( _stepper > 0 ) _stepper -- ; if( _stepper > 0 ) _stepper -- ;
} if( _index_stepper < 0 ) _index_stepper ++ ;
else if( _index_stepper > 0 ) _index_stepper -- ;
{
restart_recon = true ;
}
} }
chThdSleepMilliseconds( _lock_duration ); //Needed to (eventually) stabilize the receiver into new freq chThdSleepMilliseconds( _lock_duration ); //Needed to (eventually) stabilize the receiver into new freq
} }
@ -765,23 +779,8 @@ namespace ui {
f = f / 1000000 ; f = f / 1000000 ;
if( f >= 1 && f <= frequency_list.size() ) if( f >= 1 && f <= frequency_list.size() )
{ {
current_index=f; recon_thread-> set_index_stepper( f - 1 - current_index );
text_cycle.set_text( to_string_dec_uint( current_index + 1 , 3 ) );
recon_thread->set_freq_index( current_index );
if(frequency_list[current_index].description.size() > 0)
{
desc_cycle.set( frequency_list[current_index].description ); //Show new description
}
else
{
desc_cycle.set( "no description" ); //Show new description
show_max( true ); //UPDATE new list size on screen
}
recon_thread->set_freq_lock( 0 ); recon_thread->set_freq_lock( 0 );
RetuneMessage message { };
message.freq = 0 ;
message.range = current_index ;
EventDispatcher::send_message(message);
} }
}; };
} }
@ -836,23 +835,24 @@ namespace ui {
}; };
text_cycle.on_change = [this]() { text_cycle.on_change = [this]() {
int32_t new_index = current_index + text_cycle.get_encoder_delta();
if( frequency_list.size() > 0 ) if( frequency_list.size() > 0 )
{ {
if( new_index < 0 ) if( text_cycle.get_encoder_delta() > 0 )
new_index = frequency_list.size() - 1 ; {
if( (unsigned)new_index > frequency_list.size() - 1 ) fwd = true ;
new_index = 0 ; recon_thread -> set_recon_direction( fwd );
current_index=new_index ; button_dir.set_text( "FW>" );
timer = 0 ; recon_thread-> set_index_stepper( 1 );
recon_thread->set_freq_index( current_index );
RetuneMessage message { };
receiver_model.set_tuning_frequency( frequency_list[ current_index ] . frequency_a ); // Retune
recon_thread->set_freq_lock( 0 ); recon_thread->set_freq_lock( 0 );
message.freq = frequency_list[ current_index ] . frequency_a ; }
message.range = current_index ; else if( text_cycle.get_encoder_delta() < 0 )
EventDispatcher::send_message(message); {
chThdSleepMilliseconds( recon_lock_duration ); fwd = false ;
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "<RW" );
recon_thread-> set_index_stepper( -1 );
recon_thread->set_freq_lock( 0 );
}
} }
text_cycle.set_encoder_delta( 0 ); text_cycle.set_encoder_delta( 0 );
}; };
@ -903,7 +903,6 @@ namespace ui {
} }
} }
} }
button_manual_start.set_encoder_delta( 0 );
}; };
button_pause.on_change = [this]() { button_pause.on_change = [this]() {

View File

@ -62,6 +62,7 @@ namespace ui {
int64_t get_current_freq(); int64_t get_current_freq();
void set_stepper(const int64_t v); void set_stepper(const int64_t v);
void set_index_stepper(const int64_t v);
void change_recon_direction(); void change_recon_direction();
bool get_recon_direction(); bool get_recon_direction();
@ -101,7 +102,9 @@ namespace ui {
bool _freq_delete { false }; bool _freq_delete { false };
bool _fwd { true }; bool _fwd { true };
bool _continuous { true }; bool _continuous { true };
bool entry_has_changed = false ;
int64_t _stepper { 0 }; int64_t _stepper { 0 };
int64_t _index_stepper { 0 };
int32_t _freq_lock { 0 }; int32_t _freq_lock { 0 };
uint32_t _lock_duration { 50 }; uint32_t _lock_duration { 50 };
uint32_t _lock_nb_match { 10 }; uint32_t _lock_nb_match { 10 };
@ -267,7 +270,7 @@ namespace ui {
}; };
RSSI rssi { RSSI rssi {
{ 0 * 16, 2 * 16, 240 - 4 * 8 , 16 }, { 0 * 16, 2 * 16, 240 - 4 * 8 - 1 , 16 },
}; };
ButtonWithEncoder text_cycle { ButtonWithEncoder text_cycle {