TEST(Trims, InstantTrim) { MODEL_RESET(); modelDefault(0); anaInValues[AIL_STICK] = 50; instantTrim(); EXPECT_EQ(25, getTrimValue(0, AIL_STICK)); }
TEST(Trims, InstantTrimNegativeCurve) { MODEL_RESET(); modelDefault(0); ExpoData *expo = expoAddress(AIL_STICK); expo->curve.type = CURVE_REF_CUSTOM; expo->curve.value = 1; g_model.points[0] = -100; g_model.points[1] = -75; g_model.points[2] = -50; g_model.points[3] = -25; g_model.points[4] = 0; anaInValues[AIL_STICK] = 512; instantTrim(); EXPECT_EQ(128, getTrimValue(0, AIL_STICK)); }
void evalFunctions() #endif { MASK_FUNC_TYPE newActiveFunctions = 0; MASK_CFN_TYPE newActiveSwitches = 0; #if defined(ROTARY_ENCODERS) && defined(GVARS) static rotenc_t rePreviousValues[ROTARY_ENCODERS]; #endif #if defined(OVERRIDE_CHANNEL_FUNCTION) for (uint8_t i=0; i<NUM_CHNOUT; i++) { safetyCh[i] = OVERRIDE_CHANNEL_UNDEFINED; } #endif #if defined(GVARS) for (uint8_t i=0; i<NUM_STICKS; i++) { trimGvar[i] = -1; } #endif for (uint8_t i=0; i<NUM_CFN; i++) { const CustomFunctionData *cfn = &functions[i]; int8_t swtch = CFN_SWITCH(cfn); if (swtch) { MASK_CFN_TYPE switch_mask = ((MASK_CFN_TYPE)1 << i); #if defined(CPUARM) bool active = getSwitch(swtch, IS_PLAY_FUNC(CFN_FUNC(cfn)) ? GETSWITCH_MIDPOS_DELAY : 0); #else bool active = getSwitch(swtch); #endif if (HAS_ENABLE_PARAM(CFN_FUNC(cfn))) { active &= (bool)CFN_ACTIVE(cfn); } if (active || IS_PLAY_BOTH_FUNC(CFN_FUNC(cfn))) { switch (CFN_FUNC(cfn)) { #if defined(OVERRIDE_CHANNEL_FUNCTION) case FUNC_OVERRIDE_CHANNEL: safetyCh[CFN_CH_INDEX(cfn)] = CFN_PARAM(cfn); break; #endif case FUNC_TRAINER: { uint8_t mask = 0x0f; if (CFN_CH_INDEX(cfn) > 0) { mask = (1<<(CFN_CH_INDEX(cfn)-1)); } newActiveFunctions |= mask; break; } case FUNC_INSTANT_TRIM: newActiveFunctions |= (1 << FUNCTION_INSTANT_TRIM); if (!isFunctionActive(FUNCTION_INSTANT_TRIM)) { #if defined(GUI) if (g_menuStack[0] == menuMainView #if defined(FRSKY) || g_menuStack[0] == menuTelemetryFrsky #endif #if defined(PCBTARANIS) || g_menuStack[0] == menuMainViewChannelsMonitor || g_menuStack[0] == menuChannelsView #endif ) #endif { instantTrim(); } } break; case FUNC_RESET: switch (CFN_PARAM(cfn)) { case FUNC_RESET_TIMER1: case FUNC_RESET_TIMER2: #if defined(CPUARM) case FUNC_RESET_TIMER3: #endif timerReset(CFN_PARAM(cfn)); break; case FUNC_RESET_FLIGHT: flightReset(); break; #if defined(FRSKY) case FUNC_RESET_TELEMETRY: telemetryReset(); break; #endif #if ROTARY_ENCODERS > 0 case FUNC_RESET_ROTENC1: #if ROTARY_ENCODERS > 1 case FUNC_RESET_ROTENC2: #endif g_rotenc[CFN_PARAM(cfn)-FUNC_RESET_ROTENC1] = 0; break; #endif } #if defined(CPUARM) if (CFN_PARAM(cfn)>=FUNC_RESET_PARAM_FIRST_TELEM) { TelemetryItem * telemetryItem = & telemetryItems[CFN_PARAM(cfn)-FUNC_RESET_PARAM_FIRST_TELEM]; telemetryItem->clear(); } #endif break; #if defined(CPUARM) case FUNC_SET_TIMER: { timerSet(CFN_TIMER_INDEX(cfn), CFN_PARAM(cfn)); break; } #endif #if 0 //defined(DANGEROUS_MODULE_FUNCTIONS) case FUNC_RANGECHECK: case FUNC_BIND: case FUNC_MODULE_OFF: { unsigned int moduleIndex = CFN_PARAM(cfn); if (moduleIndex < NUM_MODULES) { moduleFlag[moduleIndex] = 1 + CFN_FUNC(cfn) - FUNC_RANGECHECK; } break; } #endif #if defined(GVARS) case FUNC_ADJUST_GVAR: if (CFN_GVAR_MODE(cfn) == 0) { SET_GVAR(CFN_GVAR_INDEX(cfn), CFN_PARAM(cfn), mixerCurrentFlightMode); } else if (CFN_GVAR_MODE(cfn) == 2) { SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_PARAM(cfn), mixerCurrentFlightMode), mixerCurrentFlightMode); } else if (CFN_GVAR_MODE(cfn) == 3) { if (!(functionsContext.activeSwitches & switch_mask)) { SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_GVAR_INDEX(cfn), getGVarFlightPhase(mixerCurrentFlightMode, CFN_GVAR_INDEX(cfn))) + (CFN_PARAM(cfn) ? +1 : -1), mixerCurrentFlightMode); } } else if (CFN_PARAM(cfn) >= MIXSRC_TrimRud && CFN_PARAM(cfn) <= MIXSRC_TrimAil) { trimGvar[CFN_PARAM(cfn)-MIXSRC_TrimRud] = CFN_GVAR_INDEX(cfn); } #if defined(ROTARY_ENCODERS) else if (CFN_PARAM(cfn) >= MIXSRC_REa && CFN_PARAM(cfn) < MIXSRC_TrimRud) { int8_t scroll = rePreviousValues[CFN_PARAM(cfn)-MIXSRC_REa] - (g_rotenc[CFN_PARAM(cfn)-MIXSRC_REa] / ROTARY_ENCODER_GRANULARITY); if (scroll) { SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_GVAR_INDEX(cfn), getGVarFlightPhase(mixerCurrentFlightMode, CFN_GVAR_INDEX(cfn))) + scroll, mixerCurrentFlightMode); } } #endif else { SET_GVAR(CFN_GVAR_INDEX(cfn), calcRESXto100(getValue(CFN_PARAM(cfn))), mixerCurrentFlightMode); } break; #endif #if defined(CPUARM) && defined(SDCARD) case FUNC_VOLUME: { getvalue_t raw = getValue(CFN_PARAM(cfn)); //only set volume if input changed more than hysteresis if (abs(requiredSpeakerVolumeRawLast - raw) > VOLUME_HYSTERESIS) { requiredSpeakerVolumeRawLast = raw; } requiredSpeakerVolume = ((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) / 2048; break; } #endif #if defined(CPUARM) && defined(SDCARD) case FUNC_PLAY_SOUND: case FUNC_PLAY_TRACK: case FUNC_PLAY_VALUE: #if defined(HAPTIC) case FUNC_HAPTIC: #endif { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!IS_SILENCE_PERIOD_ELAPSED() && repeatParam == CFN_PLAY_REPEAT_NOSTART) { functionsContext.lastFunctionTime[i] = tmr10ms; } if (!functionsContext.lastFunctionTime[i] || (repeatParam && repeatParam!=CFN_PLAY_REPEAT_NOSTART && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=100*repeatParam)) { if (!IS_PLAYING(i+1)) { functionsContext.lastFunctionTime[i] = tmr10ms; if (CFN_FUNC(cfn) == FUNC_PLAY_SOUND) { AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(cfn)); } else if (CFN_FUNC(cfn) == FUNC_PLAY_VALUE) { PLAY_VALUE(CFN_PARAM(cfn), i+1); } #if defined(HAPTIC) else if (CFN_FUNC(cfn) == FUNC_HAPTIC) { haptic.event(AU_FRSKY_LAST+CFN_PARAM(cfn)); } #endif else { playCustomFunctionFile(cfn, i+1); } } } break; } case FUNC_BACKGND_MUSIC: newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC); if (!IS_PLAYING(i+1)) { playCustomFunctionFile(cfn, i+1); } break; case FUNC_BACKGND_MUSIC_PAUSE: newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC_PAUSE); break; #elif defined(VOICE) case FUNC_PLAY_SOUND: case FUNC_PLAY_TRACK: case FUNC_PLAY_BOTH: case FUNC_PLAY_VALUE: { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!functionsContext.lastFunctionTime[i] || (CFN_FUNC(cfn)==FUNC_PLAY_BOTH && active!=(bool)(functionsContext.activeSwitches&switch_mask)) || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) { functionsContext.lastFunctionTime[i] = tmr10ms; uint8_t param = CFN_PARAM(cfn); if (CFN_FUNC(cfn) == FUNC_PLAY_SOUND) { AUDIO_PLAY(AU_FRSKY_FIRST+param); } else if (CFN_FUNC(cfn) == FUNC_PLAY_VALUE) { PLAY_VALUE(param, i+1); } else { #if defined(GVARS) if (CFN_FUNC(cfn) == FUNC_PLAY_TRACK && param > 250) param = GVAR_VALUE(param-251, getGVarFlightPhase(mixerCurrentFlightMode, param-251)); #endif PUSH_CUSTOM_PROMPT(active ? param : param+1, i+1); } } if (!active) { // PLAY_BOTH would change activeFnSwitches otherwise switch_mask = 0; } break; } #else case FUNC_PLAY_SOUND: { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!functionsContext.lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) { functionsContext.lastFunctionTime[i] = tmr10ms; AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(cfn)); } break; } #endif #if defined(FRSKY) && defined(VARIO) case FUNC_VARIO: newActiveFunctions |= (1 << FUNCTION_VARIO); break; #endif #if defined(HAPTIC) && !defined(CPUARM) case FUNC_HAPTIC: { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!functionsContext.lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) { functionsContext.lastFunctionTime[i] = tmr10ms; haptic.event(AU_FRSKY_LAST+CFN_PARAM(cfn)); } break; } #endif #if defined(SDCARD) case FUNC_LOGS: if (CFN_PARAM(cfn)) { newActiveFunctions |= (1 << FUNCTION_LOGS); logDelay = CFN_PARAM(cfn); } break; #endif case FUNC_BACKLIGHT: newActiveFunctions |= (1 << FUNCTION_BACKLIGHT); break; #if defined(PCBTARANIS) case FUNC_SCREENSHOT: if (!(functionsContext.activeSwitches & switch_mask)) { requestScreenshot = true; } break; #endif #if defined(DEBUG) case FUNC_TEST: testFunc(); break; #endif } newActiveSwitches |= switch_mask; } else { functionsContext.lastFunctionTime[i] = 0; } } } functionsContext.activeSwitches = newActiveSwitches; functionsContext.activeFunctions = newActiveFunctions; #if defined(ROTARY_ENCODERS) && defined(GVARS) for (uint8_t i=0; i<ROTARY_ENCODERS; i++) { rePreviousValues[i] = (g_rotenc[i] / ROTARY_ENCODER_GRANULARITY); } #endif }