Fix doc path
[opentx.git] / radio / src / trainer_input.h
blob4d997d4f35a47890bfdccae9eceaf6f1c1315cef
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_INPUT_H_
22 #define _TRAINER_INPUT_H_
24 #include "opentx.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 #define IS_TRAINER_INPUT_VALID() (ppmInputValidityTimer != 0)
35 #if defined(CPUARM)
36 void checkTrainerSignalWarning();
37 #else
38 #define checkTrainerSignalWarning()
39 #endif
41 // Needs to be inlined to avoid slow function calls in ISR routines
42 inline void captureTrainerPulses(uint16_t capture)
44 static uint16_t lastCapt = 0;
45 static int8_t channelNumber = -1;
47 uint16_t val = (uint16_t)(capture - lastCapt) / 2;
48 lastCapt = capture;
50 // We process ppmInput right here to make servo movement as smooth as possible
51 // while under trainee control
53 // G: Prioritize reset pulse. (Needed when less than 16 incoming pulses)
55 if (val > 4000 && val < 19000) {
56 channelNumber = 0; // triggered
58 else {
59 if (channelNumber >= 0 && channelNumber < MAX_TRAINER_CHANNELS) {
60 if (val > 800 && val < 2200) {
61 ppmInputValidityTimer = PPM_IN_VALID_TIMEOUT;
62 ppmInput[channelNumber++] =
63 // +-500 != 512, but close enough.
64 (int16_t)(val - 1500) * (g_eeGeneral.PPM_Multiplier+10) / 10;
66 else {
67 channelNumber = -1; // not triggered
73 #endif // _TRAINER_INPUT_H_