From 5948f825ba415ea6d095c6a3693cc89b991e9b59 Mon Sep 17 00:00:00 2001 From: uncrustify Date: Thu, 16 Aug 2012 23:22:11 -0700 Subject: [PATCH] uncrustify libraries/Filter/ModeFilter.h --- libraries/Filter/ModeFilter.h | 114 +++++++++++++++++----------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/libraries/Filter/ModeFilter.h b/libraries/Filter/ModeFilter.h index 4335ad8ae7..fd9ec00ee4 100644 --- a/libraries/Filter/ModeFilter.h +++ b/libraries/Filter/ModeFilter.h @@ -20,17 +20,17 @@ template class ModeFilter : public FilterWithBuffer { - public: - ModeFilter(uint8_t return_element); +public: + ModeFilter(uint8_t return_element); - // apply - Add a new raw value to the filter, retrieve the filtered result - virtual T apply(T sample); + // apply - Add a new raw value to the filter, retrieve the filtered result + virtual T apply(T sample); - private: - // private methods - uint8_t _return_element; - 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 +private: + // private methods + uint8_t _return_element; + 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 }; // Typedef for convenience @@ -59,34 +59,34 @@ typedef ModeFilter ModeFilterUInt16_Size7; template ModeFilter::ModeFilter(uint8_t return_element) : - FilterWithBuffer(), - _return_element(return_element), - drop_high_sample(true) + FilterWithBuffer(), + _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; + // ensure we have a valid return_nth_element value. if not, revert to median + if( _return_element >= FILTER_SIZE ) + _return_element = FILTER_SIZE / 2; }; // Public Methods ////////////////////////////////////////////////////////////// template -T ModeFilter::apply(T sample) +T ModeFilter:: apply(T sample) { - // insert the new items into the samples buffer - isort(sample, drop_high_sample); + // insert the new items into the samples buffer + isort(sample, drop_high_sample); - // next time drop from the other end of the sample buffer - drop_high_sample = !drop_high_sample; + // next time drop from the other end of the sample buffer + drop_high_sample = !drop_high_sample; - // return results - if( FilterWithBuffer::sample_index < FILTER_SIZE ) { - // middle sample if buffer is not yet full - return FilterWithBuffer::samples[(FilterWithBuffer::sample_index / 2)]; - }else{ - // return element specified by user in constructor - return FilterWithBuffer::samples[_return_element]; - } + // return results + if( FilterWithBuffer::sample_index < FILTER_SIZE ) { + // middle sample if buffer is not yet full + return FilterWithBuffer::samples[(FilterWithBuffer::sample_index / 2)]; + }else{ + // return element specified by user in constructor + return FilterWithBuffer::samples[_return_element]; + } } // @@ -94,45 +94,45 @@ T ModeFilter::apply(T sample) // drops either the highest or lowest sample depending on the 'drop_high_sample' parameter // template -void ModeFilter::isort(T new_sample, bool drop_high) +void ModeFilter:: isort(T new_sample, bool drop_high) { - int8_t i; + int8_t i; - // if the buffer isn't full simply increase the #items in the buffer (i.e. sample_index) - // the rest is the same as dropping the high sample - if( FilterWithBuffer::sample_index < FILTER_SIZE ) { - FilterWithBuffer::sample_index++; - drop_high = true; - } + // if the buffer isn't full simply increase the #items in the buffer (i.e. sample_index) + // the rest is the same as dropping the high sample + if( FilterWithBuffer::sample_index < FILTER_SIZE ) { + FilterWithBuffer::sample_index++; + drop_high = true; + } - if( drop_high ) { // drop highest sample from the buffer to make room for our new sample + if( drop_high ) { // drop highest sample from the buffer to make room for our new sample - // start from top. Note: sample_index always points to the next open space so we start from sample_index-1 - i = FilterWithBuffer::sample_index-1; + // start from top. Note: sample_index always points to the next open space so we start from sample_index-1 + i = FilterWithBuffer::sample_index-1; - // if the next element is higher than our new sample, push it up one position - while( FilterWithBuffer::samples[i-1] > new_sample && i > 0 ) { - FilterWithBuffer::samples[i] = FilterWithBuffer::samples[i-1]; - i--; - } + // if the next element is higher than our new sample, push it up one position + while( FilterWithBuffer::samples[i-1] > new_sample && i > 0 ) { + FilterWithBuffer::samples[i] = FilterWithBuffer::samples[i-1]; + i--; + } - // add our new sample to the buffer - FilterWithBuffer::samples[i] = new_sample; + // add our new sample to the buffer + FilterWithBuffer::samples[i] = new_sample; - }else{ // drop lowest sample from the buffer to make room for our new sample + }else{ // drop lowest sample from the buffer to make room for our new sample - // start from the bottom - i = 0; + // start from the bottom + i = 0; - // if the element is lower than our new sample, push it down one position - while( FilterWithBuffer::samples[i+1] < new_sample && i < FilterWithBuffer::sample_index-1 ) { - FilterWithBuffer::samples[i] = FilterWithBuffer::samples[i+1]; - i++; - } + // if the element is lower than our new sample, push it down one position + while( FilterWithBuffer::samples[i+1] < new_sample && i < FilterWithBuffer::sample_index-1 ) { + FilterWithBuffer::samples[i] = FilterWithBuffer::samples[i+1]; + i++; + } - // add our new sample to the buffer - FilterWithBuffer::samples[i] = new_sample; - } + // add our new sample to the buffer + FilterWithBuffer::samples[i] = new_sample; + } } #endif \ No newline at end of file