From 0b1383a7301a2011fa7afc438d3cac7c7529de92 Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 1 Jun 2017 00:30:04 +0900 Subject: [PATCH] Refactored the validation code - The check is active regardless of the USE_UNCOMMON_MIXER to detect unsupported/insufficiently supported mixers. - Custom mixers always pass the check. - Mixer mode resets to MIXER_CUSTOM if motorCount != 0 but motor array is NULL. - Mixer mode resets to MIXER_CUSTOM_AIRPLANE if useServo but servo count is zero. --- src/main/fc/config.c | 14 +++++++++++--- src/main/flight/servos.c | 7 ------- src/main/flight/servos.h | 8 ++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 437abd0500..1225eb058f 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -546,11 +546,19 @@ void activateConfig(void) void validateAndFixConfig(void) { -#if !defined(USE_UNCOMMON_MIXERS) && !defined(USE_QUAD_MIXER_ONLY) && !defined(USE_OSD_SLAVE) +#if !defined(USE_QUAD_MIXER_ONLY) && !defined(USE_OSD_SLAVE) + // Reset unsupported mixer mode to default. + // This check will be gone when motor/servo mixers are loaded dynamically + // by configurator as a part of configuration procedure. + mixerMode_e mixerMode = mixerConfigMutable()->mixerMode; - if (mixerMode != MIXER_CUSTOM && mixerMode != MIXER_CUSTOM_AIRPLANE && mixerMode != MIXER_CUSTOM_TRI && mixerMode != MIXER_GIMBAL && mixerMode != MIXER_PPM_TO_SERVO && mixers[mixerMode].motor == NULL) { - mixerConfigMutable()->mixerMode = MIXER_CUSTOM; + if (!(mixerMode == MIXER_CUSTOM || mixerMode == MIXER_CUSTOM_AIRPLANE || mixerMode == MIXER_CUSTOM_TRI)) { + if (mixers[mixerMode].motorCount && mixers[mixerMode].motor == NULL) + mixerConfigMutable()->mixerMode = MIXER_CUSTOM; + + if (mixers[mixerMode].useServo && servoMixers[mixerMode].servoRuleCount == 0) + mixerConfigMutable()->mixerMode = MIXER_CUSTOM_AIRPLANE; } #endif diff --git a/src/main/flight/servos.c b/src/main/flight/servos.c index c2113e0c3d..64e8ba8227 100755 --- a/src/main/flight/servos.c +++ b/src/main/flight/servos.c @@ -148,13 +148,6 @@ static const servoMixer_t servoMixerGimbal[] = { { SERVO_GIMBAL_ROLL, INPUT_GIMBAL_ROLL, 125, 0, 0, 100, 0 }, }; - -// Custom mixer configuration -typedef struct mixerRules_s { - uint8_t servoRuleCount; - const servoMixer_t *rule; -} mixerRules_t; - const mixerRules_t servoMixers[] = { { 0, NULL }, // entry 0 { COUNT_SERVO_RULES(servoMixerTri), servoMixerTri }, // MULTITYPE_TRI diff --git a/src/main/flight/servos.h b/src/main/flight/servos.h index 6478c6070e..fe7a4db7d4 100644 --- a/src/main/flight/servos.h +++ b/src/main/flight/servos.h @@ -91,6 +91,14 @@ typedef struct servoMixer_s { PG_DECLARE_ARRAY(servoMixer_t, MAX_SERVO_RULES, customServoMixers); +// Custom mixer configuration +typedef struct mixerRules_s { + uint8_t servoRuleCount; + const servoMixer_t *rule; +} mixerRules_t; + +extern const mixerRules_t servoMixers[]; + typedef struct servoParam_s { uint32_t reversedSources; // the direction of servo movement for each input source of the servo mixer, bit set=inverted int16_t min; // servo min