Skip to content

Commit

Permalink
Refactor mixer motor_stop handling - reduces flash usage
Browse files Browse the repository at this point in the history
Rearranges the placement of the motor_stop handling logic in relationship to the motor output calculations.

Saves 4124 bytes of flash on F3.
  • Loading branch information
etracer65 committed Oct 18, 2018
1 parent 9ab8370 commit 79abfb0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/main/flight/mixer.c
Expand Up @@ -712,12 +712,6 @@ static void applyMixToMotors(float motorMix[MAX_SUPPORTED_MOTORS])
} else {
motorOutput = constrain(motorOutput, motorRangeMin, motorRangeMax);
}
// Motor stop handling
if (featureIsEnabled(FEATURE_MOTOR_STOP) && ARMING_FLAG(ARMED) && !featureIsEnabled(FEATURE_3D) && !isAirmodeActive()) {
if (((rcData[THROTTLE]) < rxConfig()->mincheck)) {
motorOutput = disarmMotorOutput;
}
}
motor[i] = motorOutput;
}

Expand All @@ -744,6 +738,13 @@ float applyThrottleLimit(float throttle)
return throttle;
}

void applyMotorStop(void)
{
for (int i = 0; i < motorCount; i++) {
motor[i] = disarmMotorOutput;
}
}

FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensation)
{
if (isFlipOverAfterCrashMode()) {
Expand Down Expand Up @@ -844,8 +845,17 @@ FAST_CODE_NOINLINE void mixTable(timeUs_t currentTimeUs, uint8_t vbatPidCompensa
}
}

// Apply the mix to motor endpoints
applyMixToMotors(motorMix);
if (featureIsEnabled(FEATURE_MOTOR_STOP)
&& ARMING_FLAG(ARMED)
&& !featureIsEnabled(FEATURE_3D)
&& !isAirmodeActive()
&& (rcData[THROTTLE] < rxConfig()->mincheck)) {
// motor_stop handling
applyMotorStop();
} else {
// Apply the mix to motor endpoints
applyMixToMotors(motorMix);
}
}

float convertExternalToMotor(uint16_t externalValue)
Expand Down

0 comments on commit 79abfb0

Please sign in to comment.