diff --git a/libraries/Filter/Filter.h b/libraries/Filter/Filter.h index 8d47ca100f..77ee3c9834 100644 --- a/libraries/Filter/Filter.h +++ b/libraries/Filter/Filter.h @@ -17,13 +17,13 @@ #include #include -#define FILTER_MAX_SAMPLES 6 // max number of samples that can be added to the filter +#define FILTER_MAX_SAMPLES 10 // maximum size of the sample buffer (normally older values will be overwritten as new appear) template class Filter { public: - Filter(uint8_t filter_size); + Filter(uint8_t requested_size); ~Filter(); // apply - Add a new raw value to the filter, retrieve the filtered result @@ -44,8 +44,8 @@ typedef Filter FilterInt16; // Constructor template -Filter::Filter(uint8_t filter_size) : - filter_size(filter_size), sample_index(0) +Filter::Filter(uint8_t requested_size) : + filter_size(requested_size), sample_index(0) { // check filter size if( Filter::filter_size > FILTER_MAX_SAMPLES ) @@ -58,7 +58,7 @@ Filter::Filter(uint8_t filter_size) : reset(); } -// Destructor +// Destructor - THIS SHOULD NEVER BE CALLED OR IT COULD LEAD TO MEMORY FRAGMENTATION template Filter::~Filter() { diff --git a/libraries/Filter/ModeFilter.h b/libraries/Filter/ModeFilter.h index b4613290ae..00137b652e 100644 --- a/libraries/Filter/ModeFilter.h +++ b/libraries/Filter/ModeFilter.h @@ -22,7 +22,7 @@ template class ModeFilter : public Filter { public: - ModeFilter(uint8_t filter_size, uint8_t return_element); + ModeFilter(uint8_t requested_size, uint8_t return_element); // apply - Add a new raw value to the filter, retrieve the filtered result virtual T apply(T sample); @@ -40,14 +40,14 @@ typedef ModeFilter ModeFilterInt16; // Constructor ////////////////////////////////////////////////////////////// template -ModeFilter::ModeFilter(uint8_t filter_size, uint8_t return_element) : - Filter(filter_size), +ModeFilter::ModeFilter(uint8_t requested_size, uint8_t return_element) : + Filter(requested_size), _return_element(return_element), drop_high_sample(true) { // ensure we have a valid return_nth_element value. if not, revert to median - if( _return_element >= filter_size ) - _return_element = filter_size / 2; + if( _return_element >= Filter::filter_size ) + _return_element = Filter::filter_size / 2; }; // Public Methods ////////////////////////////////////////////////////////////// diff --git a/libraries/Filter/SumFilter.h b/libraries/Filter/SumFilter.h index 300124d1c1..cbbbcb6d89 100644 --- a/libraries/Filter/SumFilter.h +++ b/libraries/Filter/SumFilter.h @@ -21,7 +21,7 @@ template class SumFilter : public Filter { public: - SumFilter(uint8_t filter_size) : Filter(filter_size) {}; + SumFilter(uint8_t requested_size) : Filter(requested_size) {}; // apply - Add a new raw value to the filter, retrieve the filtered result virtual T apply(T sample);