From 6e867f06aa8ce07646f08e2d9627fc964a8a0b10 Mon Sep 17 00:00:00 2001 From: RobTillaart Date: Thu, 16 Apr 2020 12:56:15 +0200 Subject: [PATCH] #149 improve accuracy of getFastAverage() --- LICENSE.md | 6 +++--- libraries/RunningAverage/RunningAverage.cpp | 11 ++++++----- libraries/RunningAverage/RunningAverage.h | 6 +++--- libraries/RunningAverage/keywords.txt | 14 -------------- libraries/RunningAverage/library.json | 2 +- libraries/RunningAverage/library.properties | 4 +++- 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 65ed79b0..0a4ba100 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ -MIT License +# MIT License -Copyright (c) 2010-2018 Rob Tillaart +Copyright (c) 2010-2020 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/libraries/RunningAverage/RunningAverage.cpp b/libraries/RunningAverage/RunningAverage.cpp index d2aadb8b..49621626 100644 --- a/libraries/RunningAverage/RunningAverage.cpp +++ b/libraries/RunningAverage/RunningAverage.cpp @@ -1,7 +1,7 @@ // // FILE: RunningAverage.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.15 +// VERSION: 0.2.16 // DATE: 2015-July-10 // PURPOSE: RunningAverage library for Arduino // @@ -30,6 +30,7 @@ // refactored a bit; marked some TODO's; all function names to camelCase // 0.2.14 - 2020-01-15 added getValue(n) to retrieve elements in order of addition - see issue #132 // 0.2.15 - 2020-01-17 fix overflow in getValue - see issue #139 +// 0.2.16 2020-04-16 improve _sum - see issue #149 (bourkemcrobbo) // // Released to the public domain // @@ -89,16 +90,16 @@ void RunningAverage::addValue(const float value) } // returns the average of the data-set added sofar -float RunningAverage::getAverage() const +float RunningAverage::getAverage() { if (_cnt == 0) return NAN; - float sum = 0; + _sum = 0; for (uint8_t i = 0; i < _cnt; i++) { - sum += _ar[i]; + _sum += _ar[i]; } - return sum / _cnt; + return _sum / _cnt; } float RunningAverage::getFastAverage() const diff --git a/libraries/RunningAverage/RunningAverage.h b/libraries/RunningAverage/RunningAverage.h index 7e308fed..f84949f1 100644 --- a/libraries/RunningAverage/RunningAverage.h +++ b/libraries/RunningAverage/RunningAverage.h @@ -1,7 +1,7 @@ // // FILE: RunningAverage.h // AUTHOR: Rob.Tillaart@gmail.com -// VERSION: 0.2.15 +// VERSION: 0.2.16 // DATE: 2016-dec-01 // PURPOSE: RunningAverage library for Arduino // URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/RunningAverage @@ -17,7 +17,7 @@ #ifndef RunningAverage_h #define RunningAverage_h -#define RUNNINGAVERAGE_LIB_VERSION "0.2.15" +#define RUNNINGAVERAGE_LIB_VERSION "0.2.16" #include "Arduino.h" @@ -33,7 +33,7 @@ public: void fillValue(const float, const uint8_t); float getValue(const uint8_t); - float getAverage() const; // iterates over all elements. + float getAverage(); // iterates over all elements. float getFastAverage() const; // reuses previous values. // return statistical characteristics of the running average diff --git a/libraries/RunningAverage/keywords.txt b/libraries/RunningAverage/keywords.txt index fee0f844..b7237491 100644 --- a/libraries/RunningAverage/keywords.txt +++ b/libraries/RunningAverage/keywords.txt @@ -1,17 +1,9 @@ -####################################### # Syntax Coloring Map For RunningAverage -####################################### -####################################### # Datatypes (KEYWORD1) -####################################### - RunningAverage KEYWORD1 -####################################### # Methods and Functions (KEYWORD2) -####################################### - clear KEYWORD2 addValue KEYWORD2 getAverage KEYWORD2 @@ -29,13 +21,7 @@ getMinInBuffer KEYWORD2 getMaxInBuffer KEYWORD2 getValue KEYWORD2 -####################################### # Instances (KEYWORD2) -####################################### - -####################################### # Constants (LITERAL1) -####################################### - RUNNINGAVERAGE_LIB_VERSION LITERAL1 \ No newline at end of file diff --git a/libraries/RunningAverage/library.json b/libraries/RunningAverage/library.json index 202161fd..053e872f 100644 --- a/libraries/RunningAverage/library.json +++ b/libraries/RunningAverage/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Arduino.git" }, - "version": "0.2.15", + "version": "0.2.16", "frameworks": "arduino", "platforms": "*", "export": { diff --git a/libraries/RunningAverage/library.properties b/libraries/RunningAverage/library.properties index ac3a874e..c69a787f 100644 --- a/libraries/RunningAverage/library.properties +++ b/libraries/RunningAverage/library.properties @@ -1,5 +1,5 @@ name=RunningAverage -version=0.2.15 +version=0.2.16 author=Rob Tillaart maintainer=Rob Tillaart sentence=The library stores the last N individual values in a circular buffer to calculate the running average. @@ -7,3 +7,5 @@ paragraph=Supports min max average category=Data Processing url=https://github.com/RobTillaart/Arduino/tree/master/libraries/ architectures=* +includes=RunningAverager.h +depends=