122,8 → 122,12 |
|
// Value of AIRPRESSURE_OVERSAMPLING samples, with range, filtered. |
int32_t filteredAirPressure; |
int32_t lastFilteredAirPressure; |
|
#define MAX_D_AIRPRESSURE_WINDOW_LENGTH 5 |
//int32_t lastFilteredAirPressure; |
int16_t dAirPressureWindow[MAX_D_AIRPRESSURE_WINDOW_LENGTH]; |
uint8_t dWindowPtr; |
|
#define MAX_AIRPRESSURE_WINDOW_LENGTH 32 |
int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH]; |
int32_t windowedAirPressure; |
474,9 → 478,8 |
// The best oversampling count is 14.5. We add a quarter of the double ADC value to get the final half. |
airPressureSum += simpleAirPressure >> 2; |
|
lastFilteredAirPressure = filteredAirPressure; |
uint32_t lastFilteredAirPressure = filteredAirPressure; |
|
|
if (!staticParams.airpressureWindowLength) { |
filteredAirPressure = (filteredAirPressure * (staticParams.airpressureFilterConstant - 1) |
+ airPressureSum + staticParams.airpressureFilterConstant / 2) / staticParams.airpressureFilterConstant; |
484,11 → 487,14 |
// use windowed. |
windowedAirPressure += simpleAirPressure; |
windowedAirPressure -= airPressureWindow[windowPtr]; |
airPressureWindow[windowPtr] = simpleAirPressure; |
windowPtr = (windowPtr+1) % staticParams.airpressureWindowLength; |
airPressureWindow[windowPtr++] = simpleAirPressure; |
if (windowPtr == staticParams.airpressureWindowLength) windowPtr = 0; |
filteredAirPressure = windowedAirPressure / staticParams.airpressureWindowLength; |
} |
|
dAirPressureWindow[dWindowPtr++] = (int16_t)(filteredAirPressure - lastFilteredAirPressure); |
if (dWindowPtr == staticParams.dAirpressureWindowLength) dWindowPtr = 0; |
|
pressureMeasurementCount = airPressureSum = 0; |
} |
} |
617,6 → 623,11 |
} |
|
int16_t analog_getDHeight(void) { |
int16_t result = 0; |
for (int i=0; i<staticParams.dAirpressureWindowLength; i++) { |
result += dAirPressureWindow[i]; |
} |
|
// dHeight = -dPressure, so here it is the old pressure minus the current, not opposite. |
return lastFilteredAirPressure - filteredAirPressure; |
return result; |
} |