Fixes #2579: Added support for Trainer signal alarm
- added alarm “Trainer signal lost” & “Trainer signal recovered”.
- moved PPM capture code to trainer_input.{h,cpp}
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef trainer_input_h
|
||||
#define trainer_input_h
|
||||
|
||||
#include "myeeprom.h"
|
||||
|
||||
// Trainer input channels
|
||||
extern int16_t g_ppmIns[NUM_TRAINER];
|
||||
|
||||
// Timer gets decremented in per10ms()
|
||||
#define PPM_IN_VALID_TIMEOUT 100 // 1s
|
||||
extern uint8_t g_ppmInputValidityTimer;
|
||||
|
||||
#define IS_TRAINER_INPUT_VALID() (g_ppmInputValidityTimer != 0)
|
||||
|
||||
#if defined(CPUARM)
|
||||
void checkTrainerSignalWarning();
|
||||
#else
|
||||
#define checkTrainerSignalWarning()
|
||||
#endif
|
||||
|
||||
// Needs to be inlined to avoid slow function calls in ISR routines
|
||||
inline void captureTrainerPulses(uint16_t capture)
|
||||
{
|
||||
static uint16_t lastCapt=0;
|
||||
static uint8_t channelNumber=0;
|
||||
|
||||
uint16_t val = (uint16_t)(capture - lastCapt) / 2;
|
||||
lastCapt = capture;
|
||||
|
||||
// We process g_ppmInsright here to make servo movement as smooth as possible
|
||||
// while under trainee control
|
||||
//
|
||||
// G: Prioritize reset pulse. (Needed when less than 16 incoming pulses)
|
||||
//
|
||||
if (val>4000 && val<19000) {
|
||||
channelNumber = 1; // triggered
|
||||
}
|
||||
else {
|
||||
if ((channelNumber > 0) && (channelNumber <= NUM_TRAINER)) {
|
||||
if (val>800 && val<2200) {
|
||||
g_ppmInputValidityTimer = PPM_IN_VALID_TIMEOUT;
|
||||
g_ppmIns[channelNumber++ - 1] =
|
||||
//+-500 != 512, but close enough.
|
||||
(int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10;
|
||||
}
|
||||
else {
|
||||
channelNumber = 0; // not triggered
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user