Updated Wizard for X9 radios. (#4910)
[opentx.git] / radio / src / telemetry / telemetry_holders.cpp
blobedcbc14d20a873887f01d90e4cc796a1022583ac
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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 #include "opentx.h"
23 #if defined(CPUARM)
24 void TelemetryValueWithMin::reset()
26 memclear(this, sizeof(*this));
28 #endif
30 void TelemetryValueWithMin::set(uint8_t value)
32 #if defined(CPUARM)
33 if (this->value == 0) {
34 memset(values, value, TELEMETRY_AVERAGE_COUNT);
35 this->value = value;
37 else {
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];
43 values[i] = tmp;
44 sum += tmp;
46 values[TELEMETRY_AVERAGE_COUNT-1] = value;
47 sum += value;
48 this->value = sum/(TELEMETRY_AVERAGE_COUNT+1);
50 #else
51 if (this->value == 0) {
52 this->value = value;
54 else {
55 sum += value;
56 if (link_counter == 0) {
57 this->value = sum / (IS_FRSKY_D_PROTOCOL() ? FRSKY_D_AVERAGING : FRSKY_SPORT_AVERAGING);
58 sum = 0;
61 #endif
63 if (!min || value < min) {
64 min = value;
68 void TelemetryValueWithMinMax::set(uint8_t value, uint8_t unit)
70 TelemetryValueWithMin::set(value);
71 if (unit != UNIT_VOLTS) {
72 this->value = value;
74 if (!max || value > max) {
75 max = value;