From e5d90339f495d482a55902da3554b2d528a7fcde Mon Sep 17 00:00:00 2001 From: shota Date: Fri, 13 Oct 2023 02:43:57 +0900 Subject: [PATCH] fixes servo output issue --- src/main/flight/servos.c | 52 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/flight/servos.c b/src/main/flight/servos.c index 354acfd6af8..d3c5da8c75b 100755 --- a/src/main/flight/servos.c +++ b/src/main/flight/servos.c @@ -143,6 +143,33 @@ void servoComputeScalingFactors(uint8_t servoIndex) { servoMetadata[servoIndex].scaleMin = (servoParams(servoIndex)->middle - servoParams(servoIndex)->min) / 500.0f; } +void computeServoCount(void) +{ + static bool firstRun = true; + if (!firstRun) { + return; + } + minServoIndex = 255; + maxServoIndex = 0; + for (int j = 0; j < MAX_MIXER_PROFILE_COUNT; j++) { + for (int i = 0; i < MAX_SERVO_RULES; i++) { + // check if done + if (mixerServoMixersByIndex(j)[i].rate == 0){ + break; + } + if (mixerServoMixersByIndex(j)[i].targetChannel < minServoIndex) { + minServoIndex = mixerServoMixersByIndex(j)[i].targetChannel; + } + + if (mixerServoMixersByIndex(j)[i].targetChannel > maxServoIndex) { + maxServoIndex = mixerServoMixersByIndex(j)[i].targetChannel; + } + mixerUsesServos = true; + } + } + firstRun = false; +} + void servosInit(void) { // give all servos a default command @@ -153,12 +180,12 @@ void servosInit(void) /* * load mixer */ + computeServoCount(); loadCustomServoMixer(); // If there are servo rules after all, update variables - if (servoRuleCount > 0) { + if (mixerUsesServos) { servoOutputEnabled = true; - mixerUsesServos = true; } for (uint8_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) { @@ -168,26 +195,7 @@ void servosInit(void) int getServoCount(void) { - bool servoRuleDetected = false; - minServoIndex = 0; - maxServoIndex = 255; - for (int j = 0; j < MAX_MIXER_PROFILE_COUNT; j++) { - for (int i = 0; i < MAX_SERVO_RULES; i++) { - // check if done - if (mixerServoMixersByIndex(j)[i].rate == 0){ - break; - } - if (mixerServoMixersByIndex(j)[i].targetChannel < minServoIndex) { - minServoIndex = mixerServoMixersByIndex(j)[i].targetChannel; - } - - if (mixerServoMixersByIndex(j)[i].targetChannel > maxServoIndex) { - maxServoIndex = mixerServoMixersByIndex(j)[i].targetChannel; - } - servoRuleDetected = true; - } - } - if (servoRuleDetected) { + if (mixerUsesServos) { return 1 + maxServoIndex - minServoIndex; } else {