1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 17:55:28 +03:00

Remove some unnecessary checks for mixer mode; Update state flags when mixer mode is changed

This commit is contained in:
Konstantin Sharlaimov (DigitalEntity) 2017-01-30 01:30:31 +10:00
parent 73a5459828
commit bbacaa7705
5 changed files with 29 additions and 25 deletions

View file

@ -242,6 +242,7 @@ void init(void)
#ifdef USE_SERVOS #ifdef USE_SERVOS
servosInit(); servosInit();
mixerUpdateStateFlags(); // This needs to be called early to allow pwm mapper to use information about FIXED_WING state
#endif #endif
drv_pwm_config_t pwm_params; drv_pwm_config_t pwm_params;
@ -259,10 +260,7 @@ void init(void)
#endif #endif
// when using airplane/wing mixer, servo/motor outputs are remapped // when using airplane/wing mixer, servo/motor outputs are remapped
if (mixerConfig()->mixerMode == MIXER_AIRPLANE || mixerConfig()->mixerMode == MIXER_FLYING_WING || mixerConfig()->mixerMode == MIXER_CUSTOM_AIRPLANE) pwm_params.airplane = STATE(FIXED_WING);
pwm_params.airplane = true;
else
pwm_params.airplane = false;
#if defined(USE_UART2) && defined(STM32F10X) #if defined(USE_UART2) && defined(STM32F10X)
pwm_params.useUART2 = doesConfigurationUsePort(SERIAL_PORT_USART2); pwm_params.useUART2 = doesConfigurationUsePort(SERIAL_PORT_USART2);
#endif #endif

View file

@ -273,14 +273,12 @@ static void initActiveBoxIds(void)
if (feature(FEATURE_SERVO_TILT)) if (feature(FEATURE_SERVO_TILT))
activeBoxIds[activeBoxIdCount++] = BOXCAMSTAB; activeBoxIds[activeBoxIdCount++] = BOXCAMSTAB;
bool isFixedWing = mixerConfig()->mixerMode == MIXER_FLYING_WING || mixerConfig()->mixerMode == MIXER_AIRPLANE || mixerConfig()->mixerMode == MIXER_CUSTOM_AIRPLANE;
#ifdef GPS #ifdef GPS
if (sensors(SENSOR_BARO) || (isFixedWing && feature(FEATURE_GPS))) { if (sensors(SENSOR_BARO) || (STATE(FIXED_WING) && feature(FEATURE_GPS))) {
activeBoxIds[activeBoxIdCount++] = BOXNAVALTHOLD; activeBoxIds[activeBoxIdCount++] = BOXNAVALTHOLD;
activeBoxIds[activeBoxIdCount++] = BOXSURFACE; activeBoxIds[activeBoxIdCount++] = BOXSURFACE;
} }
if ((feature(FEATURE_GPS) && sensors(SENSOR_MAG) && sensors(SENSOR_ACC)) || (isFixedWing && sensors(SENSOR_ACC) && feature(FEATURE_GPS))) { if ((feature(FEATURE_GPS) && sensors(SENSOR_MAG) && sensors(SENSOR_ACC)) || (STATE(FIXED_WING) && sensors(SENSOR_ACC) && feature(FEATURE_GPS))) {
activeBoxIds[activeBoxIdCount++] = BOXNAVPOSHOLD; activeBoxIds[activeBoxIdCount++] = BOXNAVPOSHOLD;
activeBoxIds[activeBoxIdCount++] = BOXNAVRTH; activeBoxIds[activeBoxIdCount++] = BOXNAVRTH;
activeBoxIds[activeBoxIdCount++] = BOXNAVWP; activeBoxIds[activeBoxIdCount++] = BOXNAVWP;
@ -289,7 +287,7 @@ static void initActiveBoxIds(void)
} }
#endif #endif
if (isFixedWing) { if (STATE(FIXED_WING)) {
activeBoxIds[activeBoxIdCount++] = BOXPASSTHRU; activeBoxIds[activeBoxIdCount++] = BOXPASSTHRU;
activeBoxIds[activeBoxIdCount++] = BOXNAVLAUNCH; activeBoxIds[activeBoxIdCount++] = BOXNAVLAUNCH;
activeBoxIds[activeBoxIdCount++] = BOXAUTOTRIM; activeBoxIds[activeBoxIdCount++] = BOXAUTOTRIM;
@ -300,7 +298,7 @@ static void initActiveBoxIds(void)
* FLAPERON mode active only in case of airplane and custom airplane. Activating on * FLAPERON mode active only in case of airplane and custom airplane. Activating on
* flying wing can cause bad thing * flying wing can cause bad thing
*/ */
if (mixerConfig()->mixerMode == MIXER_AIRPLANE || mixerConfig()->mixerMode == MIXER_CUSTOM_AIRPLANE) { if (STATE(FLAPERON_AVAILABLE)) {
activeBoxIds[activeBoxIdCount++] = BOXFLAPERON; activeBoxIds[activeBoxIdCount++] = BOXFLAPERON;
} }
#endif #endif
@ -1845,6 +1843,7 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
#ifndef USE_QUAD_MIXER_ONLY #ifndef USE_QUAD_MIXER_ONLY
case MSP_SET_MIXER: case MSP_SET_MIXER:
mixerConfigMutable()->mixerMode = sbufReadU8(src); mixerConfigMutable()->mixerMode = sbufReadU8(src);
mixerUpdateStateFlags(); // Required for correct preset functionality
break; break;
#endif #endif

View file

@ -304,6 +304,27 @@ bool isMixerEnabled(mixerMode_e mixerMode)
} }
#ifdef USE_SERVOS #ifdef USE_SERVOS
void mixerUpdateStateFlags(void)
{
const mixerMode_e currentMixerMode = mixerConfig()->mixerMode;
// set flag that we're on something with wings
if (currentMixerMode == MIXER_FLYING_WING ||
currentMixerMode == MIXER_AIRPLANE ||
currentMixerMode == MIXER_CUSTOM_AIRPLANE
) {
ENABLE_STATE(FIXED_WING);
} else {
DISABLE_STATE(FIXED_WING);
}
if (currentMixerMode == MIXER_AIRPLANE || currentMixerMode == MIXER_CUSTOM_AIRPLANE) {
ENABLE_STATE(FLAPERON_AVAILABLE);
} else {
DISABLE_STATE(FLAPERON_AVAILABLE);
}
}
void mixerUsePWMIOConfiguration(void) void mixerUsePWMIOConfiguration(void)
{ {
int i; int i;

View file

@ -123,6 +123,7 @@ extern bool motorLimitReached;
void writeAllMotors(int16_t mc); void writeAllMotors(int16_t mc);
void mixerLoadMix(int index, motorMixer_t *customMixers); void mixerLoadMix(int index, motorMixer_t *customMixers);
void mixerUsePWMIOConfiguration(void); void mixerUsePWMIOConfiguration(void);
void mixerUpdateStateFlags(void);
void mixerResetDisarmedMotors(void); void mixerResetDisarmedMotors(void);
void mixTable(void); void mixTable(void);
void writeMotors(void); void writeMotors(void);

View file

@ -199,21 +199,6 @@ int servoDirection(int servoIndex, int inputSource)
void servosInit(void) void servosInit(void)
{ {
const mixerMode_e currentMixerMode = mixerConfig()->mixerMode; const mixerMode_e currentMixerMode = mixerConfig()->mixerMode;
// set flag that we're on something with wings
if (currentMixerMode == MIXER_FLYING_WING ||
currentMixerMode == MIXER_AIRPLANE ||
currentMixerMode == MIXER_CUSTOM_AIRPLANE
) {
ENABLE_STATE(FIXED_WING);
} else {
DISABLE_STATE(FIXED_WING);
}
if (currentMixerMode == MIXER_AIRPLANE || currentMixerMode == MIXER_CUSTOM_AIRPLANE) {
ENABLE_STATE(FLAPERON_AVAILABLE);
} else {
DISABLE_STATE(FLAPERON_AVAILABLE);
}
minServoIndex = servoMixers[currentMixerMode].minServoIndex; minServoIndex = servoMixers[currentMixerMode].minServoIndex;
maxServoIndex = servoMixers[currentMixerMode].maxServoIndex; maxServoIndex = servoMixers[currentMixerMode].maxServoIndex;