Auto Offset / Filter now independent
This commit is contained in:
@@ -643,10 +643,10 @@ void frskyDSetDefault(int index, uint16_t id)
|
||||
if (id >= D_A1_ID && id <= D_A2_ID) {
|
||||
telemetrySensor.prec = 1;
|
||||
telemetrySensor.custom.ratio = 132;
|
||||
telemetrySensor.inputFlags = TELEM_INPUT_FLAGS_FILTERING;
|
||||
telemetrySensor.filter = 1;
|
||||
}
|
||||
else if (id == D_RSSI_ID) {
|
||||
telemetrySensor.inputFlags = TELEM_INPUT_FLAGS_FILTERING;
|
||||
telemetrySensor.filter = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -254,7 +254,7 @@ void frskySportSetDefault(int index, uint16_t id, uint8_t instance)
|
||||
telemetrySensor.init(sensor->name, unit, prec);
|
||||
if (id >= ADC1_ID && id <= BATT_ID) {
|
||||
telemetrySensor.custom.ratio = 132;
|
||||
telemetrySensor.inputFlags = TELEM_INPUT_FLAGS_FILTERING;
|
||||
telemetrySensor.filter = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -143,28 +143,28 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t newVal, uin
|
||||
}
|
||||
else {
|
||||
newVal = sensor.getValue(newVal, unit, prec);
|
||||
if (sensor.inputFlags == TELEM_INPUT_FLAGS_AUTO_OFFSET) {
|
||||
if (sensor.autoOffset) {
|
||||
if (!isAvailable()) {
|
||||
offsetAuto = -newVal;
|
||||
std.offsetAuto = -newVal;
|
||||
}
|
||||
newVal += offsetAuto;
|
||||
newVal += std.offsetAuto;
|
||||
}
|
||||
else if (sensor.inputFlags == TELEM_INPUT_FLAGS_FILTERING) {
|
||||
else if (sensor.filter) {
|
||||
if (!isAvailable()) {
|
||||
for (int i=0; i<TELEMETRY_AVERAGE_COUNT; i++) {
|
||||
filterValues[i] = newVal;
|
||||
std.filterValues[i] = newVal;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// calculate the average from values[] and value
|
||||
// also shift readings in values [] array
|
||||
unsigned int sum = filterValues[0];
|
||||
unsigned int sum = std.filterValues[0];
|
||||
for (int i=0; i<TELEMETRY_AVERAGE_COUNT-1; i++) {
|
||||
int32_t tmp = filterValues[i+1];
|
||||
filterValues[i] = tmp;
|
||||
int32_t tmp = std.filterValues[i+1];
|
||||
std.filterValues[i] = tmp;
|
||||
sum += tmp;
|
||||
}
|
||||
filterValues[TELEMETRY_AVERAGE_COUNT-1] = newVal;
|
||||
std.filterValues[TELEMETRY_AVERAGE_COUNT-1] = newVal;
|
||||
sum += newVal;
|
||||
newVal = sum/(TELEMETRY_AVERAGE_COUNT+1);
|
||||
}
|
||||
|
||||
@@ -97,8 +97,10 @@ class TelemetryItem
|
||||
uint8_t lastReceived; // for detection of sensor loss
|
||||
|
||||
union {
|
||||
int32_t offsetAuto;
|
||||
int32_t filterValues[TELEMETRY_AVERAGE_COUNT];
|
||||
struct {
|
||||
int32_t offsetAuto;
|
||||
int32_t filterValues[TELEMETRY_AVERAGE_COUNT];
|
||||
} std;
|
||||
struct {
|
||||
uint16_t prescale;
|
||||
} consumption;
|
||||
|
||||
Reference in New Issue
Block a user