Cosmetics
[opentx.git] / radio / src / trainer.cpp
blob0af1901b73b4a1a66715e3bb15d18da9430e8a37
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 int16_t ppmInput[MAX_TRAINER_CHANNELS];
24 uint8_t ppmInputValidityTimer;
25 uint8_t currentTrainerMode = 0xff;
27 void checkTrainerSignalWarning()
29 enum PpmInValidState_t {
30 PPM_IN_IS_NOT_USED=0,
31 PPM_IN_IS_VALID,
32 PPM_IN_INVALID
35 static uint8_t ppmInputValidState = PPM_IN_IS_NOT_USED;
37 if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_NOT_USED)) {
38 ppmInputValidState = PPM_IN_IS_VALID;
40 else if (!ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_VALID)) {
41 ppmInputValidState = PPM_IN_INVALID;
42 AUDIO_TRAINER_LOST();
44 else if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_INVALID)) {
45 ppmInputValidState = PPM_IN_IS_VALID;
46 AUDIO_TRAINER_BACK();
50 #if defined(PCBSKY9X)
51 void checkTrainerSettings()
53 uint8_t requiredTrainerMode = SLAVE_MODE();
55 if (requiredTrainerMode != currentTrainerMode) {
56 currentTrainerMode = requiredTrainerMode;
57 if (requiredTrainerMode)
58 stop_trainer_capture();
59 else
60 init_trainer_capture();
63 #else
64 void checkTrainerSettings()
66 uint8_t requiredTrainerMode = g_model.trainerData.mode;
68 if (requiredTrainerMode != currentTrainerMode) {
69 switch (currentTrainerMode) {
70 case TRAINER_MODE_MASTER_TRAINER_JACK:
71 stop_trainer_capture();
72 break;
74 case TRAINER_MODE_SLAVE:
75 stop_trainer_ppm();
76 break;
78 #if defined(TRAINER_MODULE_CPPM)
79 case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
80 stop_trainer_module_cppm();
81 break;
82 #endif
84 #if defined(TRAINER_MODULE_SBUS)
85 case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
86 stop_trainer_module_sbus();
87 break;
88 #endif
90 #if defined(TRAINER_BATTERY_COMPARTMENT)
91 case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
92 auxSerialStop();
93 break;
94 #endif
97 currentTrainerMode = requiredTrainerMode;
99 switch (requiredTrainerMode) {
100 case TRAINER_MODE_SLAVE:
101 init_trainer_ppm();
102 break;
104 #if defined(TRAINER_MODULE_CPPM)
105 case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
106 init_trainer_module_cppm();
107 break;
108 #endif
110 #if defined(TRAINER_MODULE_SBUS)
111 case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
112 init_trainer_module_sbus();
113 break;
114 #endif
116 #if defined(TRAINER_BATTERY_COMPARTMENT)
117 case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
118 if (g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER)
119 auxSerialSbusInit();
120 else
121 init_trainer_capture();
122 break;
123 #endif
125 case TRAINER_MODE_MASTER_TRAINER_JACK:
126 init_trainer_capture();
127 break;
130 #if defined(TRAINER_MODULE_CPPM) || defined(TRAINER_MODULE_SBUS)
131 if (requiredTrainerMode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE || requiredTrainerMode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE)
132 stop_intmodule_heartbeat();
133 else
134 init_intmodule_heartbeat();
135 #else
136 init_intmodule_heartbeat();
137 #endif
140 #endif