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_SENSORS_H_
22 #define _TELEMETRY_SENSORS_H_
24 #include "telemetry.h"
26 constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE
= -2;
27 constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_OLD
= -1;
28 constexpr int8_t TELEMETRY_SENSOR_TIMEOUT_START
= 125; // * 160ms = 20s
34 int32_t value
; // value, stored as uint32_t but interpreted accordingly to type
35 uint32_t distFromEarthAxis
;
39 int32_t valueMin
; // min store
40 int32_t pilotLongitude
;
44 int32_t valueMax
; // max store
45 int32_t pilotLatitude
;
48 int8_t timeout
; // for detection of sensor loss
53 int32_t filterValues
[TELEMETRY_AVERAGE_COUNT
];
63 uint16_t year
; // full year (4 digits)
73 // pilot longitude is stored in min
74 // pilot latitude is stored in max
75 // distFromEarthAxis is stored in value
87 memset(reinterpret_cast<void*>(this), 0, sizeof(TelemetryItem
));
88 timeout
= TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE
;
91 void eval(const TelemetrySensor
& sensor
);
92 void per10ms(const TelemetrySensor
& sensor
);
94 void setValue(const TelemetrySensor
& sensor
, int32_t newVal
, uint32_t unit
, uint32_t prec
=0);
96 inline bool isAvailable()
98 return (timeout
!= TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE
);
103 return (timeout
== TELEMETRY_SENSOR_TIMEOUT_OLD
);
106 inline bool hasReceiveTime()
111 inline int8_t getDelaySinceLastValue()
113 return hasReceiveTime() ? TELEMETRY_SENSOR_TIMEOUT_START
- timeout
: TELEMETRY_SENSOR_TIMEOUT_OLD
;
116 inline bool isFresh()
118 return TELEMETRY_SENSOR_TIMEOUT_START
- timeout
<= 1; // 2 * 160ms
121 inline void setFresh()
123 timeout
= TELEMETRY_SENSOR_TIMEOUT_START
;
128 timeout
= TELEMETRY_SENSOR_TIMEOUT_OLD
;
132 extern TelemetryItem telemetryItems
[MAX_TELEMETRY_SENSORS
];
133 extern uint8_t allowNewSensors
;
134 bool isFaiForbidden(source_t idx
);
136 #endif // _TELEMETRY_SENSORS_H_