5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 void TelemetryValueWithMin::reset()
26 memclear(this, sizeof(*this));
30 void TelemetryValueWithMin::set(uint8_t value
)
33 if (this->value
== 0) {
34 memset(values
, value
, TELEMETRY_AVERAGE_COUNT
);
38 //calculate the average from values[] and value
39 //also shift readings in values [] array
40 unsigned int sum
= values
[0];
41 for (int i
=0; i
<TELEMETRY_AVERAGE_COUNT
-1; i
++) {
42 uint8_t tmp
= values
[i
+1];
46 values
[TELEMETRY_AVERAGE_COUNT
-1] = value
;
48 this->value
= sum
/(TELEMETRY_AVERAGE_COUNT
+1);
51 if (this->value
== 0) {
56 if (link_counter
== 0) {
57 this->value
= sum
/ (IS_FRSKY_D_PROTOCOL() ? FRSKY_D_AVERAGING
: FRSKY_SPORT_AVERAGING
);
63 if (!min
|| value
< min
) {
68 void TelemetryValueWithMinMax::set(uint8_t value
, uint8_t unit
)
70 TelemetryValueWithMin::set(value
);
71 if (unit
!= UNIT_VOLTS
) {
74 if (!max
|| value
> max
) {