Projectkk2glider/issue 3463 negative filtered sensor values (#3469) (ported from master)
* Fixes #3463: negative sensor values were invalid if filter was active for the sensor * Re #3463: enable simultaneous use of `offset` and `filter` (was: when `offset` was enabled, the `filter` was always inactive even if enabled)
This commit is contained in:
@@ -171,16 +171,18 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32
|
|||||||
}
|
}
|
||||||
newVal += std.offsetAuto;
|
newVal += std.offsetAuto;
|
||||||
}
|
}
|
||||||
else if (sensor.filter) {
|
if (sensor.filter) {
|
||||||
if (!isAvailable()) {
|
if (!isAvailable()) {
|
||||||
for (int i=0; i<TELEMETRY_AVERAGE_COUNT; i++) {
|
for (int i=0; i<TELEMETRY_AVERAGE_COUNT; i++) {
|
||||||
std.filterValues[i] = newVal;
|
std.filterValues[i] = newVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// calculate the average from values[] and value
|
// Calculate the average from values[] and value,
|
||||||
// also shift readings in values [] array
|
// also shift readings in values [] array.
|
||||||
unsigned int sum = std.filterValues[0];
|
// There is a possibility of value overflow in `sum` but
|
||||||
|
// in reality no sensor value should be so big to cause it.
|
||||||
|
int32_t sum = std.filterValues[0];
|
||||||
for (int i=0; i<TELEMETRY_AVERAGE_COUNT-1; i++) {
|
for (int i=0; i<TELEMETRY_AVERAGE_COUNT-1; i++) {
|
||||||
int32_t tmp = std.filterValues[i+1];
|
int32_t tmp = std.filterValues[i+1];
|
||||||
std.filterValues[i] = tmp;
|
std.filterValues[i] = tmp;
|
||||||
|
|||||||
Reference in New Issue
Block a user