From 4e07b524e956ba117f851897b92a79a964bd95af Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Fri, 7 Jun 2024 12:08:46 +0200 Subject: [PATCH] Increment minimal supported API to 1_44 (firmware 4.3) (2/4) (#4009) * Update version for motor tab * More cleanup --- locales/en/messages.json | 3 -- src/js/tabs/motors.js | 112 +++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 67 deletions(-) diff --git a/locales/en/messages.json b/locales/en/messages.json index fa1dc96b59..4aaf81566e 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -6770,9 +6770,6 @@ "message": "ESC/Motor protocol" }, "configurationEscProtocolHelp": { - "message": "Select your motor protocol.
Make sure to verify the protocol is supported by your ESC, this information should be on the makers website.
Be carefull using DSHOT900 and DSHOT1200 as not many ESC's support it!" - }, - "configurationEscProtocolHelpNoDSHOT1200": { "message": "Select your motor protocol.
Make sure to verify the protocol is supported by your ESC, this information should be on the makers website." }, "configurationunsyndePwm": { diff --git a/src/js/tabs/motors.js b/src/js/tabs/motors.js index 453d3727ff..a479ff3d5b 100644 --- a/src/js/tabs/motors.js +++ b/src/js/tabs/motors.js @@ -12,11 +12,9 @@ import FC from "../fc"; import MSP from "../msp"; import { mixerList } from "../model"; import MSPCodes from "../msp/MSPCodes"; -import { API_VERSION_1_42, API_VERSION_1_44 } from "../data_storage"; import EscProtocols from "../utils/EscProtocols"; import { updateTabList } from "../utils/updateTabList"; import { isInt, getMixerImageSrc } from "../utils/common"; -import semver from 'semver'; import * as d3 from 'd3'; import $ from 'jquery'; @@ -92,9 +90,7 @@ motors.initialize = async function (callback) { await MSP.promise(MSPCodes.MSP_MOTOR_3D_CONFIG); await MSP.promise(MSPCodes.MSP2_MOTOR_OUTPUT_REORDERING); await MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - await MSP.promise(MSPCodes.MSP_FILTER_CONFIG); - } + await MSP.promise(MSPCodes.MSP_FILTER_CONFIG); await MSP.promise(MSPCodes.MSP_ARMING_CONFIG); load_html(); @@ -261,7 +257,7 @@ motors.initialize = async function (callback) { motorsEnableTestModeElement.prop('checked', self.armed); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42) || !(FC.MOTOR_CONFIG.use_dshot_telemetry || FC.MOTOR_CONFIG.use_esc_sensor)) { + if (!(FC.MOTOR_CONFIG.use_dshot_telemetry || FC.MOTOR_CONFIG.use_esc_sensor)) { $(".motor_testing .telemetry").hide(); } @@ -341,7 +337,7 @@ motors.initialize = async function (callback) { } // Add EventListener for configuration changes - document.querySelectorAll('.configuration').forEach(elem => elem.addEventListener('change', disableHandler)); + document.querySelector('.configuration').addEventListener('change', disableHandler); /* * MIXER @@ -696,57 +692,50 @@ motors.initialize = async function (callback) { $('input[name="digitalIdlePercent"]').val(FC.PID_ADVANCED_CONFIG.digitalIdlePercent); $('input[name="idleMinRpm"]').val(FC.ADVANCED_TUNING.idleMinRpm); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - dshotBidirElement.prop('checked', FC.MOTOR_CONFIG.use_dshot_telemetry).trigger("change"); - - self.previousDshotBidir = FC.MOTOR_CONFIG.use_dshot_telemetry; - self.previousFilterDynQ = FC.FILTER_CONFIG.dyn_notch_q; - self.previousFilterDynCount = FC.FILTER_CONFIG.dyn_notch_count; - - dshotBidirElement.on("change", function () { - const value = dshotBidirElement.is(':checked'); - const newValue = (value !== FC.MOTOR_CONFIG.use_dshot_telemetry) ? 'On' : 'Off'; - self.analyticsChanges['BidirectionalDshot'] = newValue; - FC.MOTOR_CONFIG.use_dshot_telemetry = value; - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - const rpmFilterIsDisabled = FC.FILTER_CONFIG.gyro_rpm_notch_harmonics === 0; - FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount; - FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ; - - const dialogDynFilterSettings = { - title: i18n.getMessage("dialogDynFiltersChangeTitle"), - text: i18n.getMessage("dialogDynFiltersChangeNote"), - buttonYesText: i18n.getMessage("presetsWarningDialogYesButton"), - buttonNoText: i18n.getMessage("presetsWarningDialogNoButton"), - buttonYesCallback: () => _dynFilterChange(), - buttonNoCallback: null, - }; - - const _dynFilterChange = function() { - if (FC.MOTOR_CONFIG.use_dshot_telemetry && !self.previousDshotBidir) { - FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count_rpm; - FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q_rpm; - } else if (!FC.MOTOR_CONFIG.use_dshot_telemetry && self.previousDshotBidir) { - FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count; - FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q; - } - }; - - if ((FC.MOTOR_CONFIG.use_dshot_telemetry !== self.previousDshotBidir) && !(rpmFilterIsDisabled)) { - GUI.showYesNoDialog(dialogDynFilterSettings); - } else { - FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount; - FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ; - } + dshotBidirElement.prop('checked', FC.MOTOR_CONFIG.use_dshot_telemetry).trigger("change"); + + self.previousDshotBidir = FC.MOTOR_CONFIG.use_dshot_telemetry; + self.previousFilterDynQ = FC.FILTER_CONFIG.dyn_notch_q; + self.previousFilterDynCount = FC.FILTER_CONFIG.dyn_notch_count; + + dshotBidirElement.on("change", function () { + const value = dshotBidirElement.is(':checked'); + const newValue = (value !== FC.MOTOR_CONFIG.use_dshot_telemetry) ? 'On' : 'Off'; + self.analyticsChanges['BidirectionalDshot'] = newValue; + FC.MOTOR_CONFIG.use_dshot_telemetry = value; + + const rpmFilterIsDisabled = FC.FILTER_CONFIG.gyro_rpm_notch_harmonics === 0; + FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount; + FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ; + + const dialogDynFilterSettings = { + title: i18n.getMessage("dialogDynFiltersChangeTitle"), + text: i18n.getMessage("dialogDynFiltersChangeNote"), + buttonYesText: i18n.getMessage("presetsWarningDialogYesButton"), + buttonNoText: i18n.getMessage("presetsWarningDialogNoButton"), + buttonYesCallback: () => _dynFilterChange(), + buttonNoCallback: null, + }; + + const _dynFilterChange = function() { + if (FC.MOTOR_CONFIG.use_dshot_telemetry && !self.previousDshotBidir) { + FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count_rpm; + FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q_rpm; + } else if (!FC.MOTOR_CONFIG.use_dshot_telemetry && self.previousDshotBidir) { + FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count; + FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q; } - }); + }; - $('input[name="motorPoles"]').val(FC.MOTOR_CONFIG.motor_poles); - } + if ((FC.MOTOR_CONFIG.use_dshot_telemetry !== self.previousDshotBidir) && !(rpmFilterIsDisabled)) { + GUI.showYesNoDialog(dialogDynFilterSettings); + } else { + FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount; + FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ; + } + }); - $('#escProtocolTooltip').toggle(semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42)); - $('#escProtocolTooltipNoDSHOT1200').toggle(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)); + $('input[name="motorPoles"]').val(FC.MOTOR_CONFIG.motor_poles); function updateVisibility() { // Hide unused settings @@ -757,7 +746,6 @@ motors.initialize = async function (callback) { case 'DSHOT150': case 'DSHOT300': case 'DSHOT600': - case 'DSHOT1200': case 'PROSHOT1000': digitalProtocol = true; @@ -782,8 +770,8 @@ motors.initialize = async function (callback) { $('.escSensor').toggle(protocolConfigured && digitalProtocol); - $('div.checkboxDshotBidir').toggle(protocolConfigured && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42) && digitalProtocol); - $('div.motorPoles').toggle(protocolConfigured && rpmFeaturesVisible && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)); + $('div.checkboxDshotBidir').toggle(protocolConfigured && digitalProtocol); + $('div.motorPoles').toggle(protocolConfigured && rpmFeaturesVisible); $('.escMotorStop').toggle(protocolConfigured); @@ -1151,9 +1139,7 @@ motors.initialize = async function (callback) { FC.MOTOR_CONFIG.maxthrottle = parseInt($('input[name="maxthrottle"]').val()); FC.MOTOR_CONFIG.mincommand = parseInt($('input[name="mincommand"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.MOTOR_CONFIG.motor_poles = parseInt($('input[name="motorPoles"]').val()); - } + FC.MOTOR_CONFIG.motor_poles = parseInt($('input[name="motorPoles"]').val()); FC.MOTOR_3D_CONFIG.deadband3d_low = parseInt($('input[name="_3ddeadbandlow"]').val()); FC.MOTOR_3D_CONFIG.deadband3d_high = parseInt($('input[name="_3ddeadbandhigh"]').val()); @@ -1171,9 +1157,7 @@ motors.initialize = async function (callback) { await MSP.promise(MSPCodes.MSP_SET_ADVANCED_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ADVANCED_CONFIG)); await MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG)); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - await MSP.promise(MSPCodes.MSP_SET_FILTER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FILTER_CONFIG)); - } + await MSP.promise(MSPCodes.MSP_SET_FILTER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FILTER_CONFIG)); tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'motors'); self.analyticsChanges = {};