From 1b35f2bd35062a97264645c565982934d8abf445 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 24 Oct 2019 12:03:19 +0200 Subject: [PATCH] Trainer function can now replace the channels values instead of to the sticks positions (#6561) --- radio/src/functions.cpp | 12 ++++--- .../gui/128x64/model_special_functions.cpp | 8 +++-- .../gui/212x64/model_special_functions.cpp | 8 +++-- .../gui/480x272/model_special_functions.cpp | 8 +++-- radio/src/mixer.cpp | 32 +++++++++++-------- radio/src/opentx.h | 5 +-- 6 files changed, 47 insertions(+), 26 deletions(-) diff --git a/radio/src/functions.cpp b/radio/src/functions.cpp index bd840fc4a..0f93ca786 100644 --- a/radio/src/functions.cpp +++ b/radio/src/functions.cpp @@ -165,11 +165,13 @@ void evalFunctions(const CustomFunctionData * functions, CustomFunctionsContext case FUNC_TRAINER: { - uint8_t mask = 0x0f; - if (CFN_CH_INDEX(cfn) > 0) { - mask = (1<<(CFN_CH_INDEX(cfn)-1)); - } - newActiveFunctions |= mask; + uint8_t param = CFN_CH_INDEX(cfn); + if (param == 0) + newActiveFunctions |= 0x0F; + else if (param <= NUM_STICKS) + newActiveFunctions |= (1 << (param-1)); + else if (param == NUM_STICKS + 1) + newActiveFunctions |= (1 << FUNCTION_TRAINER_CHANNELS); break; } diff --git a/radio/src/gui/128x64/model_special_functions.cpp b/radio/src/gui/128x64/model_special_functions.cpp index b4f4646a3..a0472d681 100644 --- a/radio/src/gui/128x64/model_special_functions.cpp +++ b/radio/src/gui/128x64/model_special_functions.cpp @@ -222,8 +222,12 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF else #endif if (func == FUNC_TRAINER) { - maxParam = 4; - drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, CFN_CH_INDEX(cfn)==0 ? 0 : MIXSRC_Rud+CFN_CH_INDEX(cfn)-1, attr); + maxParam = NUM_STICKS + 1; + uint8_t param = CFN_CH_INDEX(cfn); + if (param == NUM_STICKS + 1) + lcdDrawText(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, "Chans", attr); + else + drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, CFN_CH_INDEX(cfn) == 0 ? 0 : MIXSRC_Rud + CFN_CH_INDEX(cfn) - 1, attr); } #if defined(GVARS) else if (func == FUNC_ADJUST_GVAR) { diff --git a/radio/src/gui/212x64/model_special_functions.cpp b/radio/src/gui/212x64/model_special_functions.cpp index 653e83783..eb1bcb58d 100644 --- a/radio/src/gui/212x64/model_special_functions.cpp +++ b/radio/src/gui/212x64/model_special_functions.cpp @@ -214,8 +214,12 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF else #endif if (func == FUNC_TRAINER) { - maxParam = NUM_STICKS; - drawSource(lcdNextPos, y, CFN_CH_INDEX(cfn)==0 ? 0 : MIXSRC_Rud+CFN_CH_INDEX(cfn)-1, attr); + maxParam = NUM_STICKS + 1; + uint8_t param = CFN_CH_INDEX(cfn); + if (param == NUM_STICKS + 1) + lcdDrawText(lcdNextPos, y, "Chans", attr); + else + drawSource(lcdNextPos, y, CFN_CH_INDEX(cfn)==0 ? 0 : MIXSRC_Rud+CFN_CH_INDEX(cfn)-1, attr); } #if defined(GVARS) else if (func == FUNC_ADJUST_GVAR) { diff --git a/radio/src/gui/480x272/model_special_functions.cpp b/radio/src/gui/480x272/model_special_functions.cpp index 6ae8c4d11..f646b027c 100644 --- a/radio/src/gui/480x272/model_special_functions.cpp +++ b/radio/src/gui/480x272/model_special_functions.cpp @@ -215,8 +215,12 @@ bool menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF else #endif if (func == FUNC_TRAINER) { - maxParam = 4; - drawSource(MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT, y, CFN_CH_INDEX(cfn)==0 ? 0 : MIXSRC_Rud+CFN_CH_INDEX(cfn)-1, attr); + maxParam = NUM_STICKS + 1; + uint8_t param = CFN_CH_INDEX(cfn); + if (param == NUM_STICKS + 1) + lcdDrawText(MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT, y, "Chans", attr); + else + drawSource(MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT, y, CFN_CH_INDEX(cfn)==0 ? 0 : MIXSRC_Rud+CFN_CH_INDEX(cfn)-1, attr); } #if defined(GVARS) else if (func == FUNC_ADJUST_GVAR) { diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index 655438d4c..6d9d543cf 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -224,6 +224,17 @@ void applyExpos(int16_t * anas, uint8_t mode, uint8_t ovwrIdx, int16_t ovwrValue // rescaled from -262144 to 262144 int16_t applyLimits(uint8_t channel, int32_t value) { +#if defined(OVERRIDE_CHANNEL_FUNCTION) + if (safetyCh[channel] != OVERRIDE_CHANNEL_UNDEFINED) { + // safety channel available for channel check + return calc100toRESX(safetyCh[channel]); + } +#endif + + if (isFunctionActive(FUNCTION_TRAINER_CHANNELS) && IS_TRAINER_INPUT_VALID()) { + return ppmInput[channel]; + } + LimitData * lim = limitAddress(channel); if (lim->curve) { @@ -277,17 +288,12 @@ int16_t applyLimits(uint8_t channel, int32_t value) ofs += tmp; // ofs can to added directly because already recalculated, } - if (ofs > lim_p) ofs = lim_p; - if (ofs < lim_n) ofs = lim_n; - - if (lim->revert) ofs = -ofs; // finally do the reverse. - -#if defined(OVERRIDE_CHANNEL_FUNCTION) - if (safetyCh[channel] != OVERRIDE_CHANNEL_UNDEFINED) { - // safety channel available for channel check - ofs = calc100toRESX(safetyCh[channel]); - } -#endif + if (ofs > lim_p) + ofs = lim_p; + if (ofs < lim_n) + ofs = lim_n; + if (lim->revert) + ofs = -ofs; // finally do the reverse. return ofs; } @@ -467,12 +473,12 @@ void evalInputs(uint8_t mode) v = 0; } - if (mode <= e_perout_mode_inactive_flight_mode && isFunctionActive(FUNCTION_TRAINER+ch) && IS_TRAINER_INPUT_VALID()) { + if (mode <= e_perout_mode_inactive_flight_mode && isFunctionActive(FUNCTION_TRAINER_STICK1+ch) && IS_TRAINER_INPUT_VALID()) { // trainer mode TrainerMix* td = &g_eeGeneral.trainer.mix[ch]; if (td->mode) { uint8_t chStud = td->srcChn; - int32_t vStud = (ppmInput[chStud]- g_eeGeneral.trainer.calib[chStud]); + int32_t vStud = (ppmInput[chStud] - g_eeGeneral.trainer.calib[chStud]); vStud *= td->studWeight; vStud /= 50; switch (td->mode) { diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 218a3b9fb..afb35eeb4 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -909,8 +909,9 @@ uint8_t lswFamily(uint8_t func); int16_t lswTimerValue(delayval_t val); enum FunctionsActive { - FUNCTION_TRAINER, - FUNCTION_INSTANT_TRIM = FUNCTION_TRAINER+4, + FUNCTION_TRAINER_STICK1, + FUNCTION_TRAINER_CHANNELS = FUNCTION_TRAINER_STICK1 + NUM_STICKS, + FUNCTION_INSTANT_TRIM, FUNCTION_VARIO, FUNCTION_BACKLIGHT, #if defined(SDCARD)