2525#define NTP_CHECK_TIME 60000 // NTP time refresh period (ms)
2626#define SCHEDULE_CHECK_TIME 2000 // How often to identify the same frequency (ms)
2727#define BACKGROUND_REFRESH_TIME 5000 // Background screen refresh time. Covers the situation where there are no other events causing a refresh
28- #define TUNE_HOLDOFF_TIME 90 // Timer to hold off display whilst tuning
2928
3029// =================================
3130// CONSTANTS AND VARIABLES
@@ -80,6 +79,7 @@ int8_t scrollDirection = 1; // Menu scroll direction
8079uint32_t background_timer = millis(); // Background screen refresh timer.
8180uint32_t tuning_timer = millis(); // Tuning hold off timer.
8281bool tuning_flag = false ; // Flag to indicate tuning
82+ uint8_t tuneHoldOff = 90 ; // Timer to hold off display whilst tuning
8383
8484//
8585// Current parameters
@@ -336,32 +336,6 @@ void useBand(const Band *band)
336336 snr = 0 ;
337337}
338338
339- // This function is called by the seek function process.
340- bool checkStopSeeking ()
341- {
342- // Returns true if the user rotates the encoder
343- if (seekStop) return true ;
344-
345- // Checking isPressed without debouncing because this callback
346- // is not invoked often enough to register a click
347- if (pb1.update (digitalRead (ENCODER_PUSH_BUTTON) == LOW, 0 ).isPressed )
348- {
349- // Wait till the button is released, otherwise the main loop will register a click
350- while (pb1.update (digitalRead (ENCODER_PUSH_BUTTON) == LOW).isPressed )
351- delay (100 );
352- return true ;
353- }
354-
355- return false ;
356- }
357-
358- // This function is called by the seek function process.
359- void showFrequencySeek (uint16_t freq)
360- {
361- currentFrequency = freq;
362- drawScreen ();
363- }
364-
365339//
366340// Tune using BFO, using algorithm from Goshante's ATS-20_EX firmware
367341//
@@ -452,6 +426,45 @@ bool updateFrequency(int newFreq, bool wrap)
452426 return true ;
453427}
454428
429+ // This function is called by the seek function process.
430+ bool checkStopSeeking ()
431+ {
432+ // Returns true if the user rotates the encoder
433+ if (seekStop) return true ;
434+
435+ // Checking isPressed without debouncing because this callback
436+ // is not invoked often enough to register a click
437+ if (pb1.update (digitalRead (ENCODER_PUSH_BUTTON) == LOW, 0 ).isPressed )
438+ {
439+ // Wait till the button is released, otherwise the main loop will register a click
440+ while (pb1.update (digitalRead (ENCODER_PUSH_BUTTON) == LOW).isPressed )
441+ delay (100 );
442+ return true ;
443+ }
444+
445+ return false ;
446+ }
447+
448+ // This function is called by the seek function process.
449+ void showFrequencySeek (uint16_t freq)
450+ {
451+ // Check if tuning flag is set
452+ if (tuneHoldOff)
453+ {
454+ if (tuning_flag)
455+ {
456+ if ((millis () - tuning_timer) > tuneHoldOff)
457+ tuning_flag = false ;
458+ }
459+ else
460+ {
461+ tuning_timer = millis ();
462+ tuning_flag = true ;
463+ }
464+ }
465+ currentFrequency = freq;
466+ drawScreen ();
467+ }
455468
456469//
457470// Handle encoder rotation in seek mode
@@ -464,11 +477,12 @@ bool doSeek(int8_t dir)
464477 {
465478 if (isSSB ())
466479 {
467- #ifdef ENABLE_HOLDOFF
468- // Tuning timer to hold off (FM/AM) display updates
469- tuning_flag = true ;
470- tuning_timer = millis ();
471- #endif
480+ if (tuneHoldOff)
481+ {
482+ // Tuning timer to hold off (FM/AM) display updates
483+ tuning_flag = true ;
484+ tuning_timer = millis ();
485+ }
472486
473487 updateBFO (currentBFO + dir * getCurrentStep (true )->step , true );
474488 }
@@ -481,6 +495,7 @@ bool doSeek(int8_t dir)
481495 // Flag is set by rotary encoder and cleared on seek/scan entry
482496 seekStop = false ;
483497 rx.seekStationProgress (showFrequencySeek, checkStopSeeking, dir>0 ? 1 : 0 );
498+ if (tuneHoldOff) tuning_flag = false ;
484499 updateFrequency (rx.getFrequency (), true );
485500 }
486501 }
@@ -518,11 +533,12 @@ bool doTune(int8_t dir, bool fast = false)
518533 //
519534 if (isSSB ())
520535 {
521- #ifdef ENABLE_HOLDOFF
522- // Tuning timer to hold off (SSB) display updates
523- tuning_flag = true ;
524- tuning_timer = millis ();
525- #endif
536+ if (tuneHoldOff)
537+ {
538+ // Tuning timer to hold off (SSB) display updates
539+ tuning_flag = true ;
540+ tuning_timer = millis ();
541+ }
526542
527543 uint32_t step = getCurrentStep (fast)->step ;
528544 uint32_t stepAdjust = (currentFrequency * 1000 + currentBFO) % step;
@@ -536,11 +552,12 @@ bool doTune(int8_t dir, bool fast = false)
536552 //
537553 else
538554 {
539- #ifdef ENABLE_HOLDOFF
540- // Tuning timer to hold off (FM/AM) display updates
541- tuning_flag = true ;
542- tuning_timer = millis ();
543- #endif
555+ if (tuneHoldOff)
556+ {
557+ // Tuning timer to hold off (FM/AM) display updates
558+ tuning_flag = true ;
559+ tuning_timer = millis ();
560+ }
544561
545562 uint16_t step = getCurrentStep (fast)->step ;
546563 uint16_t stepAdjust = currentFrequency % step;
@@ -569,11 +586,12 @@ bool doDigit(int8_t dir)
569586 // SSB tuning
570587 if (isSSB ())
571588 {
572- #ifdef ENABLE_HOLDOFF
573- // Tuning timer to hold off (SSB) display updates
574- tuning_flag = true ;
575- tuning_timer = millis ();
576- #endif
589+ if (tuneHoldOff)
590+ {
591+ // Tuning timer to hold off (SSB) display updates
592+ tuning_flag = true ;
593+ tuning_timer = millis ();
594+ }
577595
578596 updated = updateBFO (currentBFO + dir * getFreqInputStep (), false );
579597 }
@@ -583,11 +601,12 @@ bool doDigit(int8_t dir)
583601 //
584602 else
585603 {
586- #ifdef ENABLE_HOLDOFF
587- // Tuning timer to hold off (FM/AM) display updates
588- tuning_flag = true ;
589- tuning_timer = millis ();
590- #endif
604+ if (tuneHoldOff)
605+ {
606+ // Tuning timer to hold off (FM/AM) display updates
607+ tuning_flag = true ;
608+ tuning_timer = millis ();
609+ }
591610
592611 // Tune to a new frequency
593612 updated = updateFrequency (currentFrequency + getFreqInputStep () * dir, false );
@@ -913,14 +932,12 @@ void loop()
913932 // Tick NETWORK time, connecting to WiFi if requested
914933 netTickTime ();
915934
916- #ifdef ENABLE_HOLDOFF
917935 // Check if tuning flag is set
918- if (tuning_flag && ((currentTime - tuning_timer) > TUNE_HOLDOFF_TIME ))
936+ if (tuneHoldOff && tuning_flag && ((currentTime - tuning_timer) > tuneHoldOff ))
919937 {
920938 tuning_flag = false ;
921939 needRedraw = true ;
922940 }
923- #endif
924941
925942 // Run clock
926943 needRedraw |= clockTickTime ();
0 commit comments