Skip to content

Commit c300b96

Browse files
committed
Updated smoothe(*) method.
1 parent d1dd4ef commit c300b96

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/SmoothThermistor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ inline double SmoothThermistor::smoothe(
4545
((data * (this->smoothingFactor - 1) + input) / this->smoothingFactor);
4646
}
4747

48+
/*
49+
See about the max(*) function:
50+
https://www.arduino.cc/reference/en/language/functions/math/max/
51+
*/
4852
inline void SmoothThermistor::setSmoothingFactor(const int smoothingFactor) {
49-
this->smoothingFactor = (smoothingFactor > NTC_MIN_SMOOTHING_FACTOR) ?
50-
smoothingFactor :
51-
NTC_DEFAULT_SMOOTHING_FACTOR;
53+
this->smoothingFactor = max(smoothingFactor, NTC_MIN_SMOOTHING_FACTOR);
5254
}

src/SmoothThermistor.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
v.2.0.2
2424
- optimized smoothe(*) method;
25-
- added default constants for the smoothing factor;
25+
- added default constant for the smoothing factor;
2626
- added default value of constructor parameters;
2727
- updated documentation.
2828
@@ -38,8 +38,6 @@
3838

3939
// Minimum smoothing factor.
4040
#define NTC_MIN_SMOOTHING_FACTOR 2
41-
// Default smoothing factor.
42-
#define NTC_DEFAULT_SMOOTHING_FACTOR 2
4341

4442
class SmoothThermistor final : public Thermistor {
4543

@@ -59,7 +57,7 @@ class SmoothThermistor final : public Thermistor {
5957
*/
6058
SmoothThermistor(
6159
Thermistor* origin,
62-
int smoothingFactor = NTC_DEFAULT_SMOOTHING_FACTOR
60+
int smoothingFactor = NTC_MIN_SMOOTHING_FACTOR
6361
);
6462

6563
/**
@@ -96,14 +94,14 @@ class SmoothThermistor final : public Thermistor {
9694
@param input - the value to smooth
9795
@param data - the data for smoothing of the input value
9896
@return smoothed value or the input value
99-
if the smooth factor is less than 1 or the input data is 0.
97+
if the input data is 0.
10098
*/
10199
inline double smoothe(double input, double data);
102100

103101
/**
104102
Sets the smoothing factor.
105103
If the input value is less than NTC_MIN_SMOOTHING_FACTOR,
106-
then sets NTC_DEFAULT_SMOOTHING_FACTOR.
104+
then sets NTC_MIN_SMOOTHING_FACTOR.
107105
108106
@param smoothingFactor - new smoothing factor
109107
*/

0 commit comments

Comments
 (0)