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.
21 #ifndef _TELEMETRY_HOLDERS_H_
22 #define _TELEMETRY_HOLDERS_H_
25 #include "../timers.h"
27 #define TELEMETRY_AVERAGE_COUNT 3 // we actually average one more reading!
28 #define RAW_FRSKY_MINMAX(v) v.values[TELEMETRY_AVERAGE_COUNT-1]
30 class TelemetryValue
{
37 void set(uint8_t value
)
52 class TelemetryFilterDecorator
: public T
{
54 void set(uint8_t value
)
56 if (value
== 0 || this->_value
== 0) {
57 memset(values
, value
, TELEMETRY_AVERAGE_COUNT
);
61 // calculate the average from values[] and value
62 // also shift readings in values [] array
63 unsigned int sum
= values
[0];
64 for (int i
=0; i
<TELEMETRY_AVERAGE_COUNT
-1; i
++) {
65 uint8_t tmp
= values
[i
+1];
69 values
[TELEMETRY_AVERAGE_COUNT
-1] = value
;
71 this->_value
= sum
/ (TELEMETRY_AVERAGE_COUNT
+1);
77 memclear(this, sizeof(*this));
81 uint8_t values
[TELEMETRY_AVERAGE_COUNT
];
85 class TelemetryExpiringDecorator
: public T
{
87 void set(uint8_t value
)
90 expirationTime
= get_tmr10ms() + 1000/*10s*/;
95 memclear(this, sizeof(*this));
100 return get_tmr10ms() < expirationTime
;
104 tmr10ms_t expirationTime
;
108 class TelemetryMinDecorator
: public T
{
110 void set(uint8_t value
)
113 if (!_min
|| value
< _min
) {
125 memclear(this, sizeof(*this));
132 #endif // _TELEMETRY_HOLDERS_H_