diff --git a/locales/en/messages.json b/locales/en/messages.json index 560801ec..8669bc5d 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -2559,7 +2559,7 @@ "message": "I understand the risks, the propellers are removed - enable motor control and arming, and disable Runaway Takeoff Prevention." }, "motorsDialogMixerReset": { - "message": "Invalid mixer mode selected.

The {{mixerName}} model needs {{mixerMotors}} motor resources.

If using a custom mixer mode you need to define a custom mmix before changing mixer mode. If you come back to the motor tab after setting a mmix for your mode it won't reset the mode anymore. Please see the wiki for more information how to set this up.

You are not able to test any motors or fly because firmware has {{outputs}} outputs for the selected mode.

Resetting to default mixer mode" + "message": "Mixer mode problem detected

The {{mixerName}} model needs {{mixerMotors}} motor resources and the current configuration of the firmware provides {{outputs}} usable output(s) for the selected mode.

If using a custom mixer mode you need to define a custom mmix before changing mixer mode.

Please check your configuration and add the required motor resources." }, "motorsDialogSettingsChanged": { "message": "Configuration changes have been detected.

Motor Test Mode is disabled until the settings have seen saved." diff --git a/src/js/tabs/motors.js b/src/js/tabs/motors.js index 12b11446..5f938f10 100644 --- a/src/js/tabs/motors.js +++ b/src/js/tabs/motors.js @@ -330,6 +330,8 @@ TABS.motors.initialize = function (callback) { }); } + sortElement('select.mixerList'); + function refreshMixerPreview() { const mixer = FC.MIXER_CONFIG.mixer; const reverse = FC.MIXER_CONFIG.reverseMotorDir ? "_reversed" : ""; @@ -608,6 +610,12 @@ TABS.motors.initialize = function (callback) { neutral3d = (FC.MOTOR_3D_CONFIG.neutral > 1575 || FC.MOTOR_3D_CONFIG.neutral < 1425) ? 1500 : FC.MOTOR_3D_CONFIG.neutral; } + let zeroThrottleValue = rangeMin; + + if (self.feature3DEnabled) { + zeroThrottleValue = neutral3d; + } + const motorsWrapper = $('.motors .bar-wrapper'); for (let i = 0; i < 8; i++) { @@ -643,6 +651,8 @@ TABS.motors.initialize = function (callback) { escProtocolElement.append(``); } + sortElement('select.escprotocol'); + const unsyncedPWMSwitchElement = $("input[id='unsyncedPWMSwitch']"); const divUnsyncedPWMFreq = $('div.unsyncedpwmfreq'); @@ -743,7 +753,7 @@ TABS.motors.initialize = function (callback) { } escProtocolElement.val(FC.PID_ADVANCED_CONFIG.fast_pwm_protocol + 1); - console.log(FC.PID_ADVANCED_CONFIG.fast_pwm_protocol); + escProtocolElement.on("change", function () { const escProtocolValue = parseInt($(this).val()) - 1; @@ -818,11 +828,7 @@ TABS.motors.initialize = function (callback) { function setSlidersDefault() { // change all values to default - if (self.feature3DEnabled) { - $('div.sliders input').val(neutral3d); - } else { - $('div.sliders input').val(rangeMin); - } + $('div.sliders input').val(zeroThrottleValue); } function setSlidersEnabled(isEnabled) { @@ -903,7 +909,7 @@ TABS.motors.initialize = function (callback) { for (let i = 0; i < self.numberOfValidOutputs; i++) { if (!self.feature3DEnabled) { - if (FC.MOTOR_DATA[i] > rangeMin) { + if (FC.MOTOR_DATA[i] > zeroThrottleValue) { motorsRunning = true; } } else { @@ -965,7 +971,7 @@ TABS.motors.initialize = function (callback) { const motorsTesting = motorsEnableTestModeElement.is(':checked'); for (let i = 0; i < self.numberOfValidOutputs; i++) { - motorData[i] = motorsTesting ? FC.MOTOR_DATA[i] : rangeMin; + motorData[i] = motorsTesting ? FC.MOTOR_DATA[i] : zeroThrottleValue; } return motorData; @@ -1034,7 +1040,7 @@ TABS.motors.initialize = function (callback) { //keep the following here so at least we get a visual cue of our motor setup update_arm_status(); - if (previousArmState != self.armed) { + if (previousArmState !== self.armed) { console.log('arm state change detected'); motorsEnableTestModeElement.change(); @@ -1083,12 +1089,6 @@ TABS.motors.initialize = function (callback) { // enable Status and Motor data pulling GUI.interval_add('motor_and_status_pull', get_status, 50, true); - let zeroThrottleValue = rangeMin; - - if (self.feature3DEnabled) { - zeroThrottleValue = neutral3d; - } - setup_motor_output_reordering_dialog(SetupEscDshotDirectionDialogCallback, zeroThrottleValue); function SetupEscDshotDirectionDialogCallback() { @@ -1116,12 +1116,6 @@ TABS.motors.initialize = function (callback) { dialogMixerReset.showModal(); $('#dialog-mixer-reset-confirmbtn').click(function() { dialogMixerReset.close(); - - FC.MIXER_CONFIG.mixer = 3; - - MSP.promise(MSPCodes.MSP_SET_MIXER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_MIXER_CONFIG)) - .then(() => MSP.promise(MSPCodes.MSP_EEPROM_WRITE)) - .then(() => reboot()); }); } } diff --git a/src/js/utils/common.js b/src/js/utils/common.js index 22ce6e35..2e2e108a 100644 --- a/src/js/utils/common.js +++ b/src/js/utils/common.js @@ -32,11 +32,8 @@ export function bytesToSize(bytes) { export function checkChromeRuntimeError() { if (chrome.runtime.lastError) { - console.error( - `Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${ - new Error().stack - }` - ); + console.error(`Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${new Error().stack}`); + return true; } return false; @@ -54,9 +51,7 @@ const majorFirmwareVersions = { }; export function generateVirtualApiVersions() { - const firmwareVersionDropdown = document.getElementById( - "firmware-version-dropdown" - ); + const firmwareVersionDropdown = document.getElementById("firmware-version-dropdown"); const max = semver.minor(CONFIGURATOR.API_VERSION_MAX_SUPPORTED); for (let i = max; i > 0; i--) { @@ -94,6 +89,21 @@ export function getTextWidth(text) { return Math.ceil(context.measureText(text).width); } +export function sortElement(element, keepDown = "DISABLED") { + const list = document.querySelector(element); + [...list.children] + .sort((a, b) => { + if (a.innerText === keepDown) { + return 1; + } else if (b.innerText === keepDown) { + return -1; + } else { + return a.innerText > b.innerText ? 1 : -1; + } + }) + .forEach(node => list.appendChild(node)); +} + // TODO: these are temp binding while transition to module happens window.degToRad = degToRad; window.bytesToSize = bytesToSize; @@ -101,3 +111,4 @@ window.checkChromeRuntimeError = checkChromeRuntimeError; window.generateVirtualApiVersions = generateVirtualApiVersions; window.getMixerImageSrc = getMixerImageSrc; window.getTextWidth = getTextWidth; +window.sortElement = sortElement;