From 94c0f87c45933fbf25728d30e3c7cc0cfeb1d3cd Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Fri, 18 Apr 2014 21:15:50 +0100 Subject: [PATCH] Remove useServos from core_t since it's only needed for initial startup and by the mixer. main.c now asks the mixer if it needs to use servos and the mixer decides this in mixerInit(). Main already has a dependency on the mixer. This allows future commits to further clean up core_t which is still a source of dependency problems. --- src/flight_mixer.c | 13 ++++++++++--- src/flight_mixer.h | 2 ++ src/main.c | 5 +++-- src/runtime_config.h | 1 - 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/flight_mixer.c b/src/flight_mixer.c index b1105aed4d..603959d20d 100755 --- a/src/flight_mixer.c +++ b/src/flight_mixer.c @@ -12,6 +12,8 @@ int16_t motor[MAX_MOTORS]; int16_t motor_disarmed[MAX_MOTORS]; int16_t servo[MAX_SERVOS] = { 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500 }; +static int useServo; + static motorMixer_t currentMixer[MAX_MOTORS]; static const motorMixer_t mixerTri[] = { @@ -189,10 +191,10 @@ void mixerInit(void) int i; // enable servos for mixes that require them. note, this shifts motor counts. - core.useServo = mixers[mcfg.mixerConfiguration].useServo; + useServo = mixers[mcfg.mixerConfiguration].useServo; // if we want camstab/trig, that also enables servos, even if mixer doesn't if (feature(FEATURE_SERVO_TILT)) - core.useServo = 1; + useServo = 1; if (mcfg.mixerConfiguration == MULTITYPE_CUSTOM) { // load custom mixer into currentMixer @@ -266,7 +268,7 @@ static void updateGimbalServos(void) void writeServos(void) { - if (!core.useServo) + if (!useServo) return; switch (mcfg.mixerConfiguration) { @@ -521,3 +523,8 @@ void mixTable(void) } } } + +bool isMixerUsingServos(void) +{ + return useServo; +} diff --git a/src/flight_mixer.h b/src/flight_mixer.h index d5c1919bcd..8398c084fe 100644 --- a/src/flight_mixer.h +++ b/src/flight_mixer.h @@ -52,3 +52,5 @@ typedef struct servoParam_t { int8_t rate; // range [-100;+100] ; can be used to ajust a rate 0-100% and a direction int8_t forwardFromChannel; // RX channel index, 0 based. See CHANNEL_FORWARDING_DISABLED } servoParam_t; + +bool isMixerUsingServos(void); diff --git a/src/main.c b/src/main.c index 971470331c..a12b05ef44 100755 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #include "board.h" #include "flight_common.h" +#include "flight_mixer.h" #include "mw.h" #include "gps_common.h" @@ -44,7 +45,7 @@ int main(void) // We have these sensors; SENSORS_SET defined in board.h depending on hardware platform sensorsSet(SENSORS_SET); - mixerInit(); // this will set core.useServo var depending on mixer type + mixerInit(); // when using airplane/wing mixer, servo/motor outputs are remapped if (mcfg.mixerConfiguration == MULTITYPE_AIRPLANE || mcfg.mixerConfiguration == MULTITYPE_FLYING_WING) pwm_params.airplane = true; @@ -54,7 +55,7 @@ int main(void) pwm_params.useSoftSerial = feature(FEATURE_SOFTSERIAL); pwm_params.usePPM = feature(FEATURE_PPM); pwm_params.enableInput = !feature(FEATURE_SERIALRX); // disable inputs if using spektrum - pwm_params.useServos = core.useServo; + pwm_params.useServos = isMixerUsingServos(); pwm_params.extraServos = cfg.gimbal_flags & GIMBAL_FORWARDAUX; pwm_params.motorPwmRate = mcfg.motor_pwm_rate; pwm_params.servoPwmRate = mcfg.servo_pwm_rate; diff --git a/src/runtime_config.h b/src/runtime_config.h index 347b80b585..d9bfb9483c 100644 --- a/src/runtime_config.h +++ b/src/runtime_config.h @@ -54,7 +54,6 @@ typedef struct core_t { serialPort_t *telemport; serialPort_t *rcvrport; uint8_t mpu6050_scale; // es/non-es variance between MPU6050 sensors, half my boards are mpu6000ES, need this to be dynamic. automatically set by mpu6050 driver. - bool useServo; // feature SERVO_TILT or wing/airplane mixers will enable this } core_t; typedef void (* pidControllerFuncPtr)(void); // pid controller function prototype