 #endif
     time_screen_saver = millis();
     do {
-      rssi = readRSSI();
-
-      if ( ((time_screen_saver != 0 && time_screen_saver + (SCREENSAVER_TIMEOUT * 1000) < millis())) ) {
-        OSDParams[0] = -99; // CLEAR OSD
-        SendToOSD(); //UPDATE OSD
-        time_screen_saver = 0;
-      }
-
-
-
-#ifdef USE_DIVERSITY
-      drawScreen.updateScreenSaver(active_receiver, rssi, readRSSI(useReceiverA), readRSSI(useReceiverB));
+        rssi = readRSSI();
+
+        if ( ((time_screen_saver != 0 && time_screen_saver + (SCREENSAVER_TIMEOUT * 1000) < millis())) ) {
+            OSDParams[0] = -99; // CLEAR OSD
+            SendToOSD(); //UPDATE OSD
+            time_screen_saver = 0;
+        }
+
+
+
+#ifdef USE_DIVERSITY
+        drawScreen.updateScreenSaver(active_receiver, rssi, readRSSI(useReceiverA), readRSSI(useReceiverB));
 #else
-      drawScreen.updateScreenSaver(rssi);
-#endif
-
-    }
-
-    while ((digitalRead(buttonMode) == HIGH) && (digitalRead(buttonUp) == HIGH) && (digitalRead(buttonDown) == HIGH) &&  FSButtonDirection() == 0); // wait for next button press
+        drawScreen.updateScreenSaver(rssi);
+#endif
+    }
+
+    while ((digitalRead(buttonMode) == HIGH) && (digitalRead(buttonUp) == HIGH)
+            && (digitalRead(buttonDown) == HIGH) &&  FSButtonDirection() == 0); // wait for next button press
     state = state_last_used;
     return;
-  }
-#endif
-
-#ifdef USE_DIVERSITY
-  if (state == STATE_DIVERSITY) {
+}
+#endif
+
+#ifdef USE_DIVERSITY
+if (state == STATE_DIVERSITY) {
     // simple menu
     char menu_id = diversity_mode;
     uint8_t in_menu = 1;
     do {
-      diversity_mode = menu_id;
-      drawScreen.diversity(diversity_mode);
-      do
-      {
-        //delay(10); // timeout delay
-        readRSSI();
-        drawScreen.updateDiversity(active_receiver, readRSSI(useReceiverA), readRSSI(useReceiverB));
-      }
-      while ((digitalRead(buttonMode) == HIGH) && (digitalRead(buttonUp) == HIGH) && (digitalRead(buttonDown) == HIGH) &&  FSButtonDirection() == 0 ); // wait for next mode or time out
-
-      if (digitalRead(buttonMode) == LOW)       // channel UP
-      {
-        in_menu = 0; // exit menu
-      }
-      else if (digitalRead(buttonUp) == LOW || FS_BUTTON_DIR == 1) {
-        menu_id--;
-      }
-      else if (digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2) {
-        menu_id++;
-      }
-
-      if (menu_id > useReceiverB) {
-        menu_id = 0;
-      }
-      if (menu_id < 0) {
-        menu_id = useReceiverB;
-      }
-      beep(50); // beep & debounce
-      delay(KEY_DEBOUNCE); // debounce
+        diversity_mode = menu_id;
+        drawScreen.diversity(diversity_mode);
+        do  {
+            //delay(10); // timeout delay
+            readRSSI();
+            drawScreen.updateDiversity(active_receiver, readRSSI(useReceiverA), readRSSI(useReceiverB));
+        }
+        while ((digitalRead(buttonMode) == HIGH) && (digitalRead(buttonUp) == HIGH) && (digitalRead(buttonDown) == HIGH) &&  FSButtonDirection() == 0 ); // wait for next mode or time out
+
+        if (digitalRead(buttonMode) == LOW)       // channel UP
+        {
+            in_menu = 0; // exit menu
+        }
+        else if (digitalRead(buttonUp) == LOW || FS_BUTTON_DIR == 1) {
+            menu_id--;
+        }
+        else if (digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2) {
+            menu_id++;
+        }
+
+        if (menu_id > useReceiverB) {
+            menu_id = 0;
+        }
+        if (menu_id < 0) {
+            menu_id = useReceiverB;
+        }
+        beep(50); // beep & debounce
+        delay(KEY_DEBOUNCE); // debounce
     }
     while (in_menu);
 
     state = state_last_used;
-  }
-#endif
-  if (state != STATE_FAVORITE)
-  {
+}
+#endif
+if (state != STATE_FAVORITE)  {
     RefreshFav = false;
-  }
-  /*****************************************/
-  /*   Processing FAVORITES                */
-  /*****************************************/
-  if (state == STATE_FAVORITE ) //|| state == STATE_SEEK)
-  {
+}
+/*****************************************/
+/*   Processing FAVORITES                */
+/*****************************************/
+if (state == STATE_FAVORITE ) //|| state == STATE_SEEK)  {
 
     // read rssi
     wait_rssi_ready();
-    rssi = readRSSI();
-    rssi_best = (rssi > rssi_best) ? rssi : rssi_best;
+rssi = readRSSI();
+rssi_best = (rssi > rssi_best) ? rssi : rssi_best;
+time_screen_saver = millis();
+
+
+if (!RefreshFav)    {
+
+    EEPROM.write(EEPROM_ADR_STATE, STATE_FAVORITE);
+    HaveFav = false;
+    for (int i = 0; i < 10; i++)      {
+        //NoFav
+        if (EEPROM.read(EEPROM_ADR_TUNE_FAV[i]) != 255)        {
+            FirstFav = i;
+            HaveFav = true;
+        }
+    }
+    RefreshFav = true;
+    //channel=channel_from_index(channelIndex); // get 0...48 index depending of current channel
+}  // handling of keys
+
+if ( digitalRead(buttonUp) == LOW || FS_BUTTON_DIR == 1)      // channel UP    {
+    delay(KEY_DEBOUNCE); // debounce
+lfavs++;
+if (lfavs > FirstFav) {
+    lfavs = 0;
+}
+channelIndex = EEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) ;
+if (channelIndex != 255)      {
+    drawScreen.FavSel(lfavs + 1);
+    channel = channel_from_index(channelIndex); // get 0...48 index depending of current channel
     time_screen_saver = millis();
-
-
-    if (!RefreshFav)
-    {
-
-      EEPROM.write(EEPROM_ADR_STATE, STATE_FAVORITE);
-      HaveFav = false;
-      for (int i = 0; i < 10; i++)
-      {
-        //NoFav
-        if (EEPROM.read(EEPROM_ADR_TUNE_FAV[i]) != 255)
-        { FirstFav = i;
-          HaveFav = true;
-
-        }
-      }
-      RefreshFav = true;
-      //channel=channel_from_index(channelIndex); // get 0...48 index depending of current channel
-    }  // handling of keys
-
-    if ( digitalRead(buttonUp) == LOW || FS_BUTTON_DIR == 1)      // channel UP
-    {
-      delay(KEY_DEBOUNCE); // debounce
-      lfavs++;
-      if (lfavs > FirstFav) {
-        lfavs = 0;
-      }
-      channelIndex = EEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) ;
-      if (channelIndex != 255)
-      {
-        drawScreen.FavSel(lfavs + 1);
-        channel = channel_from_index(channelIndex); // get 0...48 index depending of current channel
-        time_screen_saver = millis();
-        beep(50); // beep & debounce
-        delay(KEY_DEBOUNCE); // debounce
-        channel > CHANNEL_MAX ? channel = CHANNEL_MIN : false;
-        if (channelIndex > CHANNEL_MAX_INDEX)
-        {
-          channelIndex = CHANNEL_MIN_INDEX;
-        }
-        // drawScreen.seekMode(state);
-        EEPROM.write(EEPROM_ADR_TUNE, channelIndex);
-        //Serial.println(channelIndex);
-      }
-      else
-      {
-        lfavs--;
-      }
-    }
-
-
-    if ( digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2) // channel DOWN
-    {
-
-      delay(KEY_DEBOUNCE); // debounce
-      lfavs--;
-      if (lfavs < 0)
-      {
-        lfavs = FirstFav;
-      }
-
-      channelIndex = EEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) ;
-      if (channelIndex != 255)
-      {
-        drawScreen.FavSel(lfavs + 1);
-        channel = channel_from_index(channelIndex); // get 0...48 index depending of current channel
-        time_screen_saver = millis();
-        beep(50); // beep & debounce
-        delay(KEY_DEBOUNCE); // debounce
-
-        channel < CHANNEL_MIN ? channel = CHANNEL_MAX : false;
-        if (channelIndex > CHANNEL_MAX_INDEX) // negative overflow
-        {
-          channelIndex = CHANNEL_MAX_INDEX;
-        }
-
-        //drawScreen.seekMode(state);
-        EEPROM.write(EEPROM_ADR_TUNE, channelIndex);
-      }
-      else
-      {
-        lfavs++;
-      }
-    }
-
-    if (HaveFav == false)
-    { drawScreen.NoFav();
-
-    }   // IF YOU DONT HAVE FAVS
-
-    else
-    {
-      //delay(KEY_DEBOUNCE); // debounce
-      state = STATE_SCREEN_SAVER;
-    }// IF YOU HAVE FAVS
-
-    OSDParams[0] = 4; //this is FAV menu
-    OSDParams[1] = pgm_read_word_near(channelFreqTable + channelIndex);
-    OSDParams[2] = lfavs + 1;
-    SendToOSD(); //UPDATE OSD
-  }
-
-
-
-  /*****************************************/
-  /*   Processing MANUAL MODE / SEEK MODE  */
-  /*****************************************/
-  if (state == STATE_MANUAL || state == STATE_SEEK)
-  {
+    beep(50); // beep & debounce
+    delay(KEY_DEBOUNCE); // debounce
+    channel > CHANNEL_MAX ? channel = CHANNEL_MIN : false;
+    if (channelIndex > CHANNEL_MAX_INDEX)        {
+        channelIndex = CHANNEL_MIN_INDEX;
+    }
+    // drawScreen.seekMode(state);
+    EEPROM.write(EEPROM_ADR_TUNE, channelIndex);
+    //Serial.println(channelIndex);
+}
+else      {
+    lfavs--;
+}
+}
+
+
+if ( digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2) // channel DOWN    {
+    delay(KEY_DEBOUNCE); // debounce
+lfavs--;
+if (lfavs < 0)      {
+    lfavs = FirstFav;
+}
+
+channelIndex = EEPROM.read(EEPROM_ADR_TUNE_FAV[lfavs]) ;
+if (channelIndex != 255)      {
+    drawScreen.FavSel(lfavs + 1);
+    channel = channel_from_index(channelIndex); // get 0...48 index depending of current channel
+    time_screen_saver = millis();
+    beep(50); // beep & debounce
+    delay(KEY_DEBOUNCE); // debounce
+
+    channel < CHANNEL_MIN ? channel = CHANNEL_MAX : false;
+    if (channelIndex > CHANNEL_MAX_INDEX) // negative overflow        {
+        channelIndex = CHANNEL_MAX_INDEX;
+}
+
+//drawScreen.seekMode(state);
+EEPROM.write(EEPROM_ADR_TUNE, channelIndex);
+}
+else      {
+    lfavs++;
+}
+}
+
+if (HaveFav == false)    {
+    drawScreen.NoFav();
+
+}   // IF YOU DONT HAVE FAVS
+
+else    {
+    //delay(KEY_DEBOUNCE); // debounce
+    state = STATE_SCREEN_SAVER;
+}// IF YOU HAVE FAVS
+
+OSDParams[0] = 4; //this is FAV menu
+OSDParams[1] = pgm_read_word_near(channelFreqTable + channelIndex);
+OSDParams[2] = lfavs + 1;
+SendToOSD(); //UPDATE OSD
+}
+
+
+
+/*****************************************/
+/*   Processing MANUAL MODE / SEEK MODE  */
+/*****************************************/
+if (state == STATE_MANUAL || state == STATE_SEEK)  {
     // read rssi
     wait_rssi_ready();
     rssi = readRSSI();
     FS_BUTTON_DIR = FSButtonDirection();
-    
-    
+
+
     channel = channel_from_index(channelIndex); // get 0...48 index depending of current channel
-    if (state == STATE_MANUAL) // MANUAL MODE
-    {
-
-      OSDParams[0] = 3; //this is MANUAL MODE
-
-      // handling of keys
-      if ( digitalRead(buttonUp) == LOW  || FS_BUTTON_DIR == 1 )       // channel UP
-      {
+    if (state == STATE_MANUAL) // MANUAL MODE    {
+
+        OSDParams[0] = 3; //this is MANUAL MODE
+
+    // handling of keys
+    if ( digitalRead(buttonUp) == LOW  || FS_BUTTON_DIR == 1 )       // channel UP      {
         time_screen_saver = millis();
-        beep(50); // beep & debounce
-        delay(KEY_DEBOUNCE); // debounce
-        FS_BUTTON_DIR=0;
-        channelIndex++;
-        channel++;
-        channel > CHANNEL_MAX ? channel = CHANNEL_MIN : false;
-        if (channelIndex > CHANNEL_MAX_INDEX)
-        {
-          channelIndex = CHANNEL_MIN_INDEX;
-        }
-      }
-      if ( digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2 ) // channel DOWN
-      {
-        time_screen_saver = millis();
-        beep(50); // beep & debounce
-        delay(KEY_DEBOUNCE); // debounce
-        FS_BUTTON_DIR=0;
-        channelIndex--;
-        channel--;
-        channel < CHANNEL_MIN ? channel = CHANNEL_MAX : false;
-        if (channelIndex > CHANNEL_MAX_INDEX) // negative overflow
-        {
-          channelIndex = CHANNEL_MAX_INDEX;
-        }
-      }
-
-     if (OSDParams[1]!=pgm_read_word_near(channelFreqTable + channelIndex))
-        {
-        OSDParams[1]=pgm_read_word_near(channelFreqTable + channelIndex);
-        SendToOSD(); //UPDATE OSD
-
-        }
-        if (!settings_orderby_channel) { // order by frequency
-        channelIndex = pgm_read_byte_near(channelList + channel);
-      }
-
-    }
-
-    // handling for seek mode after screen and RSSI has been fully processed
-    if (state == STATE_SEEK) //
-    { // SEEK MODE
-
-      OSDParams[0] = 2; //this is AUTO MODE
-      // recalculate rssi_seek_threshold
-      ((int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0)) > rssi_seek_threshold) ? (rssi_seek_threshold = (int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0))) : false;
-
-      if (!seek_found) // search if not found
-      {
-        if ((!force_seek) && (rssi > rssi_seek_threshold)) // check for found channel
-        {
-          seek_found = 1;
-          time_screen_saver = millis();
-          // beep twice as notice of lock
-         // beep(100);
-         // delay(100);
-        //  beep(100);
-        }
-        else
-        { // seeking itself
-          force_seek = 0;
-          // next channel
-          channel += seek_direction;
-          if (channel > CHANNEL_MAX)
-          {
-            // calculate next pass new seek threshold
-            rssi_seek_threshold = (int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0));
-            channel = CHANNEL_MIN;
-            rssi_best = 0;
-          }
-          else if (channel < CHANNEL_MIN)
-          {
-            // calculate next pass new seek threshold
-            rssi_seek_threshold = (int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0));
-            channel = CHANNEL_MAX;
-            rssi_best = 0;
-          }
-          rssi_seek_threshold = rssi_seek_threshold < 5 ? 5 : rssi_seek_threshold; // make sure we are not stopping on everyting
-          channelIndex = pgm_read_byte_near(channelList + channel);
-        }
-      }
-      else
-      { // seek was successful
-
-      }
-      FS_BUTTON_DIR = FSButtonDirection();
-      if (digitalRead(buttonUp) == LOW || digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2 || FS_BUTTON_DIR == 1) // restart seek if key pressed
-      {
-        if (digitalRead(buttonUp) == LOW  || FS_BUTTON_DIR == 1 ) {
-          seek_direction = 1;
-        }
-        else
-        {
-          seek_direction = -1;
-        }
-        beep(50); // beep & debounce
-        FS_BUTTON_DIR = 0;
-        delay(KEY_DEBOUNCE); // debounce
-        force_seek = 1;
-        seek_found = 0;
-        time_screen_saver = 0;
-      }
-
-
-   SendToOSD(); //UPDATE OSD
-    } 
-    // change to screensaver after lock and 5 seconds has passed.
-    if (((time_screen_saver + 5000 < millis()) && (time_screen_saver != 0) && (rssi > 50)) ||
+    beep(50); // beep & debounce
+    delay(KEY_DEBOUNCE); // debounce
+    FS_BUTTON_DIR=0;
+    channelIndex++;
+    channel++;
+    channel > CHANNEL_MAX ? channel = CHANNEL_MIN : false;
+    if (channelIndex > CHANNEL_MAX_INDEX)        {
+        channelIndex = CHANNEL_MIN_INDEX;
+    }
+}
+if ( digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2 ) // channel DOWN      {
+    time_screen_saver = millis();
+beep(50); // beep & debounce
+delay(KEY_DEBOUNCE); // debounce
+FS_BUTTON_DIR=0;
+channelIndex--;
+channel--;
+channel < CHANNEL_MIN ? channel = CHANNEL_MAX : false;
+if (channelIndex > CHANNEL_MAX_INDEX) // negative overflow        {
+    channelIndex = CHANNEL_MAX_INDEX;
+}
+}
+
+if (OSDParams[1]!=pgm_read_word_near(channelFreqTable + channelIndex))        {
+    OSDParams[1]=pgm_read_word_near(channelFreqTable + channelIndex);
+    SendToOSD(); //UPDATE OSD
+}
+if (!settings_orderby_channel) { // order by frequency
+    channelIndex = pgm_read_byte_near(channelList + channel);
+}
+
+}
+
+// handling for seek mode after screen and RSSI has been fully processed
+if (state == STATE_SEEK) //    { // SEEK MODE
+
+    OSDParams[0] = 2; //this is AUTO MODE
+// recalculate rssi_seek_threshold
+((int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0)) > rssi_seek_threshold) ? (rssi_seek_threshold = (int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0))) : false;
+
+if (!seek_found) // search if not found      {
+    if ((!force_seek) && (rssi > rssi_seek_threshold)) // check for found channel        {
+        seek_found = 1;
+time_screen_saver = millis();
+// beep twice as notice of lock
+// beep(100);
+// delay(100);
+//  beep(100);
+}
+else        { // seeking itself
+    force_seek = 0;
+    // next channel
+    channel += seek_direction;
+    if (channel > CHANNEL_MAX)          {
+        // calculate next pass new seek threshold
+        rssi_seek_threshold = (int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0));
+        channel = CHANNEL_MIN;
+        rssi_best = 0;
+    }
+    else if (channel < CHANNEL_MIN)          {
+        // calculate next pass new seek threshold
+        rssi_seek_threshold = (int)((float)rssi_best * (float)(RSSI_SEEK_TRESHOLD / 100.0));
+        channel = CHANNEL_MAX;
+        rssi_best = 0;
+    }
+    rssi_seek_threshold = rssi_seek_threshold < 5 ? 5 : rssi_seek_threshold; // make sure we are not stopping on everyting
+    channelIndex = pgm_read_byte_near(channelList + channel);
+}
+}
+else      { // seek was successful
+
+}
+FS_BUTTON_DIR = FSButtonDirection();
+if (digitalRead(buttonUp) == LOW || digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2 || FS_BUTTON_DIR == 1) // restart seek if key pressed      {
+    if (digitalRead(buttonUp) == LOW  || FS_BUTTON_DIR == 1 ) {
+        seek_direction = 1;
+    } else {
+        seek_direction = -1;
+    }
+beep(50); // beep & debounce
+FS_BUTTON_DIR = 0;
+delay(KEY_DEBOUNCE); // debounce
+force_seek = 1;
+seek_found = 0;
+time_screen_saver = 0;
+}
+
+
+SendToOSD(); //UPDATE OSD
+}
+// change to screensaver after lock and 5 seconds has passed.
+if (((time_screen_saver + 5000 < millis()) && (time_screen_saver != 0) && (rssi > 50)) ||
         ((time_screen_saver != 0 && time_screen_saver + (SCREENSAVER_TIMEOUT * 1000) < millis()))) {
-      state = STATE_SCREEN_SAVER;
-      OSDParams[0] = -99; // CLEAR OSD
-      SendToOSD(); //UPDATE OSD
-    }
- 
-    
-  
-   //teza
-     if (last_channel_index != channelIndex)        // tune channel on demand
-  { 
+    state = STATE_SCREEN_SAVER;
+    OSDParams[0] = -99; // CLEAR OSD
+    SendToOSD(); //UPDATE OSD
+}
+
+
+
+//teza
+if (last_channel_index != channelIndex)        // tune channel on demand  {
     drawScreen.updateSeekMode(state, channelIndex, channel, rssi, pgm_read_word_near(channelFreqTable + channelIndex), rssi_seek_threshold, seek_found);
-    OSDParams[1] = pgm_read_word_near(channelFreqTable + channelIndex);
-    SendToOSD(); //UPDATE OSD
-  }
-  }
-  /****************************/
-  /*   Processing SCAN MODE   */
-  /****************************/
-  else if (state == STATE_SCAN || state == STATE_RSSI_SETUP)
-  {
+
+OSDParams[1] = pgm_read_word_near(channelFreqTable + channelIndex);
+SendToOSD(); //UPDATE OSD
+}
+}
+/****************************/
+/*   Processing SCAN MODE   */
+/****************************/
+else if (state == STATE_SCAN || state == STATE_RSSI_SETUP)  {
     OSDParams[0] = -1; //N/A for the moment
     SendToOSD(); //UPDATE OSD
 
     // force tune on new scan start to get right RSSI value
-    if (scan_start)
-    {
-      scan_start = 0;
-      setChannelModule(channelIndex);
-      last_channel_index = channelIndex;
+    if (scan_start)    {
+        scan_start = 0;
+        setChannelModule(channelIndex);
+        last_channel_index = channelIndex;
     }
 
     // print bar for spectrum


// Channels to sent to the SPI registers
const uint16_t channelTable[] PROGMEM = {
  // Channel 1 - 8
  0x2A05,    0x299B,    0x2991,    0x2987,    0x291D,    0x2913,    0x2909,    0x289F,    // Band A
  0x2903,    0x290C,    0x2916,    0x291F,    0x2989,    0x2992,    0x299C,    0x2A05,    // Band B
  0x2895,    0x288B,    0x2881,    0x2817,    0x2A0F,    0x2A19,    0x2A83,    0x2A8D,    // Band E
  0x2906,    0x2910,    0x291A,    0x2984,    0x298E,    0x2998,    0x2A02,    0x2A0C,    // Band F / Airwave
#ifdef USE_LBAND
  0x281d ,   0x2890 ,   0x2902 ,   0x2915 ,   0x2987 ,   0x299a ,  0x2a0c ,    0x2a1f,    // Band C / Immersion Raceband
  0x2609,    0x261C,    0x268E,    0x2701,    0x2713,    0x2786,    0x2798,    0x280B     // Band D / 5.3
#else
  0x281d ,   0x2890 ,   0x2902 ,   0x2915 ,   0x2987 ,   0x299a ,  0x2a0c ,    0x2a1f,    // Band C / Immersion Raceband
#endif
};

// Channels with their Mhz Values
const uint16_t channelFreqTable[] PROGMEM = {
  // Channel 1 - 8
  5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // Band A
  5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // Band B
  5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // Band E
  5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // Band F / Airwave
#ifdef USE_LBAND
  5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, // Band C / Immersion Raceband
  5362, 5399, 5436, 5473, 5510, 5547, 5584, 5621  // Band D / 5.3
#else
  5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917  // Band C / Immersion Raceband
#endif
};

// do coding as simple hex value to save memory.
const uint8_t channelNames[] PROGMEM = {
  0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, // Band A
  0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, // Band B
  0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, // Band E
  0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, // Band F / Airwave
#ifdef USE_LBAND
  0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, // Band C / Immersion Raceband
  0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8  // BAND D / 5.3
#else
  0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8  // Band C / Immersion Raceband
#endif
};

// All Channels of the above List ordered by Mhz
const uint8_t channelList[] PROGMEM = {
#ifdef USE_LBAND
  40, 41, 42, 43, 44, 45, 46, 47, 19, 18, 32, 17, 33, 16, 7, 34, 8, 24, 6, 9, 25, 5, 35, 10, 26, 4, 11, 27, 3, 36, 12, 28, 2, 13, 29, 37, 1, 14, 30, 0, 15, 31, 38, 20, 21, 39, 22, 23
#else
  19, 18, 32, 17, 33, 16, 7, 34, 8, 24, 6, 9, 25, 5, 35, 10, 26, 4, 11, 27, 3, 36, 12, 28, 2, 13, 29, 37, 1, 14, 30, 0, 15, 31, 38, 20, 21, 39, 22, 23
#endif
};


    SendToOSD();
    int editing = -1;
    do {
        in_menu_time_out = 50;
        drawScreen.updateSetupMenu(menu_id, settings_beeps, settings_orderby_channel, call_sign, editing);
        while (--in_menu_time_out && ((digitalRead(buttonMode) == HIGH) && (digitalRead(buttonUp) == HIGH)
                                      && (digitalRead(buttonDown) == HIGH)  && FSButtonDirection() == 0)) // wait for next key press or time out
        {
            delay(100); // timeout delay
        }

        if (in_menu_time_out <= 0 ) {
            state = state_last_used;
            break; // Timed out, Don't save...
        }

        if (digitalRead(buttonMode) == LOW)       // channel UP      {
            // do something about the users selection
            switch (menu_id) {
            case 0: // Channel Order Channel/Frequency
                settings_orderby_channel = !settings_orderby_channel;
                break;
            case 1:// Beeps enable/disable
                settings_beeps = !settings_beeps;
                break;

            case 2:// Edit Call Sign
                editing++;
                if (editing > 9) {
                    editing = -1;
                }
                break;
            case 3:// Calibrate RSSI
                in_menu = 0;
                for (uint8_t loop = 0; loop < 10; loop++)            {
#define RSSI_SETUP_BEEP 25
                    beep(RSSI_SETUP_BEEP); // beep & debounce
                    delay(RSSI_SETUP_BEEP); // debounce
                }
                state = STATE_RSSI_SETUP;
                break;
            case 4:
                in_menu = 0; // save & exit menu
                state = STATE_SAVE;
                break;
            }
    }
    else if (digitalRead(buttonUp) == LOW  || FS_BUTTON_DIR == 1) {
        if (editing == -1) {
            menu_id--;
        }
        else { // change current letter in place
            call_sign[editing]++;
            call_sign[editing] > '}' ? call_sign[editing] = ' ' : false; // loop to oter end
        }

    }
    else if (digitalRead(buttonDown) == LOW || FS_BUTTON_DIR == 2) {
        if (editing == -1) {
            menu_id++;
        }
        else { // change current letter in place
            call_sign[editing]--;
            call_sign[editing] < ' ' ? call_sign[editing] = '}' : false; // loop to oter end
        }
    }

    if (menu_id > 4) {
        menu_id = 0;
    }
    if (menu_id < 0) {
        menu_id = 4;
    }

    OSDParams[0] = 1; //this is main menu
    OSDParams[1] = menu_id + 1; //By defaut=lt goes over manual
    SendToOSD();
    beep(50); // beep & debounce
    do {
        delay(150);// wait for button release
    }
    while (editing == -1 && (digitalRead(buttonMode) == LOW || digitalRead(buttonUp) == LOW
                             || digitalRead(buttonDown) == LOW || FSButtonDirection() == 1 || FSButtonDirection() == 2));
}
while (in_menu);
}

/*****************************/
/*   General house keeping   */
/*****************************/
if (last_channel_index != channelIndex)        // tune channel on demand  {
    setChannelModule(channelIndex);
last_channel_index = channelIndex;
// keep time of tune to make sure that RSSI is stable when required
time_of_tune = millis();
// give 3 beeps when tuned to give feedback of correct start
if (first_tune)    {
    first_tune = 0;
#define UP_BEEP 100
    beep(UP_BEEP);
    delay(UP_BEEP);
    beep(UP_BEEP);
    delay(UP_BEEP);
    beep(UP_BEEP);
}
}
}

/*###########################################################################*/
