diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index d80d010e46..986f48210a 100755 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -240,6 +240,10 @@ static motorMixer_t *customMixers; static uint16_t disarmMotorOutput, minMotorOutputNormal, maxMotorOutputNormal, deadbandMotor3dHigh, deadbandMotor3dLow; static float rcCommandThrottleRange; +uint8_t getMotorCount() { + return motorCount; +} + bool isMotorProtocolDshot(void) { #ifdef USE_DSHOT if (motorConfig->motorPwmProtocol == PWM_TYPE_DSHOT150 || motorConfig->motorPwmProtocol == PWM_TYPE_DSHOT300 || motorConfig->motorPwmProtocol == PWM_TYPE_DSHOT600) diff --git a/src/main/flight/mixer.h b/src/main/flight/mixer.h index b329128b80..b0c530df39 100644 --- a/src/main/flight/mixer.h +++ b/src/main/flight/mixer.h @@ -115,6 +115,8 @@ extern int16_t motor_disarmed[MAX_SUPPORTED_MOTORS]; struct motorConfig_s; struct rxConfig_s; +uint8_t getMotorCount(); + void mixerUseConfigs( flight3DConfig_t *flight3DConfigToUse, struct motorConfig_s *motorConfigToUse, diff --git a/src/main/telemetry/esc_telemetry.c b/src/main/telemetry/esc_telemetry.c index b55785d510..9d5cde0f1e 100644 --- a/src/main/telemetry/esc_telemetry.c +++ b/src/main/telemetry/esc_telemetry.c @@ -90,7 +90,6 @@ static serialPort_t *escTelemetryPort = NULL; static esc_telemetry_t escTelemetryData[MAX_SUPPORTED_MOTORS]; static uint32_t escTriggerTimestamp = -1; static uint32_t escTriggerLastTimestamp = -1; -static uint8_t enabledMotorCount; static uint8_t timeoutRetryCount = 0; static uint8_t escTelemetryMotor = 0; // motor index @@ -142,12 +141,6 @@ bool escTelemetryInit(void) escTelemetryEnabled = true; masterConfig.batteryConfig.currentMeterType = CURRENT_SENSOR_ESC; masterConfig.batteryConfig.batteryMeterType = BATTERY_SENSOR_ESC; - - //Determine number of enabled motors - enabledMotorCount = 0; - while(enabledMotorCount < MAX_SUPPORTED_MOTORS && pwmGetMotors()[enabledMotorCount].enabled) { - enabledMotorCount++; - } } return escTelemetryPort != NULL; @@ -254,12 +247,12 @@ void escTelemetryProcess(uint32_t currentTime) if (state == ESC_TLM_FRAME_COMPLETE) { // Wait until all ESCs are processed - if (escTelemetryMotor == enabledMotorCount-1) { + if (escTelemetryMotor == getMotorCount()-1) { escCurrent = 0; escConsumption = 0; escVbat = 0; - for (int i = 0; i < enabledMotorCount; i++) { + for (int i = 0; i < getMotorCount(); i++) { if (!escTelemetryData[i].skipped) { escVbat = i > 0 ? ((escVbat + escTelemetryData[i].voltage) / 2) : escTelemetryData[i].voltage; escCurrent = escCurrent + escTelemetryData[i].current; @@ -288,7 +281,7 @@ void escTelemetryProcess(uint32_t currentTime) static void selectNextMotor(void) { escTelemetryMotor++; - if (escTelemetryMotor == enabledMotorCount) { + if (escTelemetryMotor == getMotorCount()) { escTelemetryMotor = 0; } escTriggerTimestamp = millis();