From f71fa9a3488f537e890f4b3bd72169f79805e696 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Tue, 16 Jul 2019 21:16:25 +0200 Subject: [PATCH] Output allocation method that is more aligned with FC counterpart --- js/outputMapping.js | 68 ++++++++++++++++++++++++++++++---- js/servoMixerRuleCollection.js | 12 +++++- tabs/mixer.js | 38 ++++--------------- 3 files changed, 79 insertions(+), 39 deletions(-) diff --git a/js/outputMapping.js b/js/outputMapping.js index 227077ac..af8a7305 100644 --- a/js/outputMapping.js +++ b/js/outputMapping.js @@ -16,6 +16,66 @@ let OutputMappingCollection = function () { const TIM_USE_LED = 24; const TIM_USE_BEEPER = 25; + const OUTPUT_TYPE_MOTOR = 0; + const OUTPUT_TYPE_SERVO = 1; + + function getTimerMap(isMR, motors, servos) { + let timerMap = [], + motorsToGo = motors, + servosToGo = servos; + + for (let i = 0; i < data.length; i++) { + timerMap[i] = null; + + if (isMR) { + if (servosToGo > 0 && bit_check(data[i], TIM_USE_MC_SERVO)) { + servosToGo--; + timerMap[i] = OUTPUT_TYPE_SERVO; + } else if (motorsToGo > 0 && bit_check(data[i], TIM_USE_MC_MOTOR)) { + motorsToGo--; + timerMap[i] = OUTPUT_TYPE_MOTOR; + } + } else { + if (servosToGo > 0 && bit_check(data[i], TIM_USE_FW_SERVO)) { + servosToGo--; + timerMap[i] = OUTPUT_TYPE_SERVO; + } else if (motorsToGo > 0 && bit_check(data[i], TIM_USE_FW_MOTOR)) { + motorsToGo--; + timerMap[i] = OUTPUT_TYPE_MOTOR; + } + } + + } + + return timerMap; + }; + + self.getOutputTable = function (isMR, motors, servos) { + let currentMotorIndex = 1, + currentServoIndex = 0, + timerMap = getTimerMap(isMR, motors, servos), + outputMap = [], + offset = getFirstOutputOffset(); + + for (let i = 0; i < self.getOutputCount(); i++) { + + let assignment = timerMap[i + offset]; + + if (assignment === null) { + outputMap[i] = "-"; + } else if (assignment == OUTPUT_TYPE_MOTOR) { + outputMap[i] = "Motor " + currentMotorIndex; + currentMotorIndex++; + } else if (assignment == OUTPUT_TYPE_SERVO) { + outputMap[i] = "Servo " + currentServoIndex; + currentServoIndex++; + } + + } + + return outputMap; + }; + self.flush = function () { data = []; }; @@ -78,14 +138,6 @@ let OutputMappingCollection = function () { return getOutput(servoIndex, TIM_USE_FW_SERVO); }; - self.getFwMotorOutput = function (index) { - return getOutput(index, TIM_USE_FW_MOTOR); - }; - - self.getMrMotorOutput = function (index) { - return getOutput(index, TIM_USE_MC_MOTOR); - }; - self.getMrServoOutput = function (index) { return getOutput(index, TIM_USE_MC_SERVO); }; diff --git a/js/servoMixerRuleCollection.js b/js/servoMixerRuleCollection.js index 439336be..f55a96aa 100644 --- a/js/servoMixerRuleCollection.js +++ b/js/servoMixerRuleCollection.js @@ -70,7 +70,17 @@ let ServoMixerRuleCollection = function () { } } return false; - } + }; + + self.getNumberOfConfiguredServos = function () { + let count = 0; + for (let i = 0; i < self.getServoCount(); i ++) { + if (self.isServoConfigured(i)) { + count++; + } + } + return count; + }; return self; }; \ No newline at end of file diff --git a/tabs/mixer.js b/tabs/mixer.js index a94a2db8..40bcb583 100644 --- a/tabs/mixer.js +++ b/tabs/mixer.js @@ -75,36 +75,14 @@ TABS.mixer.initialize = function (callback, scrollPosition) { } function renderOutputMapping() { - let motorRules = MOTOR_RULES.get(), - servoRules = SERVO_RULES.get(), - output; - - for (var index = 0; index < motorRules.length; index++) { - if (motorRules[index].isUsed()) { - if (MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER) { - output = OUTPUT_MAPPING.getMrMotorOutput(index); - } else { - output = OUTPUT_MAPPING.getFwMotorOutput(index); - } - if (output !== null) { - $('#function-' + output).html("Motor " + (index + 1)); - } - } - } - - let usedServoIndex = 0; - for (let i = 0; i < MIXER_CONFIG.numberOfServos; i++) { - if (SERVO_RULES.isServoConfigured(i)) { - if (MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER) { - output = OUTPUT_MAPPING.getMrServoOutput(usedServoIndex); - } else { - output = OUTPUT_MAPPING.getFwServoOutput(usedServoIndex); - } - if (output !== null) { - $('#function-' + output).html("Servo " + i); - } - usedServoIndex++; - } + let outputMap = OUTPUT_MAPPING.getOutputTable( + MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER, + MOTOR_RULES.getNumberOfConfiguredMotors(), + SERVO_RULES.getNumberOfConfiguredServos() + ); + + for (let i = 1; i <= OUTPUT_MAPPING.getOutputCount(); i++) { + $('#function-' + i).html(outputMap[i - 1]); } }