Page 341 - 2
P. 341

static uint16_t rvec[RSSI_SMOOTH], rsum, r;


                // http://www.multiwii.com/forum/viewtopic.php?f=8&t=5530
                #if defined(RX_RSSI_CHAN)
                  uint16_t rssi_Input = constrain(rcData[RX_RSSI_CHAN],1000,2000);
                  r = map((uint16_t)rssi_Input , 1000, 2000, 0, 1023);
                #else
                  r = analogRead(RX_RSSI_PIN);
                #endif


                #if RSSI_SMOOTH == 1
                  analog.rssi = r;
                #else
                  rsum += r;
                  rsum -= rvec[ind];
                  rvec[ind++] = r;
                  ind %= RSSI_SMOOTH;
                  r = rsum / RSSI_SMOOTH;
                  analog.rssi = r;
                #endif
               #endif // RX RSSI
               break;
              }
              default: // here analogReader >=4, because of ++ in switch()
              {
                #if defined(VBAT) && defined(VBAT_CELLS)
                  if ( (analogReader<4) || (analogReader>4+VBAT_CELLS_NUM-1) ) break;
                  uint8_t ind = analogReader-4;
                  static uint16_t vbatcells_pins[VBAT_CELLS_NUM] = VBAT_CELLS_PINS;
                  static uint8_t vbatcells_offset[VBAT_CELLS_NUM] = VBAT_CELLS_OFFSETS;
                  static uint8_t vbatcells_div[VBAT_CELLS_NUM] = VBAT_CELLS_DIVS;
                  uint16_t v = analogRead(vbatcells_pins[ind]);
                  analog.vbatcells[ind] = vbatcells_offset[ind] + (v << 2) / vbatcells_div[ind]; // result is Vb
            att in 0.1V steps
                  if (ind == VBAT_CELLS_NUM -1) analog.vbat = analog.vbatcells[ind];
                #endif // VBAT) && defined(VBAT_CELLS)
                break;
              } // end default
              } // end of switch()


            #if defined( POWERMETER_HARD ) && (defined(LOG_VALUES) || defined(LCD_TELEMETRY))
              if (analog.amperage > powerValueMaxMAH) powerValueMaxMAH = analog.amperage;
            #endif


            #if defined(WATTS)


                                                         - 341 -
   336   337   338   339   340   341   342   343   344   345   346