From 8282bc76d2037e4e88fb0eba5db94ebdb1fbfad3 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Thu, 26 Feb 2015 12:05:03 +0000 Subject: [PATCH] Mixer code readability and code size improvement. Naze target size before: 113412, after: 113388 Closes #551 --- src/main/flight/mixer.c | 55 ++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index 31af981d3..875ea3bb0 100755 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -26,6 +26,7 @@ #include "common/axis.h" #include "common/maths.h" +#include "drivers/system.h" #include "drivers/gpio.h" #include "drivers/timer.h" #include "drivers/pwm_output.h" @@ -544,7 +545,6 @@ static void airplaneMixer(void) void mixTable(void) { - int16_t maxMotor; uint32_t i; if (motorCount > 3) { @@ -662,29 +662,42 @@ void mixTable(void) } #endif - maxMotor = motor[0]; - for (i = 1; i < motorCount; i++) - if (motor[i] > maxMotor) - maxMotor = motor[i]; - for (i = 0; i < motorCount; i++) { - if (maxMotor > escAndServoConfig->maxthrottle) // this is a way to still have good gyro corrections if at least one motor reaches its max. - motor[i] -= maxMotor - escAndServoConfig->maxthrottle; - if (feature(FEATURE_3D)) { - if ((rcData[THROTTLE]) > rxConfig->midrc) { - motor[i] = constrain(motor[i], flight3DConfig->deadband3d_high, escAndServoConfig->maxthrottle); - } else { - motor[i] = constrain(motor[i], escAndServoConfig->mincommand, flight3DConfig->deadband3d_low); + if (ARMING_FLAG(ARMED)) { + + int16_t maxMotor; + + maxMotor = 0; + for (i = 1; i < motorCount; i++) { + if (motor[i] > maxMotor) { + maxMotor = motor[i]; } - } else { - motor[i] = constrain(motor[i], escAndServoConfig->minthrottle, escAndServoConfig->maxthrottle); - if ((rcData[THROTTLE]) < rxConfig->mincheck) { - if (!feature(FEATURE_MOTOR_STOP)) - motor[i] = escAndServoConfig->minthrottle; - else - motor[i] = escAndServoConfig->mincommand; + } + + for (i = 0; i < motorCount; i++) { + if (maxMotor > escAndServoConfig->maxthrottle) { + // this is a way to still have good gyro corrections if at least one motor reaches its max. + motor[i] -= maxMotor - escAndServoConfig->maxthrottle; + } + + if (feature(FEATURE_3D)) { + if ((rcData[THROTTLE]) > rxConfig->midrc) { + motor[i] = constrain(motor[i], flight3DConfig->deadband3d_high, escAndServoConfig->maxthrottle); + } else { + motor[i] = constrain(motor[i], escAndServoConfig->mincommand, flight3DConfig->deadband3d_low); + } + } else { + motor[i] = constrain(motor[i], escAndServoConfig->minthrottle, escAndServoConfig->maxthrottle); + if ((rcData[THROTTLE]) < rxConfig->mincheck) { + if (!feature(FEATURE_MOTOR_STOP)) + motor[i] = escAndServoConfig->minthrottle; + else + motor[i] = escAndServoConfig->mincommand; + } } } - if (!ARMING_FLAG(ARMED)) { + + } else { + for (i = 0; i < motorCount; i++) { motor[i] = motor_disarmed[i]; } } -- 2.11.4.GIT