ModeFilter: Add get() method and support for Float type
This commit is contained in:
parent
9848d05a9d
commit
77877ba5fc
@ -35,9 +35,15 @@ public:
|
|||||||
// apply - Add a new raw value to the filter, retrieve the filtered result
|
// apply - Add a new raw value to the filter, retrieve the filtered result
|
||||||
virtual T apply(T sample);
|
virtual T apply(T sample);
|
||||||
|
|
||||||
|
// get - get latest filtered value from filter (equal to the value returned by latest call to apply method)
|
||||||
|
virtual T get() const {
|
||||||
|
return _output;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// private methods
|
// private methods
|
||||||
uint8_t _return_element;
|
uint8_t _return_element;
|
||||||
|
T _output;
|
||||||
void isort(T sample, bool drop_high_sample);
|
void isort(T sample, bool drop_high_sample);
|
||||||
bool drop_high_sample; // switch to determine whether to drop the highest or lowest sample when new value arrives
|
bool drop_high_sample; // switch to determine whether to drop the highest or lowest sample when new value arrives
|
||||||
};
|
};
|
||||||
@ -63,6 +69,11 @@ typedef ModeFilter<uint16_t,4> ModeFilterUInt16_Size4;
|
|||||||
typedef ModeFilter<uint16_t,5> ModeFilterUInt16_Size5;
|
typedef ModeFilter<uint16_t,5> ModeFilterUInt16_Size5;
|
||||||
typedef ModeFilter<uint16_t,6> ModeFilterUInt16_Size6;
|
typedef ModeFilter<uint16_t,6> ModeFilterUInt16_Size6;
|
||||||
typedef ModeFilter<uint16_t,7> ModeFilterUInt16_Size7;
|
typedef ModeFilter<uint16_t,7> ModeFilterUInt16_Size7;
|
||||||
|
typedef ModeFilter<float,3> ModeFilterFloat_Size3;
|
||||||
|
typedef ModeFilter<float,4> ModeFilterFloat_Size4;
|
||||||
|
typedef ModeFilter<float,5> ModeFilterFloat_Size5;
|
||||||
|
typedef ModeFilter<float,6> ModeFilterFloat_Size6;
|
||||||
|
typedef ModeFilter<float,7> ModeFilterFloat_Size7;
|
||||||
|
|
||||||
// Constructor //////////////////////////////////////////////////////////////
|
// Constructor //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -91,10 +102,10 @@ T ModeFilter<T,FILTER_SIZE>:: apply(T sample)
|
|||||||
// return results
|
// return results
|
||||||
if( FilterWithBuffer<T,FILTER_SIZE>::sample_index < FILTER_SIZE ) {
|
if( FilterWithBuffer<T,FILTER_SIZE>::sample_index < FILTER_SIZE ) {
|
||||||
// middle sample if buffer is not yet full
|
// middle sample if buffer is not yet full
|
||||||
return FilterWithBuffer<T,FILTER_SIZE>::samples[(FilterWithBuffer<T,FILTER_SIZE>::sample_index / 2)];
|
return _output = FilterWithBuffer<T,FILTER_SIZE>::samples[(FilterWithBuffer<T,FILTER_SIZE>::sample_index / 2)];
|
||||||
}else{
|
}else{
|
||||||
// return element specified by user in constructor
|
// return element specified by user in constructor
|
||||||
return FilterWithBuffer<T,FILTER_SIZE>::samples[_return_element];
|
return _output = FilterWithBuffer<T,FILTER_SIZE>::samples[_return_element];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user