 uint16_t readRSSI()
 {
 #ifdef USE_DIVERSITY
-  return readRSSI(-1);
+    return readRSSI(-1);
 }
 uint16_t readRSSI(char receiver)
 {
 #endif
-  int rssi = 0;
-  int rssiA = 0;
-
-#ifdef USE_DIVERSITY
-  int rssiB = 0;
-#endif
-  for (uint8_t i = 0; i < RSSI_READS; i++)
-  {
-    analogRead(rssiPinA);
-    rssiA += analogRead(rssiPinA);//random(RSSI_MAX_VAL-200, RSSI_MAX_VAL);//
-
-#ifdef USE_DIVERSITY
-    analogRead(rssiPinB);
-    rssiB += analogRead(rssiPinB);//random(RSSI_MAX_VAL-200, RSSI_MAX_VAL);//
+    int rssi = 0;
+    int rssiA = 0;
+
+#ifdef USE_DIVERSITY
+    int rssiB = 0;
+#endif
+    for (uint8_t i = 0; i < RSSI_READS; i++)  {
+        analogRead(rssiPinA);
+        rssiA += analogRead(rssiPinA);//random(RSSI_MAX_VAL-200, RSSI_MAX_VAL);//
+
+#ifdef USE_DIVERSITY
+        analogRead(rssiPinB);
+        rssiB += analogRead(rssiPinB);//random(RSSI_MAX_VAL-200, RSSI_MAX_VAL);//
 #endif
 
 
 
 #ifdef Debug
-    rssiB += 1;// random(RSSI_MAX_VAL - 200, RSSI_MAX_VAL); //
-#endif
-
-
-  }
-  rssiA = rssiA / RSSI_READS; // average of RSSI_READS readings
-
-#ifdef USE_DIVERSITY
-  rssiB = rssiB / RSSI_READS; // average of RSSI_READS readings
-#endif
-  // special case for RSSI setup
-  if (state == STATE_RSSI_SETUP)
-  { // RSSI setup
-    if (rssiA < rssi_setup_min_a)
-    {
-      rssi_setup_min_a = rssiA;
-    }
-    if (rssiA > rssi_setup_max_a)
-    {
-      rssi_setup_max_a = rssiA;
-    }
-
-#ifdef USE_DIVERSITY
-    if (rssiB < rssi_setup_min_b)
-    {
-      rssi_setup_min_b = rssiB;
-    }
-    if (rssiB > rssi_setup_max_b)
-    {
-      rssi_setup_max_b = rssiB;
-    }
-#endif
-  }
-
-  rssiA = map(rssiA, rssi_min_a, rssi_max_a , 1, 100);   // scale from 1..100%
-#ifdef USE_DIVERSITY
-  rssiB = map(rssiB, rssi_min_b, rssi_max_b , 1, 100);   // scale from 1..100%
-  if (receiver == -1) // no receiver was chosen using diversity
-  {
-    switch (diversity_mode)
-    {
-      case useReceiverAuto:
-        // select receiver
-        if ((int)abs((float)(((float)rssiA - (float)rssiB) / (float)rssiB) * 100.0) >= DIVERSITY_CUTOVER)
-        {
-          if (rssiA > rssiB && diversity_check_count > 0)
-          {
-            diversity_check_count--;
-          }
-          if (rssiA < rssiB && diversity_check_count < DIVERSITY_MAX_CHECKS)
-          {
-            diversity_check_count++;
-          }
-          // have we reached the maximum number of checks to switch receivers?
-          if (diversity_check_count == 0 || diversity_check_count >= DIVERSITY_MAX_CHECKS) {
-            receiver = (diversity_check_count == 0) ? useReceiverA : useReceiverB;
-          }
-          else {
-            receiver = active_receiver;
-          }
-        }
-        else {
-          receiver = active_receiver;
-        }
-        break;
-      case useReceiverB:
-        receiver = useReceiverB;
-        break;
-      case useReceiverA:
-      default:
-        receiver = useReceiverA;
-    }
+        rssiB += 1;// random(RSSI_MAX_VAL - 200, RSSI_MAX_VAL); //
+#endif
+
+
+    }
+    rssiA = rssiA / RSSI_READS; // average of RSSI_READS readings
+
+#ifdef USE_DIVERSITY
+    rssiB = rssiB / RSSI_READS; // average of RSSI_READS readings
+#endif
+    // special case for RSSI setup
+    if (state == STATE_RSSI_SETUP)  { // RSSI setup
+        if (rssiA < rssi_setup_min_a)    {
+            rssi_setup_min_a = rssiA;
+        }
+        if (rssiA > rssi_setup_max_a)    {
+            rssi_setup_max_a = rssiA;
+        }
+
+#ifdef USE_DIVERSITY
+        if (rssiB < rssi_setup_min_b)    {
+            rssi_setup_min_b = rssiB;
+        }
+        if (rssiB > rssi_setup_max_b)    {
+            rssi_setup_max_b = rssiB;
+        }
+#endif
+    }
+
+    rssiA = map(rssiA, rssi_min_a, rssi_max_a , 1, 100);   // scale from 1..100%
+#ifdef USE_DIVERSITY
+    rssiB = map(rssiB, rssi_min_b, rssi_max_b , 1, 100);   // scale from 1..100%
+    if (receiver == -1) // no receiver was chosen using diversity  {
+        switch (diversity_mode)    {
+        case useReceiverAuto:
+            // select receiver
+            if ((int)abs((float)(((float)rssiA - (float)rssiB) / (float)rssiB) * 100.0) >= DIVERSITY_CUTOVER)        {
+                if (rssiA > rssiB && diversity_check_count > 0)          {
+                    diversity_check_count--;
+                }
+                if (rssiA < rssiB && diversity_check_count < DIVERSITY_MAX_CHECKS)          {
+                    diversity_check_count++;
+                }
+                // have we reached the maximum number of checks to switch receivers?
+                if (diversity_check_count == 0 || diversity_check_count >= DIVERSITY_MAX_CHECKS) {
+                    receiver = (diversity_check_count == 0) ? useReceiverA : useReceiverB;
+                }
+                else {
+                    receiver = active_receiver;
+                }
+            }
+            else {
+                receiver = active_receiver;
+            }
+            break;
+        case useReceiverB:
+            receiver = useReceiverB;
+            break;
+        case useReceiverA:
+        default:
+            receiver = useReceiverA;
+        }
     // set the antenna LED and switch the video
     setReceiver(receiver);
-  }
-#endif
-
-#ifdef USE_DIVERSITY
-  if (receiver == useReceiverA || state == STATE_RSSI_SETUP)
-  {
+}
+#endif
+
+#ifdef USE_DIVERSITY
+if (receiver == useReceiverA || state == STATE_RSSI_SETUP)  {
 #endif
     rssi = rssiA;
 #ifdef USE_DIVERSITY
-  }
-  else {
+}  else {
     rssi = rssiB;
-  }
-#endif
-
-
-  //SEND RSSI FEEDBACK
-  if ( (( time_screen_saver2 != 0 &&  time_screen_saver2 + 8000 < millis()))   && (  state == STATE_SCREEN_SAVER) )
-  {
-    if ((p_active_receiver != active_receiver )  || ((rssi - 60 > p_rssi) ||  (rssi + 60 < p_rssi)))
-    { p_active_receiver = active_receiver;
-      p_rssi = rssi ;
-      OSDParams[0] = rssiA; //rssiA; //this is  A
-      OSDParams[1] = rssiB; //rssiB; //this is  B
-      OSDParams[2] = receiver; //active_receiver; //CUrrent reciever
-      OSDParams[3] = -1; //THIS is for rssi method
-      SendToOSD();
-      time_screen_saver2 = 1;
-    }
-  }
-
-  return constrain(rssi, 1, 100); // clip values to only be within this range.
+}
+#endif
+
+
+//SEND RSSI FEEDBACK
+if ( (( time_screen_saver2 != 0 &&  time_screen_saver2 + 8000 < millis()))   && (  state == STATE_SCREEN_SAVER) )  {
+    if ((p_active_receiver != active_receiver )  || ((rssi - 60 > p_rssi) ||  (rssi + 60 < p_rssi)))     {
+        p_active_receiver = active_receiver;
+        p_rssi = rssi ;
+        OSDParams[0] = rssiA; //rssiA; //this is  A
+        OSDParams[1] = rssiB; //rssiB; //this is  B
+        OSDParams[2] = receiver; //active_receiver; //CUrrent reciever
+        OSDParams[3] = -1; //THIS is for rssi method
+        SendToOSD();
+        time_screen_saver2 = 1;
+    }
+}
+
+return constrain(rssi, 1, 100); // clip values to only be within this range.
 }
 
 void setReceiver(uint8_t receiver) {
 #ifdef USE_DIVERSITY
-  if (receiver == useReceiverA)
-  {
+    if (receiver == useReceiverA)  {
 #ifdef USE_FAST_SWITCHING
-    PORTC = (PORTC & B11111101) | B00000001; //This turns off receiverB_led and turns on receiverA_led simultaniously, this does however breaks the adaptability of receiverA_led/receiverB_led in settings.h
+        PORTC = (PORTC & B11111101) | B00000001; //This turns off receiverB_led and turns on receiverA_led simultaniously, this does however breaks the adaptability of receiverA_led/receiverB_led in settings.h
 #else
-    digitalWrite(receiverB_led, LOW);
-    digitalWrite(receiverA_led, HIGH);
-#endif
-  }
-  else
-  {
-#ifdef USE_FAST_SWITCHING
-    PORTC = (PORTC & B11111110) | B00000010; //This turns off receiverA_led and turns on receiverB_led simultaniously
-#else
-    digitalWrite(receiverA_led, LOW);
-    digitalWrite(receiverB_led, HIGH);
-#endif
-  }
-#else
-  digitalWrite(receiverA_led, HIGH);
-#endif
-
-  active_receiver = receiver;
-}
-
-
-
-void setChannelModule(uint8_t channel)
-{
-  uint8_t i;
-  uint16_t channelData;
-
-  channelData = pgm_read_word_near(channelTable + channel);
-
-  // bit bash out 25 bits of data
-  // Order: A0-3, !R/W, D0-D19
-  // A0=0, A1=0, A2=0, A3=1, RW=0, D0-19=0
-  SERIAL_ENABLE_HIGH();
-  delayMicroseconds(1);
-  //delay(2);
-  SERIAL_ENABLE_LOW();
-
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT1();
-
-  SERIAL_SENDBIT0();
-
-  // remaining zeros
-  for (i = 20; i > 0; i--)
-    SERIAL_SENDBIT0();
-
-  // Clock the data in
-  SERIAL_ENABLE_HIGH();
-  //delay(2);
-  delayMicroseconds(1);
-  SERIAL_ENABLE_LOW();
-
-  // Second is the channel data from the lookup table
-  // 20 bytes of register data are sent, but the MSB 4 bits are zeros
-  // register address = 0x1, write, data0-15=channelData data15-19=0x0
-  SERIAL_ENABLE_HIGH();
-  SERIAL_ENABLE_LOW();
-
-  // Register 0x1
-  SERIAL_SENDBIT1();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-  SERIAL_SENDBIT0();
-
-  // Write to register
-  SERIAL_SENDBIT1();
-
-  // D0-D15
-  //   note: loop runs backwards as more efficent on AVR
-  for (i = 16; i > 0; i--)
-  {
-    // Is bit high or low?
-    if (channelData & 0x1)
-    {
-      SERIAL_SENDBIT1();
+        digitalWrite(receiverB_led, LOW);
+        digitalWrite(receiverA_led, HIGH);
+#endif
     }
     else
     {
-      SERIAL_SENDBIT0();
-    }
-
-    // Shift bits along to check the next one
-    channelData >>= 1;
-  }
-
-  // Remaining D16-D19
-  for (i = 4; i > 0; i--)
+#ifdef USE_FAST_SWITCHING
+        PORTC = (PORTC & B11111110) | B00000010; //This turns off receiverA_led and turns on receiverB_led simultaniously
+#else
+        digitalWrite(receiverA_led, LOW);
+        digitalWrite(receiverB_led, HIGH);
+#endif
+    }
+#else
+    digitalWrite(receiverA_led, HIGH);
+#endif
+
+    active_receiver = receiver;
+}
+
+
+
+void setChannelModule(uint8_t channel) {
+    uint8_t i;
+    uint16_t channelData;
+
+    channelData = pgm_read_word_near(channelTable + channel);
+
+    // bit bash out 25 bits of data
+    // Order: A0-3, !R/W, D0-D19
+    // A0=0, A1=0, A2=0, A3=1, RW=0, D0-19=0
+    SERIAL_ENABLE_HIGH();
+    delayMicroseconds(1);
+    //delay(2);
+    SERIAL_ENABLE_LOW();
+
     SERIAL_SENDBIT0();
-
-  // Finished clocking data in
-  SERIAL_ENABLE_HIGH();
-  delayMicroseconds(1);
-  //delay(2);
-
-  digitalWrite(slaveSelectPin, LOW);
-  digitalWrite(spiClockPin, LOW);
-  digitalWrite(spiDataPin, LOW);
-}
-
-
-void SERIAL_SENDBIT1()
-{
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(1);
-
-  digitalWrite(spiDataPin, HIGH);
-  delayMicroseconds(1);
-  digitalWrite(spiClockPin, HIGH);
-  delayMicroseconds(1);
-
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(1);
-}
-
-void SERIAL_SENDBIT0()
-{
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(1);
-
-  digitalWrite(spiDataPin, LOW);
-  delayMicroseconds(1);
-  digitalWrite(spiClockPin, HIGH);
-  delayMicroseconds(1);
-
-  digitalWrite(spiClockPin, LOW);
-  delayMicroseconds(1);
-}
-
-void SERIAL_ENABLE_LOW()
-{
-  delayMicroseconds(1);
-  digitalWrite(slaveSelectPin, LOW);
-  delayMicroseconds(1);
-}
-
-void SERIAL_ENABLE_HIGH()
-{
-  delayMicroseconds(1);
-  digitalWrite(slaveSelectPin, HIGH);
-  delayMicroseconds(1);
+    SERIAL_SENDBIT0();
+    SERIAL_SENDBIT0();
+    SERIAL_SENDBIT1();
+
+    SERIAL_SENDBIT0();
+
+    // remaining zeros
+    for (i = 20; i > 0; i--)
+        SERIAL_SENDBIT0();
+
+    // Clock the data in
+    SERIAL_ENABLE_HIGH();
+    //delay(2);
+    delayMicroseconds(1);
+    SERIAL_ENABLE_LOW();
+
+    // Second is the channel data from the lookup table
+    // 20 bytes of register data are sent, but the MSB 4 bits are zeros
+    // register address = 0x1, write, data0-15=channelData data15-19=0x0
+    SERIAL_ENABLE_HIGH();
+    SERIAL_ENABLE_LOW();
+
+    // Register 0x1
+    SERIAL_SENDBIT1();
+    SERIAL_SENDBIT0();
+    SERIAL_SENDBIT0();
+    SERIAL_SENDBIT0();
+
+    // Write to register
+    SERIAL_SENDBIT1();
+
+    // D0-D15
+    //   note: loop runs backwards as more efficent on AVR
+    for (i = 16; i > 0; i--)  {
+        // Is bit high or low?
+        if (channelData & 0x1)    {
+            SERIAL_SENDBIT1();
+        }
+        else    {
+            SERIAL_SENDBIT0();
+        }
+
+        // Shift bits along to check the next one
+        channelData >>= 1;
+    }
+
+    // Remaining D16-D19
+    for (i = 4; i > 0; i--)
+        SERIAL_SENDBIT0();
+
+    // Finished clocking data in
+    SERIAL_ENABLE_HIGH();
+    delayMicroseconds(1);
+    //delay(2);
+
+    digitalWrite(slaveSelectPin, LOW);
+    digitalWrite(spiClockPin, LOW);
+    digitalWrite(spiDataPin, LOW);
+}
+
+
+void SERIAL_SENDBIT1() {
+    digitalWrite(spiClockPin, LOW);
+    delayMicroseconds(1);
+
+    digitalWrite(spiDataPin, HIGH);
+    delayMicroseconds(1);
+    digitalWrite(spiClockPin, HIGH);
+    delayMicroseconds(1);
+
+    digitalWrite(spiClockPin, LOW);
+    delayMicroseconds(1);
+}
+
+void SERIAL_SENDBIT0() {
+    digitalWrite(spiClockPin, LOW);
+    delayMicroseconds(1);
+
+    digitalWrite(spiDataPin, LOW);
+    delayMicroseconds(1);
+    digitalWrite(spiClockPin, HIGH);
+    delayMicroseconds(1);
+
+    digitalWrite(spiClockPin, LOW);
+    delayMicroseconds(1);
+}
+
+void SERIAL_ENABLE_LOW() {
+    delayMicroseconds(1);
+    digitalWrite(slaveSelectPin, LOW);
+    delayMicroseconds(1);
+}
+
+void SERIAL_ENABLE_HIGH() {
+    delayMicroseconds(1);
+    digitalWrite(slaveSelectPin, HIGH);
+    delayMicroseconds(1);
 }
 
 
 void FillTemp_Tune_fav(int FavChannelx) {
-  for (int i = 0; i < 10; i++)
-  {
-    if ( temp_EEPROM_ADR_TUNE_FAV[i] == 255 && FavChannelx != 255) //not used  gc9n
-    {
-      temp_EEPROM_ADR_TUNE_FAV[i] = FavChannelx;
-      i = 12;
-    }
-
-  }
+    for (int i = 0; i < 10; i++)  {
+        if ( temp_EEPROM_ADR_TUNE_FAV[i] == 255 && FavChannelx != 255) //not used  gc9n    {
+            temp_EEPROM_ADR_TUNE_FAV[i] = FavChannelx;
+        i = 12;
+    }
+}
 }
 
 void SendToOSD() //GC9N
 {
-  if (settings_OSD == true || OSDParams[0] == -99 )
-  {
-    char one[5]  ;
-    char two[5] ;
-    char three[5] ;
-    char four[5] ;
-    char blank[5] = " " ;
-    char combined[20] = {0};
-
-
-    itoa(OSDParams[0], one, 10);
-    itoa(OSDParams[1], two, 10);
-    itoa(OSDParams[2], three, 10);
-    itoa(OSDParams[3], four, 10);
-
-    char ClearScreen[20] = " CLEAR ";
-    char RssiScreen[20] = " DRAWRSSI";
-
-    strcat(combined, OSDCommand);
-
-    if (OSDParams[0] == -99) // CLEARSCREEN
-    {
-      for (uint8_t i = 0; i < 20; i++)
-      {
-        combined[i] = ClearScreen[i];
-      }
-    }
-
-    if (OSDParams[3] == -1) // DRAW_RSSI
-    {
-      for (uint8_t i = 0; i < 20; i++)
-      {
-        combined[i] = RssiScreen[i];
-      }
-    }
-
-    strcat(combined, blank);
-    strcat(combined, one);
-    strcat(combined, blank);
-    strcat(combined, two);
-    strcat(combined, blank);
-    strcat(combined, three);
-
-
-    Serial.println(combined);
-    OSDParams[3] = 0;
-
-  }
+    if (settings_OSD == true || OSDParams[0] == -99 )  {
+        char one[5]  ;
+        char two[5] ;
+        char three[5] ;
+        char four[5] ;
+        char blank[5] = " " ;
+        char combined[20] = {0};
+
+
+        itoa(OSDParams[0], one, 10);
+        itoa(OSDParams[1], two, 10);
+        itoa(OSDParams[2], three, 10);
+        itoa(OSDParams[3], four, 10);
+
+        char ClearScreen[20] = " CLEAR ";
+        char RssiScreen[20] = " DRAWRSSI";
+
+        strcat(combined, OSDCommand);
+
+        if (OSDParams[0] == -99) // CLEARSCREEN    {
+            for (uint8_t i = 0; i < 20; i++)      {
+                combined[i] = ClearScreen[i];
+            }
+    }
+
+    if (OSDParams[3] == -1) // DRAW_RSSI    {
+        for (uint8_t i = 0; i < 20; i++)      {
+            combined[i] = RssiScreen[i];
+        }
+}
+
+strcat(combined, blank);
+strcat(combined, one);
+strcat(combined, blank);
+strcat(combined, two);
+strcat(combined, blank);
+strcat(combined, three);
+
+
+Serial.println(combined);
+OSDParams[3] = 0;
+
+}
 }
 
 int8_t FSButtonDirection () //gc9n
 {
-  char dir; //1 UP 2 DOWN
-  while ( Serial.available() > 0) {
-
-    dir = Serial.read();
-    if (dir == ']')
-    {
-      FS_BUTTON_DIR = 2;
-      return 2;
-    }
-
-    else if (dir == '[')
-    {
-      FS_BUTTON_DIR = 1;
-      return 1;
-    }
-
-    else
-    { FS_BUTTON_DIR = 0;
-      return 0;
-    }
-  }
-
-}
+    char dir; //1 UP 2 DOWN
+    while ( Serial.available() > 0) {
+
+        dir = Serial.read();
+        if (dir == ']')    {
+            FS_BUTTON_DIR = 2;
+            return 2;
+        }
+
+        else if (dir == '[')    {
+            FS_BUTTON_DIR = 1;
+            return 1;
+        }
+
+        else {
+            FS_BUTTON_DIR = 0;
+            return 0;
+        }
+    }
+
+}

#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));
#else
      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) {
    // 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
    }
    while (in_menu);

    state = state_last_used;
  }
#endif
  if (state != STATE_FAVORITE)
  {
    RefreshFav = false;
  }
  /*****************************************/
  /*   Processing FAVORITES                */
  /*****************************************/
  if (state == STATE_FAVORITE ) //|| state == STATE_SEEK)
  {

    // read rssi
    wait_rssi_ready();
    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();
        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
      {
        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)) ||
        ((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
  { 
    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[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;
    }

    // print bar for spectrum

    } // end switch

    last_state = state;
}
/*************************************/
/*   Processing depending of state   */
/*************************************/
#ifndef TVOUT_SCREENS
if (state == STATE_SCREEN_SAVER || state == STATE_SCREEN_SAVER_LITE) {


#ifdef USE_DIVERSITY
