Subversion Repositories FlightCtrl

Rev

Rev 2033 | Rev 2036 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2033 Rev 2035
Line 498... Line 498...
498
    } else {
498
    } else {
499
      // normal case.
499
      // normal case.
500
      // If AIRPRESSURE_OVERSAMPLING is an odd number we only want to add half the double sample.
500
      // If AIRPRESSURE_OVERSAMPLING is an odd number we only want to add half the double sample.
501
      // The 2 cases above (end of range) are ignored for this.
501
      // The 2 cases above (end of range) are ignored for this.
502
      debugOut.digital[1] &= ~DEBUG_SENSORLIMIT;
502
      debugOut.digital[1] &= ~DEBUG_SENSORLIMIT;
503
      if (pressureMeasurementCount == AIRPRESSURE_OVERSAMPLING - 1)
-
 
504
        airPressureSum += simpleAirPressure / 2;
-
 
505
      else
-
 
506
        airPressureSum += simpleAirPressure;
503
          airPressureSum += simpleAirPressure;
507
    }
504
    }
Line 508... Line 505...
508
   
505
   
509
    // 2 samples were added.
506
    // 2 samples were added.
-
 
507
    pressureMeasurementCount += 2;
510
    pressureMeasurementCount += 2;
508
    // Assumption here: AIRPRESSURE_OVERSAMPLING is even (well we all know it's 14 haha...)
-
 
509
    if (pressureMeasurementCount == AIRPRESSURE_OVERSAMPLING) {
-
 
510
 
-
 
511
      // The best oversampling count is 14.5. We add a quarter of the double ADC value to get the final half.
-
 
512
      airPressureSum += simpleAirPressure >> 2;
511
    if (pressureMeasurementCount >= AIRPRESSURE_OVERSAMPLING) {
513
 
-
 
514
      lastFilteredAirPressure = filteredAirPressure;
-
 
515
 
512
      lastFilteredAirPressure = filteredAirPressure;
516
      if (!staticParams.airpressureWindowLength) {
513
      filteredAirPressure = (filteredAirPressure * (AIRPRESSURE_FILTER - 1)
517
          filteredAirPressure = (filteredAirPressure * (staticParams.airpressureFilterConstant - 1)
-
 
518
                          + airPressureSum + staticParams.airpressureFilterConstant / 2) / staticParams.airpressureFilterConstant;
-
 
519
      } else {
-
 
520
          // use windowed.
-
 
521
          filteredAirPressure = windowedAirPressure / staticParams.airpressureWindowLength;
514
                             + airPressureSum + AIRPRESSURE_FILTER / 2) / AIRPRESSURE_FILTER;
522
      }
515
      pressureMeasurementCount = airPressureSum = 0;
523
      pressureMeasurementCount = airPressureSum = 0;
516
    }
524
    }
517
    //int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
525
    //int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
518
    //int32_t windowedAirPressure = 0;
526
    //int32_t windowedAirPressure = 0;
519
    //uint8_t windowPtr;
527
    //uint8_t windowPtr;
520
    windowedAirPressure += simpleAirPressure;
528
    windowedAirPressure += simpleAirPressure;
521
    windowedAirPressure -= airPressureWindow[windowPtr];
529
    windowedAirPressure -= airPressureWindow[windowPtr];
522
    airPressureWindow[windowPtr] = simpleAirPressure;
530
    airPressureWindow[windowPtr] = simpleAirPressure;
523
    windowPtr = (windowPtr+1) % MAX_AIRPRESSURE_WINDOW_LENGTH;
531
    windowPtr = (windowPtr+1) % staticParams.airpressureWindowLength;
524
  }
532
  }
Line 525... Line 533...
525
}
533
}
526
 
534