diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index cd3f64696d3..1cefd3d3d17 100644 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -2382,7 +2382,7 @@ static void cliServoMix(char *cmdline) if ( i >= 0 && i < MAX_SERVO_RULES && args[TARGET] >= 0 && args[TARGET] < MAX_SUPPORTED_SERVOS && - args[INPUT] >= 0 && args[INPUT] < INPUT_SOURCE_COUNT && + servoMixerInputSupported(args[INPUT]) && args[RATE] >= -1000 && args[RATE] <= 1000 && args[SPEED] >= 0 && args[SPEED] <= MAX_SERVO_SPEED && args[CONDITION] >= -1 && args[CONDITION] < MAX_LOGIC_CONDITIONS @@ -4232,6 +4232,9 @@ static void cliStatus(char *cmdline) settingGetName(settingGet(invalidIndex), buf); cliPrintErrorLinef("Invalid setting: %s", buf); } + if (!servoMixerRulesValid()) { + cliPrintErrorLinef("Servo mixer rule uses an input this board does not support"); + } } #if defined(USE_OSD) diff --git a/src/main/fc/config.c b/src/main/fc/config.c index d3021317ae5..434f495e4ef 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -264,7 +264,7 @@ void validateAndFixConfig(void) } #endif - if (settingsValidate(NULL)) { + if (settingsValidate(NULL) && servoMixerRulesValid()) { DISABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING); } else { ENABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING); diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index c78ae69ee4a..38872eca15d 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2368,8 +2368,13 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) case MSP_SET_SERVO_MIX_RULE: sbufReadU8Safe(&tmp_u8, src); if ((dataSize == 9) && (tmp_u8 < MAX_SERVO_RULES)) { - customServoMixersMutable(tmp_u8)->targetChannel = sbufReadU8(src); - customServoMixersMutable(tmp_u8)->inputSource = sbufReadU8(src); + const uint8_t targetChannel = sbufReadU8(src); + const uint8_t inputSource = sbufReadU8(src); + if (!servoMixerInputSupported(inputSource)) { + return MSP_RESULT_ERROR; + } + customServoMixersMutable(tmp_u8)->targetChannel = targetChannel; + customServoMixersMutable(tmp_u8)->inputSource = inputSource; customServoMixersMutable(tmp_u8)->rate = sbufReadU16(src); customServoMixersMutable(tmp_u8)->speed = sbufReadU8(src); sbufReadU16(src); //Read 2bytes for min/max and ignore it @@ -2382,8 +2387,13 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) case MSP2_INAV_SET_SERVO_MIXER: sbufReadU8Safe(&tmp_u8, src); if ((dataSize == 7) && (tmp_u8 < MAX_SERVO_RULES)) { - customServoMixersMutable(tmp_u8)->targetChannel = sbufReadU8(src); - customServoMixersMutable(tmp_u8)->inputSource = sbufReadU8(src); + const uint8_t targetChannel = sbufReadU8(src); + const uint8_t inputSource = sbufReadU8(src); + if (!servoMixerInputSupported(inputSource)) { + return MSP_RESULT_ERROR; + } + customServoMixersMutable(tmp_u8)->targetChannel = targetChannel; + customServoMixersMutable(tmp_u8)->inputSource = inputSource; customServoMixersMutable(tmp_u8)->rate = sbufReadU16(src); customServoMixersMutable(tmp_u8)->speed = sbufReadU8(src); #ifdef USE_PROGRAMMING_FRAMEWORK diff --git a/src/main/flight/servos.c b/src/main/flight/servos.c index e72dd66ea7d..42a1821ceb2 100755 --- a/src/main/flight/servos.c +++ b/src/main/flight/servos.c @@ -204,6 +204,30 @@ int getServoCount(void) } } +bool servoMixerInputSupported(int inputSource) +{ +#ifndef USE_34CHANNELS + // servoMixer() fills these inputs only on 34-channel targets + if (inputSource >= INPUT_RC_CH19 && inputSource <= INPUT_RC_CH34) { + return false; + } +#endif + return inputSource >= 0 && inputSource < INPUT_SOURCE_COUNT; +} + +bool servoMixerRulesValid(void) +{ + for (int profile = 0; profile < MAX_MIXER_PROFILE_COUNT; profile++) { + const servoMixer_t *rules = mixerServoMixersByIndex(profile); + for (int i = 0; i < MAX_SERVO_RULES && rules[i].rate != 0; i++) { + if (!servoMixerInputSupported(rules[i].inputSource)) { + return false; + } + } + } + return true; +} + void loadCustomServoMixer(void) { @@ -234,6 +258,10 @@ void loadCustomServoMixer(void) if (customServoMixers(i)->rate == 0){ break; } + // Arming is blocked while such a rule exists; see servoMixerRulesValid() + if (!servoMixerInputSupported(customServoMixers(i)->inputSource)) { + continue; + } currentServoMixer[servoRuleCount] = *customServoMixers(i); servoSpeedLimitFilter[servoRuleCount].state = 0; servoRuleCount++; diff --git a/src/main/flight/servos.h b/src/main/flight/servos.h index 07a337a6d56..6c6d641a97a 100644 --- a/src/main/flight/servos.h +++ b/src/main/flight/servos.h @@ -194,6 +194,8 @@ bool isServoOutputEnabled(void); void setServoOutputEnabled(bool flag); bool isMixerUsingServos(void); void writeServos(void); +bool servoMixerInputSupported(int inputSource); +bool servoMixerRulesValid(void); void loadCustomServoMixer(void); void servoMixer(float dT); void servoComputeScalingFactors(uint8_t servoIndex);