ASTERISK option added
[opentx.git] / radio / src / trainer.h
blobe3c67acac8e661ee457233c9cfa3315ba43908c2
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 #ifndef _TRAINER_H_
22 #define _TRAINER_H_
24 #include "dataconstants.h"
26 // Trainer input channels
27 extern int16_t ppmInput[MAX_TRAINER_CHANNELS];
29 // Timer gets decremented in per10ms()
30 #define PPM_IN_VALID_TIMEOUT 100 // 1s
31 extern uint8_t ppmInputValidityTimer;
33 extern uint8_t currentTrainerMode;
34 #define IS_TRAINER_INPUT_VALID() (ppmInputValidityTimer != 0)
36 void checkTrainerSignalWarning();
37 void checkTrainerSettings();
38 void forceResetTrainerSettings();
40 // Needs to be inlined to avoid slow function calls in ISR routines
41 inline void captureTrainerPulses(uint16_t capture)
43 static uint16_t lastCapt = 0;
44 static int8_t channelNumber = -1;
46 uint16_t val = (uint16_t)(capture - lastCapt) / 2;
47 lastCapt = capture;
49 // We process ppmInput right here to make servo movement as smooth as possible
50 // while under trainee control
52 // G: Prioritize reset pulse. (Needed when less than 16 incoming pulses)
54 if (val > 4000 && val < 19000) {
55 channelNumber = 0; // triggered
57 else {
58 if (channelNumber >= 0 && channelNumber < MAX_TRAINER_CHANNELS) {
59 if (val > 800 && val < 2200) {
60 ppmInputValidityTimer = PPM_IN_VALID_TIMEOUT;
61 ppmInput[channelNumber++] =
62 // +-500 != 512, but close enough.
63 (int16_t)(val - 1500) * (g_eeGeneral.PPM_Multiplier+10) / 10;
65 else {
66 channelNumber = -1; // not triggered
72 #endif // _TRAINER_H_