Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/fc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/main/flight/servos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down Expand Up @@ -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++;
Expand Down
2 changes: 2 additions & 0 deletions src/main/flight/servos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading