Graft of 'cli_diff_command' into 'master'.
[betaflight.git] / src / main / telemetry / telemetry.c
blob96e2193e9aeec74702d8f28a856db237aa297f6a
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
23 #ifdef TELEMETRY
25 #include "drivers/gpio.h"
26 #include "drivers/timer.h"
27 #include "drivers/serial.h"
28 #include "drivers/serial_softserial.h"
29 #include "io/serial.h"
31 #include "rx/rx.h"
32 #include "io/rc_controls.h"
34 #include "config/runtime_config.h"
35 #include "config/config.h"
37 #include "telemetry/telemetry.h"
38 #include "telemetry/frsky.h"
39 #include "telemetry/hott.h"
40 #include "telemetry/smartport.h"
41 #include "telemetry/ltm.h"
42 #include "telemetry/jetiexbus.h"
44 static telemetryConfig_t *telemetryConfig;
46 void telemetryUseConfig(telemetryConfig_t *telemetryConfigToUse)
48 telemetryConfig = telemetryConfigToUse;
51 void telemetryInit(void)
53 initFrSkyTelemetry(telemetryConfig);
54 initHoTTTelemetry(telemetryConfig);
55 initSmartPortTelemetry(telemetryConfig);
56 initLtmTelemetry(telemetryConfig);
57 initJetiExBusTelemetry(telemetryConfig);
59 telemetryCheckState();
62 bool telemetryDetermineEnabledState(portSharing_e portSharing)
64 bool enabled = portSharing == PORTSHARING_NOT_SHARED;
66 if (portSharing == PORTSHARING_SHARED) {
67 if (telemetryConfig->telemetry_switch)
68 enabled = IS_RC_MODE_ACTIVE(BOXTELEMETRY);
69 else
70 enabled = ARMING_FLAG(ARMED);
73 return enabled;
76 bool telemetryCheckRxPortShared(serialPortConfig_t *portConfig)
78 return portConfig->functionMask & FUNCTION_RX_SERIAL && portConfig->functionMask & TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK;
81 serialPort_t *telemetrySharedPort = NULL;
83 void telemetryCheckState(void)
85 checkFrSkyTelemetryState();
86 checkHoTTTelemetryState();
87 checkSmartPortTelemetryState();
88 checkLtmTelemetryState();
89 checkJetiExBusTelemetryState();
92 void telemetryProcess(rxConfig_t *rxConfig, uint16_t deadband3d_throttle)
94 handleFrSkyTelemetry(rxConfig, deadband3d_throttle);
95 handleHoTTTelemetry();
96 handleSmartPortTelemetry();
97 handleLtmTelemetry();
98 handleJetiExBusTelemetry();
101 #endif