From be3c674fe5ba4421b3c8d80b78f5127f0a23e36c Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 5 May 2014 10:36:34 +0200 Subject: [PATCH] Fixes #36 --- radio/src/opentx.cpp | 29 ++++++++++++-------- radio/src/opentx.h | 1 + radio/src/targets/sky9x/board_sky9x.cpp | 13 ++++----- radio/src/targets/taranis/trainer_driver.cpp | 7 +++-- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index fd08ea0e4..38e407e2f 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -319,7 +319,8 @@ void per10ms() if (lightOffCounter) lightOffCounter--; if (flashCounter) flashCounter--; if (s_noHi) s_noHi--; - if (trimsCheckTimer) trimsCheckTimer --; + if (trimsCheckTimer) trimsCheckTimer--; + if (ppmInValid) ppmInValid--; #if defined(RTCLOCK) /* Update global Date/Time every 100 per10ms cycles */ @@ -3196,7 +3197,7 @@ void evalInputs(uint8_t mode) } #endif - if (mode <= e_perout_mode_inactive_phase && isFunctionActive(FUNCTION_TRAINER+ch)) { + if (mode <= e_perout_mode_inactive_phase && isFunctionActive(FUNCTION_TRAINER+ch) && ppmInValid) { // trainer mode TrainerMix* td = &g_eeGeneral.trainer.mix[ch]; if (td->mode) { @@ -3823,6 +3824,10 @@ void perOut(uint8_t mode, uint8_t tick10ms) bool mixCondition = (md->phases != 0 || md->swtch); delayval_t mixEnabled = !(md->phases & (1 << s_perout_flight_phase)) && getSwitch(md->swtch); + if (mixEnabled && md->srcRaw >= MIXSRC_FIRST_TRAINER && md->srcRaw <= MIXSRC_LAST_TRAINER && !ppmInValid) { + mixEnabled = 0; + } + //========== VALUE =============== getvalue_t v = 0; if (mode > e_perout_mode_inactive_phase) { @@ -5046,6 +5051,7 @@ void perMain() int16_t g_ppmIns[NUM_TRAINER]; uint8_t ppmInState = 0; // 0=unsync 1..8= wait for value i-1 +uint8_t ppmInValid = 0; #if !defined(SIMU) && !defined(CPUARM) @@ -5132,19 +5138,18 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS // G: We process g_ppmIns immediately here, to make servo movement as smooth as possible // while under trainee control - if (val>4000 && val < 16000) // G: Prioritize reset pulse. (Needed when less than 8 incoming pulses) + if (val>4000 && val < 16000) { // G: Prioritize reset pulse. (Needed when less than 8 incoming pulses) ppmInState = 1; // triggered - else - { - if (ppmInState && ppmInState<=8) - { - if (val>800 && val<2200) // if valid pulse-width range - { - g_ppmIns[ppmInState++ - 1] = - (int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough. + } + else { + if (ppmInState>0 && ppmInState<=8) { + if (val>800 && val<2200) { // if valid pulse-width range + ppmInValid = 100; + g_ppmIns[ppmInState++ - 1] = (int16_t)(val - 1500) * (uint8_t)(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough. } - else + else { ppmInState = 0; // not triggered + } } } diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 1ddafc247..eccbd62a7 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1013,6 +1013,7 @@ extern uint8_t g_beepCnt; extern uint8_t g_beepVal[5]; extern uint8_t ppmInState; //0=unsync 1..8= wait for value i-1 +extern uint8_t ppmInValid; extern int16_t g_ppmIns[NUM_TRAINER]; extern int32_t chans[NUM_CHNOUT]; extern int16_t ex_chans[NUM_CHNOUT]; // Outputs (before LIMITS) of the last perMain diff --git a/radio/src/targets/sky9x/board_sky9x.cpp b/radio/src/targets/sky9x/board_sky9x.cpp index bb01fd7e4..a33453da3 100644 --- a/radio/src/targets/sky9x/board_sky9x.cpp +++ b/radio/src/targets/sky9x/board_sky9x.cpp @@ -314,15 +314,14 @@ extern "C" void TC3_IRQHandler() //capture ppm in at 2MHz ppmInState = 1; // triggered } else { - if (ppmInState && ppmInState<=16) - { - if (val>800 && val<2200) // if valid pulse-width range - { - g_ppmIns[ppmInState++ - 1] = - (int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough. + if (ppmInState>0 && ppmInState<=16) { + if (val>800 && val<2200) { // if valid pulse-width range + ppmInValid = 100; + g_ppmIns[ppmInState++ - 1] = (int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough. } - else + else { ppmInState = 0; // not triggered + } } } diff --git a/radio/src/targets/taranis/trainer_driver.cpp b/radio/src/targets/taranis/trainer_driver.cpp index 5e453d215..2a92fd74e 100644 --- a/radio/src/targets/taranis/trainer_driver.cpp +++ b/radio/src/targets/taranis/trainer_driver.cpp @@ -126,12 +126,13 @@ extern "C" void TIM3_IRQHandler() // We process g_ppmInsright here to make servo movement as smooth as possible // while under trainee control - if ((val>4000) && (val < 19000)) { // G: Prioritize reset pulse. (Needed when less than 16 incoming pulses) + if (val>4000 && val<19000) { // G: Prioritize reset pulse. (Needed when less than 16 incoming pulses) ppmInState = 1; // triggered } else { - if (ppmInState && (ppmInState<=16)) { - if ((val>800) && (val<2200)) { + if (ppmInState>0 && ppmInState<=16) { + if (val>800 && val<2200) { + ppmInValid = 100; g_ppmIns[ppmInState++ - 1] = (int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough. } else {