diff --git a/locales/en/messages.json b/locales/en/messages.json index c8f9f439..693bf4ae 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -276,25 +276,6 @@ "deviceReady": { "message": "Device - Ready" }, - - "backupFileIncompatible": { - "message": "Backup file provided was generated for previous version of the configurator and is incompatible with this version of configurator. Sorry" - }, - - "backupFileUnmigratable": { - "message": "Backup file provided was generated by a previous version of the configurator and is not migratable. Sorry." - }, - - "configMigrationFrom": { - "message": "Migrating configuration file generated by configurator: $1" - }, - "configMigratedTo": { - "message": "Migrated configuration to configurator: $1" - }, - "configMigrationSuccessful": { - "message": "Configuration migration complete, migrations applied: $1" - }, - "tabFirmwareFlasher": { "message": "Firmware Flasher" }, @@ -768,10 +749,6 @@ "defaultSupport5": { "message": "Betaflight devs on slack" }, - - "initialSetupBackupAndRestoreApiVersion": { - "message": "Backup and restore functionality disabled. You have firmware with API version $1, backup and restore requires $2. Please backup your settings via the CLI, see Betaflight documentation for procedure." - }, "initialSetupButtonCalibrateAccel": { "message": "Calibrate Accelerometer" }, @@ -793,30 +770,12 @@ "initialSetupResetText": { "message": "Restore settings to default" }, - "initialSetupButtonBackup": { - "message": "Backup JSON" - }, - "initialSetupButtonRestore": { - "message": "Restore JSON" - }, "initialSetupButtonRebootBootloader": { "message": "Activate Boot Loader / DFU" }, - "initialSetupBackupRestoreHeader": { - "message": "Experimental Backup and Restore" - }, - "initialSetupBackupRestoreText": { - "message": "Backup your configuration in case of an accident, CLI settings are not included - use the command 'diff all' in CLI for this." - }, "initialSetupRebootBootloaderText": { "message": "Reboot into boot loader / DFU mode." }, - "initialSetupBackupSuccess": { - "message": "Backup saved successfully" - }, - "initialSetupRestoreSuccess": { - "message": "Configuration restored successfully" - }, "initialSetupButtonResetZaxis": { "message": "Reset Z axis, offset: 0 deg" }, diff --git a/src/css/tabs/setup.less b/src/css/tabs/setup.less index 236c8215..78a65008 100644 --- a/src/css/tabs/setup.less +++ b/src/css/tabs/setup.less @@ -171,9 +171,6 @@ float: left; } } -.backupRestore { - margin-bottom: 0; -} .block.info { .fields { padding: 5px 5px 3px 5px; diff --git a/src/js/Beepers.js b/src/js/Beepers.js index b31c9b36..cba055b0 100644 --- a/src/js/Beepers.js +++ b/src/js/Beepers.js @@ -24,22 +24,12 @@ class Beepers { { bit: 16, name: 'SYSTEM_INIT', visible: true }, { bit: 17, name: 'USB', visible: true }, { bit: 18, name: 'BLACKBOX_ERASE', visible: true }, + { bit: 19, name: 'CRASH_FLIP', visible: true }, + { bit: 20, name: 'CAM_CONNECTION_OPEN', visible: true }, + { bit: 21, name: 'CAM_CONNECTION_CLOSE', visible: true }, + { bit: 22, name: 'RC_SMOOTHING_INIT_FAIL', visible: true }, ]; - if (semver.gte(config.apiVersion, API_VERSION_1_37)) { - beepers.push( - { bit: 19, name: 'CRASH_FLIP', visible: true }, - { bit: 20, name: 'CAM_CONNECTION_OPEN', visible: true }, - { bit: 21, name: 'CAM_CONNECTION_CLOSE', visible: true }, - ); - } - - if (semver.gte(config.apiVersion, API_VERSION_1_39)) { - beepers.push( - { bit: 22, name: 'RC_SMOOTHING_INIT_FAIL', visible: true }, - ); - } - if (supportedConditions) { self._beepers = []; beepers.forEach(function (beeper) { diff --git a/src/js/CliAutoComplete.js b/src/js/CliAutoComplete.js index 93abfd15..fff2866f 100644 --- a/src/js/CliAutoComplete.js +++ b/src/js/CliAutoComplete.js @@ -532,34 +532,25 @@ CliAutoComplete._initTextcomplete = function() { }), ]); - if (semver.gte(FC.CONFIG.flightControllerVersion, "4.0.0")) { - $textarea.textcomplete('register', [ - strategy({ // "resource show all", from BF 4.0.0 onwards - match: /^(\s*resource\s+show\s+)(\w*)$/i, - search: function(term, callback) { - sendOnEnter = true; - searcher(term, callback, ['all'], 1, true); - }, - template: highlighterPrefix, - }), - ]); - } - + $textarea.textcomplete('register', [ + strategy({ // "resource show all", from BF 4.0.0 onwards + match: /^(\s*resource\s+show\s+)(\w*)$/i, + search: function(term, callback) { + sendOnEnter = true; + searcher(term, callback, ['all'], 1, true); + }, + template: highlighterPrefix, + }), + ]); // diff command const diffArgs1 = ["master", "profile", "rates", "all"]; const diffArgs2 = []; - if (semver.lt(FC.CONFIG.flightControllerVersion, "3.4.0")) { - diffArgs2.push("showdefaults"); - } else { - // above 3.4.0 - diffArgs2.push("defaults"); - if (semver.gte(FC.CONFIG.flightControllerVersion, "4.0.0")) { - diffArgs1.push("hardware"); - diffArgs2.push("bare"); - } - } + // above 3.4.0 + diffArgs2.push("defaults"); + diffArgs1.push("hardware"); + diffArgs2.push("bare"); diffArgs1.sort(); diffArgs2.sort(); diff --git a/src/js/Features.js b/src/js/Features.js index 06d00585..40bca380 100644 --- a/src/js/Features.js +++ b/src/js/Features.js @@ -5,6 +5,7 @@ const Features = function (config) { const features = [ {bit: 0, group: 'rxMode', mode: 'select', name: 'RX_PPM'}, + {bit: 1, group: 'batteryVoltage', name: 'VBAT'}, {bit: 2, group: 'other', name: 'INFLIGHT_ACC_CAL'}, {bit: 3, group: 'rxMode', mode: 'select', name: 'RX_SERIAL'}, {bit: 4, group: 'escMotorStop', name: 'MOTOR_STOP'}, @@ -13,94 +14,29 @@ const Features = function (config) { {bit: 7, group: 'gps', name: 'GPS', haveTip: true}, {bit: 9, group: 'other', name: 'SONAR'}, {bit: 10, group: 'telemetry', name: 'TELEMETRY'}, + {bit: 11, group: 'batteryCurrent', name: 'CURRENT_METER'}, {bit: 12, group: '3D', name: '3D'}, {bit: 13, group: 'rxMode', mode: 'select', name: 'RX_PARALLEL_PWM'}, {bit: 14, group: 'rxMode', mode: 'select', name: 'RX_MSP'}, {bit: 15, group: 'rssi', name: 'RSSI_ADC'}, {bit: 16, group: 'other', name: 'LED_STRIP'}, {bit: 17, group: 'other', name: 'DISPLAY', haveTip: true}, + {bit: 18, group: 'other', name: 'OSD'}, + {bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true}, + {bit: 20, group: 'other', name: 'CHANNEL_FORWARDING'}, + {bit: 21, group: 'other', name: 'TRANSPONDER', haveTip: true}, + {bit: 22, group: 'other', name: 'AIRMODE'}, + {bit: 25, group: 'rxMode', mode: 'select', name: 'RX_SPI'}, + {bit: 27, group: 'escSensor', name: 'ESC_SENSOR'}, + {bit: 28, group: 'antiGravity', name: 'ANTI_GRAVITY', haveTip: true, hideName: true}, ]; - if (!semver.gte(config.apiVersion, API_VERSION_1_33)) { + if (semver.lt(config.apiVersion, API_VERSION_1_44)) { // DYNAMIC_FILTER got removed from FEATURES in BF 4.3 / API 1.44 features.push( - {bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true}, + {bit: 29, group: 'other', name: 'DYNAMIC_FILTER'}, ); } - if (semver.gte(config.apiVersion, "1.12.0")) { - features.push( - {bit: 20, group: 'other', name: 'CHANNEL_FORWARDING'}, - ); - } - - if (semver.gte(config.apiVersion, "1.15.0") && !semver.gte(config.apiVersion, API_VERSION_1_36)) { - features.push( - {bit: 8, group: 'rxFailsafe', name: 'FAILSAFE', haveTip: true}, - ); - } - - if (semver.gte(config.apiVersion, "1.16.0")) { - features.push( - {bit: 21, group: 'other', name: 'TRANSPONDER', haveTip: true}, - ); - } - - if (config.flightControllerVersion !== '') { - if (semver.gte(config.apiVersion, "1.16.0")) { - features.push( - {bit: 22, group: 'other', name: 'AIRMODE'}, - ); - } - - if (semver.gte(config.apiVersion, "1.16.0")) { - if (semver.lt(config.apiVersion, "1.20.0")) { - features.push( - {bit: 23, group: 'superexpoRates', name: 'SUPEREXPO_RATES'}, - ); - } else if (!semver.gte(config.apiVersion, API_VERSION_1_33)) { - features.push( - {bit: 23, group: 'other', name: 'SDCARD'}, - ); - } - } - - if (semver.gte(config.apiVersion, "1.20.0")) { - features.push( - {bit: 18, group: 'other', name: 'OSD'}, - ); - if (!semver.gte(config.apiVersion, API_VERSION_1_35)) { - features.push( - {bit: 24, group: 'other', name: 'VTX'}, - ); - } - } - - if (semver.gte(config.apiVersion, API_VERSION_1_31)) { - features.push( - {bit: 25, group: 'rxMode', mode: 'select', name: 'RX_SPI'}, - {bit: 27, group: 'escSensor', name: 'ESC_SENSOR'}, - ); - } - - if (semver.gte(config.apiVersion, API_VERSION_1_36)) { - features.push( - {bit: 28, group: 'antiGravity', name: 'ANTI_GRAVITY', haveTip: true, hideName: true}, - ); - if (semver.lt(config.apiVersion, API_VERSION_1_44)) { // DYNAMIC_FILTER got removed from FEATURES in BF 4.3 / API 1.44 - features.push( - {bit: 29, group: 'other', name: 'DYNAMIC_FILTER'}, - ); - } - } - - if (!semver.gte(config.apiVersion, API_VERSION_1_36)) { - features.push( - {bit: 1, group: 'batteryVoltage', name: 'VBAT'}, - {bit: 11, group: 'batteryCurrent', name: 'CURRENT_METER'}, - ); - } - } - self._features = features; self._featureMask = 0; diff --git a/src/js/RateCurve.js b/src/js/RateCurve.js index 19e7d68f..c509ac09 100644 --- a/src/js/RateCurve.js +++ b/src/js/RateCurve.js @@ -87,13 +87,8 @@ const RateCurve = function (useLegacyCurve) { let expoPower; let rcRateConstant; - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - expoPower = 3; - rcRateConstant = 200; - } else { - expoPower = 2; - rcRateConstant = 205.85; - } + expoPower = 3; + rcRateConstant = 200; if (rcExpo > 0) { rcCommandf = rcCommandf * Math.pow(rcCommandfAbs, expoPower) * rcExpo + rcCommandf * (1-rcExpo); @@ -169,23 +164,7 @@ const RateCurve = function (useLegacyCurve) { yaw_rate_limit: FC.RC_TUNING.yaw_rate_limit, }; - if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - currentRates.roll_rate = FC.RC_TUNING.roll_pitch_rate; - currentRates.pitch_rate = FC.RC_TUNING.roll_pitch_rate; - } - - if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) { - currentRates.rc_rate_yaw = currentRates.rc_rate; - } - - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - currentRates.superexpo = true; - } - - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - currentRates.rc_rate_pitch = currentRates.rc_rate; - currentRates.rc_expo_pitch = currentRates.rc_expo; - } + currentRates.superexpo = true; if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { switch (FC.RC_TUNING.rates_type) { diff --git a/src/js/backup_restore.js b/src/js/backup_restore.js deleted file mode 100644 index f0d26725..00000000 --- a/src/js/backup_restore.js +++ /dev/null @@ -1,956 +0,0 @@ -'use strict'; - -// code below is highly experimental, although it runs fine on latest firmware -// the data inside nested objects needs to be verified if deep copy works properly -function configuration_backup(callback) { - let activeProfile = null; - - let version = CONFIGURATOR.version; - - if (version.indexOf(".") === -1) { - version = `${version}.0.0`; - } - - const configuration = { - 'generatedBy': version, - 'apiVersion': FC.CONFIG.apiVersion, - 'profiles': [], - }; - - const profileSpecificData = [ - MSPCodes.MSP_PID_CONTROLLER, - MSPCodes.MSP_PID, - MSPCodes.MSP_RC_TUNING, - MSPCodes.MSP_ACC_TRIM, - MSPCodes.MSP_SERVO_CONFIGURATIONS, - MSPCodes.MSP_MODE_RANGES, - MSPCodes.MSP_ADJUSTMENT_RANGES, - ]; - - function update_profile_specific_data_list() { - if (semver.gt(FC.CONFIG.apiVersion, "1.12.0")) { - profileSpecificData.push(MSPCodes.MSP_SERVO_MIX_RULES); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - profileSpecificData.push(MSPCodes.MSP_RC_DEADBAND); - } - } - - update_profile_specific_data_list(); - - MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () { - activeProfile = FC.CONFIG.profile; - select_profile(); - }); - - function select_profile() { - if (activeProfile > 0) { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [0], false, fetch_specific_data); - } else { - fetch_specific_data(); - } - } - - function fetch_specific_data() { - let fetchingProfile = 0; - let codeKey = 0; - - function fetch_specific_data_item() { - if (fetchingProfile < FC.CONFIG.numProfiles) { - MSP.send_message(profileSpecificData[codeKey], false, false, function () { - codeKey++; - - if (codeKey < profileSpecificData.length) { - fetch_specific_data_item(); - } else { - configuration.profiles.push({ - 'PID': jQuery.extend(true, {}, FC.PID), - 'PIDs': jQuery.extend(true, [], FC.PIDS), - 'RC': jQuery.extend(true, {}, FC.RC_TUNING), - 'AccTrim': jQuery.extend(true, [], FC.CONFIG.accelerometerTrims), - 'ServoConfig': jQuery.extend(true, [], FC.SERVO_CONFIG), - 'ServoRules': jQuery.extend(true, [], FC.SERVO_RULES), - 'ModeRanges': jQuery.extend(true, [], FC.MODE_RANGES), - 'AdjustmentRanges': jQuery.extend(true, [], FC.ADJUSTMENT_RANGES), - }); - - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - configuration.profiles[fetchingProfile].RCdeadband = jQuery.extend(true, {}, FC.RC_DEADBAND_CONFIG); - } - codeKey = 0; - fetchingProfile++; - - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [fetchingProfile], false, fetch_specific_data_item); - } - }); - } else { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [activeProfile], false, fetch_unique_data); - } - } - - // start fetching - fetch_specific_data_item(); - } - - const uniqueData = [ - MSPCodes.MSP_RX_MAP, - MSPCodes.MSP_CF_SERIAL_CONFIG, - MSPCodes.MSP_LED_STRIP_CONFIG, - MSPCodes.MSP_LED_COLORS, - ]; - - function update_unique_data_list() { - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - uniqueData.push(MSPCodes.MSP_LOOP_TIME); - uniqueData.push(MSPCodes.MSP_ARMING_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - uniqueData.push(MSPCodes.MSP_MOTOR_3D_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - uniqueData.push(MSPCodes.MSP_SENSOR_ALIGNMENT); - uniqueData.push(MSPCodes.MSP_RX_CONFIG); - uniqueData.push(MSPCodes.MSP_FAILSAFE_CONFIG); - uniqueData.push(MSPCodes.MSP_RXFAIL_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - uniqueData.push(MSPCodes.MSP_LED_STRIP_MODECOLOR); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - uniqueData.push(MSPCodes.MSP_MOTOR_CONFIG); - uniqueData.push(MSPCodes.MSP_RSSI_CONFIG); - uniqueData.push(MSPCodes.MSP_GPS_CONFIG); - uniqueData.push(MSPCodes.MSP_FEATURE_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - uniqueData.push(MSPCodes.MSP_MODE_RANGES_EXTRA); - } - } - - update_unique_data_list(); - - function fetch_unique_data() { - let codeKey = 0; - - function fetch_unique_data_item() { - if (codeKey < uniqueData.length) { - MSP.send_message(uniqueData[codeKey], false, false, function () { - codeKey++; - fetch_unique_data_item(); - }); - } else { - configuration.RCMAP = jQuery.extend(true, [], FC.RC_MAP); - configuration.SERIAL_CONFIG = jQuery.extend(true, {}, FC.SERIAL_CONFIG); - configuration.LED_STRIP = jQuery.extend(true, [], FC.LED_STRIP); - configuration.LED_COLORS = jQuery.extend(true, [], FC.LED_COLORS); - configuration.BOARD_ALIGNMENT_CONFIG = jQuery.extend(true, {}, FC.BOARD_ALIGNMENT_CONFIG); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - configuration.CRAFT_NAME = FC.CONFIG.craftName; - configuration.PILOT_NAME = FC.CONFIG.pilotName; - } else { - configuration.CRAFT_NAME = FC.CONFIG.name; - configuration.DISPLAY_NAME = FC.CONFIG.displayName; - } - configuration.MIXER_CONFIG = jQuery.extend(true, {}, FC.MIXER_CONFIG); - configuration.SENSOR_CONFIG = jQuery.extend(true, {}, FC.SENSOR_CONFIG); - configuration.PID_ADVANCED_CONFIG = jQuery.extend(true, {}, FC.PID_ADVANCED_CONFIG); - - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - configuration.LED_MODE_COLORS = jQuery.extend(true, [], FC.LED_MODE_COLORS); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - configuration.FC_CONFIG = jQuery.extend(true, {}, FC.FC_CONFIG); - configuration.ARMING_CONFIG = jQuery.extend(true, {}, FC.ARMING_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - configuration.MOTOR_3D_CONFIG = jQuery.extend(true, {}, FC.MOTOR_3D_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - configuration.SENSOR_ALIGNMENT = jQuery.extend(true, {}, FC.SENSOR_ALIGNMENT); - configuration.RX_CONFIG = jQuery.extend(true, {}, FC.RX_CONFIG); - configuration.FAILSAFE_CONFIG = jQuery.extend(true, {}, FC.FAILSAFE_CONFIG); - configuration.RXFAIL_CONFIG = jQuery.extend(true, [], FC.RXFAIL_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - configuration.RSSI_CONFIG = jQuery.extend(true, {}, FC.RSSI_CONFIG); - configuration.FEATURE_CONFIG = jQuery.extend(true, {}, FC.FEATURE_CONFIG); - configuration.MOTOR_CONFIG = jQuery.extend(true, {}, FC.MOTOR_CONFIG); - configuration.GPS_CONFIG = jQuery.extend(true, {}, FC.GPS_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - configuration.BEEPER_CONFIG = jQuery.extend(true, {}, FC.BEEPER_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - configuration.MODE_RANGES_EXTRA = jQuery.extend(true, [], FC.MODE_RANGES_EXTRA); - } - - save(); - } - } - - if (GUI.configuration_loaded === true) { - return fetch_unique_data_item(); - } - - MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG).then(function() { - return MSP.promise(MSPCodes.MSP_SENSOR_CONFIG); - }).then(function() { - return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) - ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME)) - : MSP.promise(MSPCodes.MSP_NAME); - }).then(function() { - return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) - ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); - }).then(function() { - return MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG); - }).then(function() { - return MSP.promise(MSPCodes.MSP_MIXER_CONFIG); - }).then(function() { - return MSP.promise(MSPCodes.MSP_BEEPER_CONFIG); - }).then(function() { - return fetch_unique_data_item(); - }); - } - - function save() { - let chosenFileEntry = null; - - const prefix = 'backup'; - const suffix = 'json'; - - const filename = generateFilename(prefix, suffix); - - const accepts = [{ - description: `${suffix.toUpperCase()} files`, extensions: [suffix], - }]; - - // create or load the file - chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, accepts: accepts}, function (fileEntry) { - if (checkChromeRuntimeError()) { - return; - } - - if (!fileEntry) { - console.log('No file selected, backup aborted.'); - return; - } - - chosenFileEntry = fileEntry; - - // echo/console log path specified - chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) { - console.log(`Backup file path: ${path}`); - }); - - // change file entry from read only to read/write - chrome.fileSystem.getWritableEntry(chosenFileEntry, function (fileEntryWritable) { - // check if file is writable - chrome.fileSystem.isWritableEntry(fileEntryWritable, function (isWritable) { - if (isWritable) { - chosenFileEntry = fileEntryWritable; - - // crunch the config object - const serializedConfigObject = JSON.stringify(configuration, null, '\t'); - const blob = new Blob([serializedConfigObject], {type: 'text/plain'}); // first parameter for Blob needs to be an array - - chosenFileEntry.createWriter(function (writer) { - writer.onerror = function (e) { - console.error(e); - }; - - let truncated = false; - writer.onwriteend = function () { - if (!truncated) { - // onwriteend will be fired again when truncation is finished - truncated = true; - writer.truncate(blob.size); - - return; - } - - analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Backup'); - console.log('Write SUCCESSFUL'); - if (callback) callback(); - }; - - writer.write(blob); - }, function (e) { - console.error(e); - }); - } else { - // Something went wrong or file is set to read only and cannot be changed - console.log('File appears to be read only, sorry.'); - } - }); - }); - }); - } - -} - -function configuration_restore(callback) { - let chosenFileEntry = null; - - const accepts = [{ - description: 'JSON files', extensions: ['json'], - }]; - - // load up the file - chrome.fileSystem.chooseEntry({type: 'openFile', accepts: accepts}, function (fileEntry) { - if (checkChromeRuntimeError()) { - return; - } - - if (!fileEntry) { - console.log('No file selected, restore aborted.'); - return; - } - - chosenFileEntry = fileEntry; - - // echo/console log path specified - chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) { - console.log(`Restore file path: ${path}`); - }); - - // read contents into variable - chosenFileEntry.file(function (file) { - const reader = new FileReader(); - - reader.onprogress = function (e) { - if (e.total > 1048576) { // 1 MB - // dont allow reading files bigger then 1 MB - console.log('File limit (1 MB) exceeded, aborting'); - reader.abort(); - } - }; - - reader.onloadend = function (e) { - if ((e.total != 0 && e.total == e.loaded) || GUI.isCordova()) { - // Cordova: Ignore verification : seem to have a bug with progressEvent returned - console.log('Read SUCCESSFUL'); - let configuration; - try { // check if string provided is a valid JSON - configuration = JSON.parse(e.target.result); - } catch (err) { - // data provided != valid json object - console.log(`Data provided != valid JSON string, restore aborted: ${err}`); - - return; - } - - // validate - if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.BACKUP_FILE_VERSION_MIN_SUPPORTED)) { - if (!compareVersions(configuration.generatedBy, "1.14.0") && !migrate(configuration)) { - GUI.log(i18n.getMessage('backupFileUnmigratable')); - return; - } - if (configuration.FEATURE_CONFIG.features._featureMask) { - const features = new Features(FC.CONFIG); - features.setMask(configuration.FEATURE_CONFIG.features._featureMask); - configuration.FEATURE_CONFIG.features = features; - } - - analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Restore'); - - configuration_upload(configuration, callback); - } else { - GUI.log(i18n.getMessage('backupFileIncompatible')); - } - } - }; - - reader.readAsText(file); - }); - }); - - function compareVersions(generated, required) { - if (generated == undefined) { - return false; - } - return semver.gte(generated, required); - } - - - function migrate(configuration) { - let appliedMigrationsCount = 0; - let migratedVersion = configuration.generatedBy; - GUI.log(i18n.getMessage('configMigrationFrom', [migratedVersion])); - - if (!compareVersions(migratedVersion, '0.59.1')) { - - // variable was renamed - configuration.RSSI_CONFIG.channel = configuration.MISC.rssi_aux_channel; - configuration.MISC.rssi_aux_channel = undefined; - - migratedVersion = '0.59.1'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (!compareVersions(migratedVersion, '0.60.1')) { - - // LED_STRIP support was added. - if (!configuration.LED_STRIP) { - configuration.LED_STRIP = []; - } - - migratedVersion = '0.60.1'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (!compareVersions(migratedVersion, '0.61.0')) { - - // Changing PID controller via UI was added. - if (!configuration.PIDs && configuration.PID) { - configuration.PIDs = configuration.PID; - configuration.PID = { - controller: 0, // assume pid controller 0 was used. - }; - } - - migratedVersion = '0.61.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (!compareVersions(migratedVersion, '0.63.0')) { - - // LED Strip was saved as object instead of array. - if (typeof(configuration.LED_STRIP) == 'object') { - const fixedLedStrip = []; - - let index = 0; - while (configuration.LED_STRIP[index]) { - fixedLedStrip.push(configuration.LED_STRIP[index++]); - } - configuration.LED_STRIP = fixedLedStrip; - } - - for (let profileIndex = 0; profileIndex < 3; profileIndex++) { - const RC = configuration.profiles[profileIndex].RC; - // TPA breakpoint was added - if (!RC.dynamic_THR_breakpoint) { - RC.dynamic_THR_breakpoint = 1500; // firmware default - } - - // Roll and pitch rates were split - RC.roll_rate = RC.roll_pitch_rate; - RC.pitch_rate = RC.roll_pitch_rate; - } - - migratedVersion = '0.63.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (configuration.apiVersion == undefined) { - configuration.apiVersion = "1.0.0"; // a guess that will satisfy the rest of the code - } - // apiVersion previously stored without patchlevel - if (!semver.parse(configuration.apiVersion)) { - configuration.apiVersion += ".0"; - if (!semver.parse(configuration.apiVersion)) { - return false; - } - } - if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.7.0')) { - // Serial configuation redesigned, 0.63.0 saves old and new configurations. - const ports = []; - for (const port of configuration.SERIAL_CONFIG.ports) { - const oldPort = port; - - const newPort = { - identifier: oldPort.identifier, - functions: [], - msp_baudrate: String(configuration.SERIAL_CONFIG.mspBaudRate), - gps_baudrate: String(configuration.SERIAL_CONFIG.gpsBaudRate), - telemetry_baudrate: 'AUTO', - blackbox_baudrate: '115200', - }; - - switch(oldPort.scenario) { - case 1: // MSP, CLI, TELEMETRY, SMARTPORT TELEMETRY, GPS-PASSTHROUGH - case 5: // MSP, CLI, GPS-PASSTHROUGH - case 8: // MSP ONLY - newPort.functions.push('MSP'); - break; - case 2: // GPS - newPort.functions.push('GPS'); - break; - case 3: // RX_SERIAL - newPort.functions.push('RX_SERIAL'); - break; - case 10: // BLACKBOX ONLY - newPort.functions.push('BLACKBOX'); - break; - case 11: // MSP, CLI, BLACKBOX, GPS-PASSTHROUGH - newPort.functions.push('MSP'); - newPort.functions.push('BLACKBOX'); - break; - } - - ports.push(newPort); - } - configuration.SERIAL_CONFIG = { - ports: ports, - }; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.8.0')) { - // api 1.8 exposes looptime and arming config - - if (configuration.FC_CONFIG == undefined) { - configuration.FC_CONFIG = { - loopTime: 3500, - }; - } - - if (configuration.ARMING_CONFIG == undefined) { - configuration.ARMING_CONFIG = { - auto_disarm_delay: 5, - disarm_kill_switch: 1, - }; - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '0.63.0')) { - // backups created with 0.63.0 for firmwares with api < 1.8 were saved with incorrect looptime - if (configuration.FC_CONFIG.loopTime == 0) { - //reset it to the default - configuration.FC_CONFIG.loopTime = 3500; - } - } - - if (semver.lt(migratedVersion, '0.66.0')) { - // api 1.12 updated servo configuration protocol and added servo mixer rules - for (let profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) { - if (semver.eq(configuration.apiVersion, '1.10.0')) { - // drop two unused servo configurations - while (configuration.profiles[profileIndex].ServoConfig.length > 8) { - configuration.profiles[profileIndex].ServoConfig.pop(); - } - } - - for (let i = 0; i < configuration.profiles[profileIndex].ServoConfig.length; i++) { - const servoConfig = profiles[profileIndex].ServoConfig; - - servoConfig[i].angleAtMin = 45; - servoConfig[i].angleAtMax = 45; - servoConfig[i].reversedInputSources = 0; - - // set the rate to 0 if an invalid value is detected. - if (servoConfig[i].rate < -100 || servoConfig[i].rate > 100) { - servoConfig[i].rate = 0; - } - } - - configuration.profiles[profileIndex].ServoRules = []; - } - - migratedVersion = '0.66.0'; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (semver.lt(configuration.apiVersion, '1.14.0') && semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - // api 1.14 removed old pid controllers - for (let profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) { - let newPidControllerIndex = configuration.profiles[profileIndex].PID.controller; - switch (newPidControllerIndex) { - case 3: - case 4: - case 5: - newPidControllerIndex = 0; - break; - } - configuration.profiles[profileIndex].PID.controller = newPidControllerIndex; - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - - if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.14.0')) { - // api 1.14 exposes 3D configuration - - if (configuration.MOTOR_3D_CONFIG == undefined) { - configuration.MOTOR_3D_CONFIG = { - deadband3d_low: 1406, - deadband3d_high: 1514, - neutral: 1460, - deadband3d_throttle: 50, - }; - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - - if (compareVersions(migratedVersion, '0.66.0') && !compareVersions(configuration.apiVersion, '1.15.0')) { - // api 1.15 exposes RCdeadband and sensor alignment - - for (let profileIndex = 0; profileIndex < configuration.profiles.length; profileIndex++) { - if (configuration.profiles[profileIndex].RCdeadband == undefined) { - configuration.profiles[profileIndex].RCdeadband = { - deadband: 0, - yaw_deadband: 0, - alt_hold_deadband: 40, - }; - } - } - if (configuration.SENSOR_ALIGNMENT == undefined) { - configuration.SENSOR_ALIGNMENT = { - align_gyro: 0, - align_acc: 0, - align_mag: 0, - }; - } - - // api 1.15 exposes RX_CONFIG, FAILSAFE_CONFIG and RXFAIL_CONFIG configuration - - if (configuration.RX_CONFIG == undefined) { - configuration.RX_CONFIG = { - serialrx_provider: 0, - spektrum_sat_bind: 0, - stick_center: 1500, - stick_min: 1100, - stick_max: 1900, - rx_min_usec: 885, - rx_max_usec: 2115, - }; - } - - if (configuration.FAILSAFE_CONFIG == undefined) { - configuration.FAILSAFE_CONFIG = { - failsafe_delay: 10, - failsafe_off_delay: 200, - failsafe_throttle: 1000, - failsafe_switch_mode: 0, - failsafe_throttle_low_delay: 100, - failsafe_procedure: 0, - }; - } - - if (configuration.RXFAIL_CONFIG == undefined) { - configuration.RXFAIL_CONFIG = [ - {mode: 0, value: 1500}, - {mode: 0, value: 1500}, - {mode: 0, value: 1500}, - {mode: 0, value: 875}, - ]; - - for (let i = 0; i < 14; i++) { - const rxfailChannel = { - mode: 1, - value: 1500, - }; - configuration.RXFAIL_CONFIG.push(rxfailChannel); - } - } - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '1.2.0')) { - // old version of the configurator incorrectly had a 'disabled' option for GPS SBAS mode. - if (FC.GPS_CONFIG.ublox_sbas < 0) { - FC.GPS_CONFIG.ublox_sbas = 0; - } - migratedVersion = '1.2.0'; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (compareVersions(migratedVersion, '1.3.1')) { - - // LED_COLORS & LED_MODE_COLORS support was added. - if (!configuration.LED_COLORS) { - configuration.LED_COLORS = []; - } - if (!configuration.LED_MODE_COLORS) { - configuration.LED_MODE_COLORS = []; - } - - migratedVersion = '1.3.1'; - - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); - appliedMigrationsCount++; - } - - if (appliedMigrationsCount > 0) { - GUI.log(i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount])); - } - return true; - } - - function configuration_upload(configuration, _callback) { - function upload() { - let activeProfile = null; - let numProfiles = FC.CONFIG.numProfiles; - if (configuration.profiles.length < numProfiles) { - numProfiles = configuration.profiles.length; - } - - const profileSpecificData = [ - MSPCodes.MSP_SET_PID_CONTROLLER, - MSPCodes.MSP_SET_PID, - MSPCodes.MSP_SET_RC_TUNING, - MSPCodes.MSP_SET_ACC_TRIM, - ]; - - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - profileSpecificData.push(MSPCodes.MSP_SET_RC_DEADBAND); - } - - MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () { - activeProfile = FC.CONFIG.profile; - select_profile(); - }); - - function select_profile() { - if (activeProfile > 0) { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [0], false, upload_specific_data); - } else { - upload_specific_data(); - } - } - - function upload_specific_data() { - let savingProfile = 0; - let codeKey = 0; - - function load_objects(profile) { - FC.PID = configuration.profiles[profile].PID; - FC.PIDS = configuration.profiles[profile].PIDs; - FC.RC_TUNING = configuration.profiles[profile].RC; - FC.CONFIG.accelerometerTrims = configuration.profiles[profile].AccTrim; - FC.SERVO_CONFIG = configuration.profiles[profile].ServoConfig; - FC.SERVO_RULES = configuration.profiles[profile].ServoRules; - FC.MODE_RANGES = configuration.profiles[profile].ModeRanges; - FC.ADJUSTMENT_RANGES = configuration.profiles[profile].AdjustmentRanges; - FC.RC_DEADBAND_CONFIG = configuration.profiles[profile].RCdeadband; - } - - function upload_using_specific_commands() { - MSP.send_message(profileSpecificData[codeKey], mspHelper.crunch(profileSpecificData[codeKey]), false, function () { - codeKey++; - - if (codeKey < profileSpecificData.length) { - upload_using_specific_commands(); - } else { - codeKey = 0; - savingProfile++; - - if (savingProfile < numProfiles) { - load_objects(savingProfile); - - MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [savingProfile], false, upload_using_specific_commands); - }); - } else { - MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { - MSP.send_message(MSPCodes.MSP_SELECT_SETTING, [activeProfile], false, upload_unique_data); - }); - } - } - }); - } - - function upload_servo_configuration() { - mspHelper.sendServoConfigurations(upload_mode_ranges); - } - - function upload_mode_ranges() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - if (configuration.MODE_RANGES_EXTRA == undefined) { - FC.MODE_RANGES_EXTRA = []; - - for (let modeIndex = 0; modeIndex < FC.MODE_RANGES.length; modeIndex++) { - const defaultModeRangeExtra = { - modeId: FC.MODE_RANGES[modeIndex].modeId, - modeLogic: 0, - linkedTo: 0, - }; - FC.MODE_RANGES_EXTRA.push(defaultModeRangeExtra); - } - } else { - FC.MODE_RANGES_EXTRA = configuration.MODE_RANGES_EXTRA; - } - } - - mspHelper.sendModeRanges(upload_adjustment_ranges); - } - - function upload_adjustment_ranges() { - mspHelper.sendAdjustmentRanges(upload_using_specific_commands); - } - // start uploading - load_objects(0); - upload_servo_configuration(); - } - - function upload_unique_data() { - let codeKey = 0; - - const uniqueData = [ - MSPCodes.MSP_SET_RX_MAP, - MSPCodes.MSP_SET_CF_SERIAL_CONFIG, - ]; - - function update_unique_data_list() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.CRAFT_NAME]); - uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME]); - } else { - uniqueData.push(MSPCodes.MSP_SET_NAME); - } - - uniqueData.push(MSPCodes.MSP_SET_SENSOR_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_MIXER_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_BEEPER_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_ADVANCED_CONFIG); - - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - uniqueData.push(MSPCodes.MSP_SET_LOOP_TIME); - uniqueData.push(MSPCodes.MSP_SET_ARMING_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.14.0")) { - uniqueData.push(MSPCodes.MSP_SET_MOTOR_3D_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - uniqueData.push(MSPCodes.MSP_SET_SENSOR_ALIGNMENT); - uniqueData.push(MSPCodes.MSP_SET_RX_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_FAILSAFE_CONFIG); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - uniqueData.push(MSPCodes.MSP_SET_FEATURE_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_MOTOR_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_GPS_CONFIG); - uniqueData.push(MSPCodes.MSP_SET_RSSI_CONFIG); - } - } - - function load_objects() { - FC.MISC = configuration.MISC; - FC.RC_MAP = configuration.RCMAP; - FC.SERIAL_CONFIG = configuration.SERIAL_CONFIG; - FC.LED_STRIP = configuration.LED_STRIP; - FC.LED_COLORS = configuration.LED_COLORS; - FC.LED_MODE_COLORS = configuration.LED_MODE_COLORS; - FC.ARMING_CONFIG = configuration.ARMING_CONFIG; - FC.FC_CONFIG = configuration.FC_CONFIG; - FC.MOTOR_3D_CONFIG = configuration.MOTOR_3D_CONFIG; - FC.SENSOR_ALIGNMENT = configuration.SENSOR_ALIGNMENT; - FC.RX_CONFIG = configuration.RX_CONFIG; - FC.FAILSAFE_CONFIG = configuration.FAILSAFE_CONFIG; - FC.RXFAIL_CONFIG = configuration.RXFAIL_CONFIG; - FC.FEATURE_CONFIG = configuration.FEATURE_CONFIG; - FC.MOTOR_CONFIG = configuration.MOTOR_CONFIG; - FC.GPS_CONFIG = configuration.GPS_CONFIG; - FC.RSSI_CONFIG = configuration.RSSI_CONFIG; - FC.BOARD_ALIGNMENT_CONFIG = configuration.BOARD_ALIGNMENT_CONFIG; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.CONFIG.craftName = configuration.CRAFT_NAME; - FC.CONFIG.pilotName = configuration.PILOT_NAME; - } else { - FC.CONFIG.name = configuration.CRAFT_NAME; - FC.CONFIG.displayName = configuration.DISPLAY_NAME; - } - FC.MIXER_CONFIG = configuration.MIXER_CONFIG; - FC.SENSOR_CONFIG = configuration.SENSOR_CONFIG; - FC.PID_ADVANCED_CONFIG = configuration.PID_ADVANCED_CONFIG; - - FC.BEEPER_CONFIG.beepers = new Beepers(FC.CONFIG); - FC.BEEPER_CONFIG.beepers.setDisabledMask(configuration.BEEPER_CONFIG.beepers._beeperDisabledMask); - FC.BEEPER_CONFIG.dshotBeaconTone = configuration.BEEPER_CONFIG.dshotBeaconTone; - FC.BEEPER_CONFIG.dshotBeaconConditions = new Beepers(FC.CONFIG, [ "RX_LOST", "RX_SET" ]); - FC.BEEPER_CONFIG.dshotBeaconConditions.setDisabledMask(configuration.BEEPER_CONFIG.dshotBeaconConditions._beeperDisabledMask); - } - - function send_unique_data_item() { - if (codeKey < uniqueData.length) { - const callback = () => { - codeKey++; - send_unique_data_item(); - }; - - if (Array.isArray(uniqueData[codeKey])) { - MSP.send_message(uniqueData[codeKey][0], mspHelper.crunch(...uniqueData[codeKey]), false, callback); - } else { - MSP.send_message(uniqueData[codeKey], mspHelper.crunch(uniqueData[codeKey]), false, callback); - } - } else { - send_led_strip_config(); - } - } - - load_objects(); - - update_unique_data_list(); - - // start uploading - send_unique_data_item(); - } - - function send_led_strip_config() { - mspHelper.sendLedStripConfig(send_led_strip_colors); - } - - function send_led_strip_colors() { - mspHelper.sendLedStripColors(send_led_strip_mode_colors); - } - - function send_led_strip_mode_colors() { - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - mspHelper.sendLedStripModeColors(send_rxfail_config); - } else { - send_rxfail_config(); - } - } - - function send_rxfail_config() { - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - mspHelper.sendRxFailConfig(save_to_eeprom); - } else { - save_to_eeprom(); - } - } - - function save_to_eeprom() { - MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, reboot); - } - - function reboot() { - GUI.log(i18n.getMessage('eeprom_saved_ok')); - - GUI.tab_switch_cleanup(function() { - MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(_callback)); - }); - } - } - - if (CONFIGURATOR.virtualMode) { - FC.resetState(); - FC.CONFIG.apiVersion = CONFIGURATOR.virtualApiVersion; - - sensor_status(FC.CONFIG.activeSensors); - update_dataflash_global(); - } - - upload(); - } -} diff --git a/src/js/data_storage.js b/src/js/data_storage.js index 759eb550..301cf864 100644 --- a/src/js/data_storage.js +++ b/src/js/data_storage.js @@ -18,10 +18,7 @@ const API_VERSION_1_45 = '1.45.0'; const CONFIGURATOR = { // all versions are specified and compared using semantic versioning http://semver.org/ - API_VERSION_ACCEPTED: '1.2.1', - API_VERSION_MIN_SUPPORTED_BACKUP_RESTORE: '1.5.0', - API_VERSION_MIN_SUPPORTED_PID_CONTROLLER_CHANGE: '1.5.0', - BACKUP_FILE_VERSION_MIN_SUPPORTED: '0.55.0', // chrome.runtime.getManifest().version is stored as string, so does this one + API_VERSION_ACCEPTED: API_VERSION_1_41, API_VERSION_MAX_SUPPORTED: API_VERSION_1_45, connectionValid: false, diff --git a/src/js/fc.js b/src/js/fc.js index 574c0237..492dba6a 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -643,7 +643,7 @@ const FC = { dterm_lowpass_dyn_max_hz: 250, dyn_lpf_curve_expo: 5, dterm_lowpass_type: this.FILTER_TYPE_FLAGS.PT1, - dterm_lowpass2_hz: 150, + dterm_lowpass2_hz: 200, dterm_lowpass2_type: this.FILTER_TYPE_FLAGS.BIQUAD, dterm_notch_cutoff: 160, dterm_notch_hz: 260, @@ -712,8 +712,6 @@ const FC = { getSerialRxTypes: () => { const apiVersion = FC.CONFIG.apiVersion; - const flightControllerIdentifier = FC.CONFIG.flightControllerIdentifier; - const flightControllerVersion = FC.CONFIG.flightControllerVersion; // defaults const serialRxTypes = [ @@ -724,33 +722,14 @@ const FC = { 'SUMH', 'XBUS_MODE_B', 'XBUS_MODE_B_RJ01', + 'IBUS', + 'CRSF', + 'JETIEXBUS', + 'SPEKTRUM2048/SRXL', + 'TARGET_CUSTOM', + 'FrSky FPort', ]; - if (semver.gte(apiVersion, "1.15.0")) { - serialRxTypes.push('IBUS'); - } - - if ((flightControllerIdentifier === 'BTFL' && semver.gte(flightControllerVersion, "2.6.0")) || - (flightControllerIdentifier === 'CLFL' && semver.gte(apiVersion, API_VERSION_1_31))) { - serialRxTypes.push('JETIEXBUS'); - } - - if (semver.gte(apiVersion, API_VERSION_1_31)) { - serialRxTypes.push('CRSF'); - } - - if (semver.gte(apiVersion, "1.24.0")) { - serialRxTypes.push('SPEKTRUM2048/SRXL'); - } - - if (semver.gte(apiVersion, API_VERSION_1_35)) { - serialRxTypes.push('TARGET_CUSTOM'); - } - - if (semver.gte(apiVersion, API_VERSION_1_37)) { - serialRxTypes.push('FrSky FPort'); - } - if (semver.gte(apiVersion, API_VERSION_1_42)) { serialRxTypes.push('SPEKTRUM SRXL2'); } @@ -822,14 +801,7 @@ const FC = { }, boardHasVcp() { - let hasVcp = false; - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_37)) { - hasVcp = bit_check(this.CONFIG.targetCapabilities, this.TARGET_CAPABILITIES_FLAGS.HAS_VCP); - } else { - hasVcp = BOARD.find_board_definition(this.CONFIG.boardIdentifier).vcp; - } - - return hasVcp; + return bit_check(this.CONFIG.targetCapabilities, this.TARGET_CAPABILITIES_FLAGS.HAS_VCP); }, boardHasFlashBootloader() { @@ -849,44 +821,44 @@ const FC = { getFilterDefaults() { const versionFilterDefaults = this.DEFAULT; // Change filter defaults depending on API version here - if (semver.eq(this.CONFIG.apiVersion, API_VERSION_1_40)) { - versionFilterDefaults.dterm_lowpass2_hz = 200; - } else if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_41)) { - versionFilterDefaults.gyro_lowpass_hz = 150; - versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.BIQUAD; - versionFilterDefaults.gyro_lowpass2_hz = 0; - versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.gyro_lowpass_hz = 150; + versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.gyro_lowpass2_hz = 0; + versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.dterm_lowpass_hz = 150; + versionFilterDefaults.dterm_lowpass_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.dterm_lowpass2_hz = 150; + versionFilterDefaults.dterm_lowpass2_type = this.FILTER_TYPE_FLAGS.BIQUAD; + + if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_42)) { + versionFilterDefaults.gyro_lowpass_hz = 200; + versionFilterDefaults.gyro_lowpass_dyn_min_hz = 200; + versionFilterDefaults.gyro_lowpass_dyn_max_hz = 500; + versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; + versionFilterDefaults.gyro_lowpass2_hz = 250; + versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; versionFilterDefaults.dterm_lowpass_hz = 150; - versionFilterDefaults.dterm_lowpass_type = this.FILTER_TYPE_FLAGS.BIQUAD; + versionFilterDefaults.dterm_lowpass_dyn_min_hz = 70; + versionFilterDefaults.dterm_lowpass_dyn_max_hz = 170; + versionFilterDefaults.dterm_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; versionFilterDefaults.dterm_lowpass2_hz = 150; - versionFilterDefaults.dterm_lowpass2_type = this.FILTER_TYPE_FLAGS.BIQUAD; - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_42)) { - versionFilterDefaults.gyro_lowpass_hz = 200; - versionFilterDefaults.gyro_lowpass_dyn_min_hz = 200; - versionFilterDefaults.gyro_lowpass_dyn_max_hz = 500; - versionFilterDefaults.gyro_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; - versionFilterDefaults.gyro_lowpass2_hz = 250; - versionFilterDefaults.gyro_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; - versionFilterDefaults.dterm_lowpass_hz = 150; - versionFilterDefaults.dterm_lowpass_dyn_min_hz = 70; - versionFilterDefaults.dterm_lowpass_dyn_max_hz = 170; - versionFilterDefaults.dterm_lowpass_type = this.FILTER_TYPE_FLAGS.PT1; - versionFilterDefaults.dterm_lowpass2_hz = 150; - versionFilterDefaults.dterm_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; - } - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_44)) { - versionFilterDefaults.dyn_notch_q = 300; - versionFilterDefaults.gyro_lowpass_hz = 250; - versionFilterDefaults.gyro_lowpass_dyn_min_hz = 250; - versionFilterDefaults.gyro_lowpass2_hz = 500; - versionFilterDefaults.dterm_lowpass_hz = 75; - versionFilterDefaults.dterm_lowpass_dyn_min_hz = 75; - versionFilterDefaults.dterm_lowpass_dyn_max_hz = 150; - } - if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_45)) { - versionFilterDefaults.dyn_notch_min_hz = 100; - } + versionFilterDefaults.dterm_lowpass2_type = this.FILTER_TYPE_FLAGS.PT1; } + + if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_44)) { + versionFilterDefaults.dyn_notch_q = 300; + versionFilterDefaults.gyro_lowpass_hz = 250; + versionFilterDefaults.gyro_lowpass_dyn_min_hz = 250; + versionFilterDefaults.gyro_lowpass2_hz = 500; + versionFilterDefaults.dterm_lowpass_hz = 75; + versionFilterDefaults.dterm_lowpass_dyn_min_hz = 75; + versionFilterDefaults.dterm_lowpass_dyn_max_hz = 150; + } + + if (semver.gte(this.CONFIG.apiVersion, API_VERSION_1_45)) { + versionFilterDefaults.dyn_notch_min_hz = 100; + } + return versionFilterDefaults; }, diff --git a/src/js/main.js b/src/js/main.js index 2f755bef..bf072d40 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -730,11 +730,7 @@ function updateTabList(features) { $('#tabs ul.mode-connected li.tab_osd').hide(); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - $('#tabs ul.mode-connected li.tab_power').show(); - } else { - $('#tabs ul.mode-connected li.tab_power').hide(); - } + $('#tabs ul.mode-connected li.tab_power').show(); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { $('#tabs ul.mode-connected li.tab_vtx').show(); diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index fe4ac2cd..bb39a6c2 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -181,23 +181,19 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.CONFIG.mode = data.readU32(); FC.CONFIG.profile = data.readU8(); FC.CONFIG.cpuload = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - FC.CONFIG.numProfiles = data.readU8(); - FC.CONFIG.rateProfile = data.readU8(); + FC.CONFIG.numProfiles = data.readU8(); + FC.CONFIG.rateProfile = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - // Read flight mode flags - const byteCount = data.readU8(); - for (let i = 0; i < byteCount; i++) { - data.readU8(); - } - - // Read arming disable flags - FC.CONFIG.armingDisableCount = data.readU8(); // Flag count - FC.CONFIG.armingDisableFlags = data.readU32(); - } + // Read flight mode flags + const byteCount = data.readU8(); + for (let i = 0; i < byteCount; i++) { + data.readU8(); } + // Read arming disable flags + FC.CONFIG.armingDisableCount = data.readU8(); // Flag count + FC.CONFIG.armingDisableFlags = data.readU32(); + sensor_status(FC.CONFIG.activeSensors); break; @@ -295,9 +291,7 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.ANALOG.mAhdrawn = data.readU16(); FC.ANALOG.rssi = data.readU16(); // 0-1023 FC.ANALOG.amperage = data.read16() / 100; // A - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.ANALOG.voltage = data.readU16() / 100; - } + FC.ANALOG.voltage = data.readU16() / 100; FC.ANALOG.last_received_timestamp = Date.now(); break; case MSPCodes.MSP_VOLTAGE_METERS: @@ -333,70 +327,51 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.BATTERY_STATE.voltage = data.readU8() / 10.0; // V FC.BATTERY_STATE.mAhDrawn = data.readU16(); // mAh FC.BATTERY_STATE.amperage = data.readU16() / 100; // A - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.BATTERY_STATE.batteryState = data.readU8(); - FC.BATTERY_STATE.voltage = data.readU16() / 100; - } + FC.BATTERY_STATE.batteryState = data.readU8(); + FC.BATTERY_STATE.voltage = data.readU16() / 100; break; case MSPCodes.MSP_VOLTAGE_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.MISC.vbatscale = data.readU8(); // 10-200 - FC.MISC.vbatmincellvoltage = data.readU8() / 10; // 10-50 - FC.MISC.vbatmaxcellvoltage = data.readU8() / 10; // 10-50 - FC.MISC.vbatwarningcellvoltage = data.readU8() / 10; // 10-50 - if (semver.gte(FC.CONFIG.apiVersion, "1.23.0")) { - FC.MISC.batterymetertype = data.readU8(); - } - } else { - FC.VOLTAGE_METER_CONFIGS = []; - const voltageMeterCount = data.readU8(); + FC.VOLTAGE_METER_CONFIGS = []; + const voltageMeterCount = data.readU8(); - for (let i = 0; i < voltageMeterCount; i++) { - const subframeLength = data.readU8(); - if (subframeLength !== 5) { - for (let j = 0; j < subframeLength; j++) { - data.readU8(); - } - } else { - const voltageMeterConfig = { - id: data.readU8(), - sensorType: data.readU8(), - vbatscale: data.readU8(), - vbatresdivval: data.readU8(), - vbatresdivmultiplier: data.readU8(), - }; - - FC.VOLTAGE_METER_CONFIGS.push(voltageMeterConfig); + for (let i = 0; i < voltageMeterCount; i++) { + const subframeLength = data.readU8(); + if (subframeLength !== 5) { + for (let j = 0; j < subframeLength; j++) { + data.readU8(); } + } else { + const voltageMeterConfig = { + id: data.readU8(), + sensorType: data.readU8(), + vbatscale: data.readU8(), + vbatresdivval: data.readU8(), + vbatresdivmultiplier: data.readU8(), + }; + + FC.VOLTAGE_METER_CONFIGS.push(voltageMeterConfig); } } break; case MSPCodes.MSP_CURRENT_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.BF_CONFIG.currentscale = data.read16(); - FC.BF_CONFIG.currentoffset = data.read16(); - FC.BF_CONFIG.currentmetertype = data.readU8(); - FC.BF_CONFIG.batterycapacity = data.readU16(); - } else { - FC.CURRENT_METER_CONFIGS = []; - const currentMeterCount = data.readU8(); - for (let i = 0; i < currentMeterCount; i++) { - const currentMeterConfig = {}; - const subframeLength = data.readU8(); + FC.CURRENT_METER_CONFIGS = []; + const currentMeterCount = data.readU8(); + for (let i = 0; i < currentMeterCount; i++) { + const currentMeterConfig = {}; + const subframeLength = data.readU8(); - if (subframeLength !== 6) { - for (let j = 0; j < subframeLength; j++) { - data.readU8(); - } - } else { - currentMeterConfig.id = data.readU8(); - currentMeterConfig.sensorType = data.readU8(); - currentMeterConfig.scale = data.read16(); - currentMeterConfig.offset = data.read16(); - - FC.CURRENT_METER_CONFIGS.push(currentMeterConfig); + if (subframeLength !== 6) { + for (let j = 0; j < subframeLength; j++) { + data.readU8(); } + } else { + currentMeterConfig.id = data.readU8(); + currentMeterConfig.sensorType = data.readU8(); + currentMeterConfig.scale = data.read16(); + currentMeterConfig.offset = data.read16(); + + FC.CURRENT_METER_CONFIGS.push(currentMeterConfig); } } break; @@ -408,11 +383,9 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.BATTERY_CONFIG.capacity = data.readU16(); FC.BATTERY_CONFIG.voltageMeterSource = data.readU8(); FC.BATTERY_CONFIG.currentMeterSource = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.BATTERY_CONFIG.vbatmincellvoltage = data.readU16() / 100; - FC.BATTERY_CONFIG.vbatmaxcellvoltage = data.readU16() / 100; - FC.BATTERY_CONFIG.vbatwarningcellvoltage = data.readU16() / 100; - } + FC.BATTERY_CONFIG.vbatmincellvoltage = data.readU16() / 100; + FC.BATTERY_CONFIG.vbatmaxcellvoltage = data.readU16() / 100; + FC.BATTERY_CONFIG.vbatwarningcellvoltage = data.readU16() / 100; break; case MSPCodes.MSP_SET_BATTERY_CONFIG: console.log('Battery configuration saved'); @@ -420,15 +393,9 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_RC_TUNING: FC.RC_TUNING.RC_RATE = parseFloat((data.readU8() / 100).toFixed(2)); FC.RC_TUNING.RC_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - FC.RC_TUNING.roll_pitch_rate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.RC_TUNING.pitch_rate = 0; - FC.RC_TUNING.roll_rate = 0; - } else { - FC.RC_TUNING.roll_pitch_rate = 0; - FC.RC_TUNING.roll_rate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.RC_TUNING.pitch_rate = parseFloat((data.readU8() / 100).toFixed(2)); - } + FC.RC_TUNING.roll_pitch_rate = 0; + FC.RC_TUNING.roll_rate = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.pitch_rate = parseFloat((data.readU8() / 100).toFixed(2)); FC.RC_TUNING.yaw_rate = parseFloat((data.readU8() / 100).toFixed(2)); if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { FC.RC_TUNING.dynamic_THR_PID = parseFloat((data.readU8() / 100).toFixed(2)); @@ -437,36 +404,17 @@ MspHelper.prototype.process_data = function(dataHandler) { } FC.RC_TUNING.throttle_MID = parseFloat((data.readU8() / 100).toFixed(2)); FC.RC_TUNING.throttle_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - if (semver.gte(FC.CONFIG.apiVersion, "1.7.0")) { - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.RC_TUNING.dynamic_THR_breakpoint = data.readU16(); - } else { - data.readU16(); - } + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.RC_TUNING.dynamic_THR_breakpoint = data.readU16(); } else { - FC.RC_TUNING.dynamic_THR_breakpoint = 0; - } - if (semver.gte(FC.CONFIG.apiVersion, "1.10.0")) { - FC.RC_TUNING.RC_YAW_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - FC.RC_TUNING.rcYawRate = parseFloat((data.readU8() / 100).toFixed(2)); - } else { - FC.RC_TUNING.rcYawRate = 0; - } - } else { - FC.RC_TUNING.RC_YAW_EXPO = 0; - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.RC_TUNING.rcPitchRate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.RC_TUNING.RC_PITCH_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); - } else { - FC.RC_TUNING.rcPitchRate = 0; - FC.RC_TUNING.RC_PITCH_EXPO = 0; - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.RC_TUNING.throttleLimitType = data.readU8(); - FC.RC_TUNING.throttleLimitPercent = data.readU8(); + data.readU16(); } + FC.RC_TUNING.RC_YAW_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.rcYawRate = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.rcPitchRate = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.RC_PITCH_EXPO = parseFloat((data.readU8() / 100).toFixed(2)); + FC.RC_TUNING.throttleLimitType = data.readU8(); + FC.RC_TUNING.throttleLimitPercent = data.readU8(); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { FC.RC_TUNING.roll_rate_limit = data.readU16(); FC.RC_TUNING.pitch_rate_limit = data.readU16(); @@ -488,18 +436,12 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_ARMING_CONFIG: - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - FC.ARMING_CONFIG.auto_disarm_delay = data.readU8(); - FC.ARMING_CONFIG.disarm_kill_switch = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.ARMING_CONFIG.small_angle = data.readU8(); - } + FC.ARMING_CONFIG.auto_disarm_delay = data.readU8(); + FC.ARMING_CONFIG.disarm_kill_switch = data.readU8(); + FC.ARMING_CONFIG.small_angle = data.readU8(); break; case MSPCodes.MSP_LOOP_TIME: - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - FC.FC_CONFIG.loopTime = data.readU16(); - } + FC.FC_CONFIG.loopTime = data.readU16(); break; case MSPCodes.MSP_MISC: // 22 bytes FC.RX_CONFIG.midrc = data.readU16(); @@ -533,14 +475,12 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_GPS_CONFIG: FC.GPS_CONFIG.provider = data.readU8(); FC.GPS_CONFIG.ublox_sbas = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - FC.GPS_CONFIG.auto_config = data.readU8(); - FC.GPS_CONFIG.auto_baud = data.readU8(); + FC.GPS_CONFIG.auto_config = data.readU8(); + FC.GPS_CONFIG.auto_baud = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.GPS_CONFIG.home_point_once = data.readU8(); - FC.GPS_CONFIG.ublox_use_galileo = data.readU8(); - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + FC.GPS_CONFIG.home_point_once = data.readU8(); + FC.GPS_CONFIG.ublox_use_galileo = data.readU8(); } break; case MSPCodes.MSP_GPS_RESCUE: @@ -570,9 +510,6 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.MOTOR_3D_CONFIG.deadband3d_low = data.readU16(); FC.MOTOR_3D_CONFIG.deadband3d_high = data.readU16(); FC.MOTOR_3D_CONFIG.neutral = data.readU16(); - if (semver.lt(FC.CONFIG.apiVersion, "1.17.0")) { - FC.RC_DEADBAND_CONFIG.deadband3d_throttle = data.readU16(); - } break; case MSPCodes.MSP_BOXNAMES: FC.AUX_CONFIG = []; // empty the array as new data is coming in @@ -618,61 +555,18 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_SERVO_CONFIGURATIONS: FC.SERVO_CONFIG = []; // empty the array as new data is coming in - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - if (data.byteLength % 12 == 0) { - for (let i = 0; i < data.byteLength; i += 12) { - const arr = { - 'min': data.readU16(), - 'max': data.readU16(), - 'middle': data.readU16(), - 'rate': data.read8(), - 'indexOfChannelToForward': data.readU8(), - 'reversedInputSources': data.readU32(), - }; + if (data.byteLength % 12 == 0) { + for (let i = 0; i < data.byteLength; i += 12) { + const arr = { + 'min': data.readU16(), + 'max': data.readU16(), + 'middle': data.readU16(), + 'rate': data.read8(), + 'indexOfChannelToForward': data.readU8(), + 'reversedInputSources': data.readU32(), + }; - FC.SERVO_CONFIG.push(arr); - } - } - } else if (semver.gte(FC.CONFIG.apiVersion, "1.12.0")) { - if (data.byteLength % 14 == 0) { - for (let i = 0; i < data.byteLength; i += 14) { - const arr = { - 'min': data.readU16(), - 'max': data.readU16(), - 'middle': data.readU16(), - 'rate': data.read8(), - 'angleAtMin': data.readU8(), - 'angleAtMax': data.readU8(), - 'indexOfChannelToForward': data.readU8(), - 'reversedInputSources': data.readU32(), - }; - - FC.SERVO_CONFIG.push(arr); - } - } - } else { - if (data.byteLength % 7 == 0) { - for (let i = 0; i < data.byteLength; i += 7) { - const arr = { - 'min': data.readU16(), - 'max': data.readU16(), - 'middle': data.readU16(), - 'rate': data.read8(), - 'angleAtMin': 45, - 'angleAtMax': 45, - 'indexOfChannelToForward': undefined, - 'reversedInputSources': 0, - }; - - FC.SERVO_CONFIG.push(arr); - } - } - - if (semver.eq(FC.CONFIG.apiVersion, '1.10.0')) { - // drop two unused servo configurations due to MSP rx buffer to small) - while (FC.SERVO_CONFIG.length > 8) { - FC.SERVO_CONFIG.pop(); - } + FC.SERVO_CONFIG.push(arr); } } break; @@ -681,21 +575,16 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.RC_DEADBAND_CONFIG.yaw_deadband = data.readU8(); FC.RC_DEADBAND_CONFIG.alt_hold_deadband = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, "1.17.0")) { - FC.RC_DEADBAND_CONFIG.deadband3d_throttle = data.readU16(); - } + FC.RC_DEADBAND_CONFIG.deadband3d_throttle = data.readU16(); break; case MSPCodes.MSP_SENSOR_ALIGNMENT: FC.SENSOR_ALIGNMENT.align_gyro = data.readU8(); FC.SENSOR_ALIGNMENT.align_acc = data.readU8(); FC.SENSOR_ALIGNMENT.align_mag = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, '1.41.0')) { - FC.SENSOR_ALIGNMENT.gyro_detection_flags = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_1_align = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_2_align = data.readU8(); - } + FC.SENSOR_ALIGNMENT.gyro_detection_flags = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_1_align = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_2_align = data.readU8(); break; case MSPCodes.MSP_DISPLAYPORT: break; @@ -795,9 +684,7 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_MIXER_CONFIG: FC.MIXER_CONFIG.mixer = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.MIXER_CONFIG.reverseMotorDir = data.readU8(); - } + FC.MIXER_CONFIG.reverseMotorDir = data.readU8(); break; case MSPCodes.MSP_FEATURE_CONFIG: @@ -808,12 +695,8 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_BEEPER_CONFIG: FC.BEEPER_CONFIG.beepers.setDisabledMask(data.readU32()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.BEEPER_CONFIG.dshotBeaconTone = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.BEEPER_CONFIG.dshotBeaconConditions.setDisabledMask(data.readU32()); - } + FC.BEEPER_CONFIG.dshotBeaconTone = data.readU8(); + FC.BEEPER_CONFIG.dshotBeaconConditions.setDisabledMask(data.readU32()); break; case MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG: @@ -823,15 +706,13 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_SET_REBOOT: - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - const rebootType = data.read8(); - if ((rebootType === self.REBOOT_TYPES.MSC) || (rebootType === self.REBOOT_TYPES.MSC_UTC)) { - if (data.read8() === 0) { - console.log('Storage device not ready.'); + const rebootType = data.read8(); + if ((rebootType === self.REBOOT_TYPES.MSC) || (rebootType === self.REBOOT_TYPES.MSC_UTC)) { + if (data.read8() === 0) { + console.log('Storage device not ready.'); - showErrorDialog(i18n.getMessage('storageDeviceNotReady')); - break; - } + showErrorDialog(i18n.getMessage('storageDeviceNotReady')); + break; } } console.log('Reboot request accepted'); @@ -880,49 +761,39 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.CONFIG.boardVersion = data.readU16(); FC.CONFIG.boardType = 0; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_35)) { - FC.CONFIG.boardType = data.readU8(); - } + FC.CONFIG.boardType = data.readU8(); FC.CONFIG.targetCapabilities = 0; FC.CONFIG.targetName = ''; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.CONFIG.targetCapabilities = data.readU8(); - const length = data.readU8(); - for (let i = 0; i < length; i++) { - FC.CONFIG.targetName += String.fromCharCode(data.readU8()); - } + FC.CONFIG.targetCapabilities = data.readU8(); + let length = data.readU8(); + for (let i = 0; i < length; i++) { + FC.CONFIG.targetName += String.fromCharCode(data.readU8()); } FC.CONFIG.boardName = ''; FC.CONFIG.manufacturerId = ''; FC.CONFIG.signature = []; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - let length = data.readU8(); + length = data.readU8(); - for (let i = 0; i < length; i++) { - FC.CONFIG.boardName += String.fromCharCode(data.readU8()); - } - - length = data.readU8(); - - for (let i = 0; i < length; i++) { - FC.CONFIG.manufacturerId += String.fromCharCode(data.readU8()); - } - - for (let i = 0; i < self.SIGNATURE_LENGTH; i++) { - FC.CONFIG.signature.push(data.readU8()); - } + for (let i = 0; i < length; i++) { + FC.CONFIG.boardName += String.fromCharCode(data.readU8()); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.CONFIG.mcuTypeId = data.readU8(); - } else { - FC.CONFIG.mcuTypeId = 255; + length = data.readU8(); + + for (let i = 0; i < length; i++) { + FC.CONFIG.manufacturerId += String.fromCharCode(data.readU8()); } + for (let i = 0; i < self.SIGNATURE_LENGTH; i++) { + FC.CONFIG.signature.push(data.readU8()); + } + + FC.CONFIG.mcuTypeId = data.readU8(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { FC.CONFIG.configurationState = data.readU8(); } @@ -973,35 +844,20 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_CF_SERIAL_CONFIG: FC.SERIAL_CONFIG.ports = []; - if (semver.lt(FC.CONFIG.apiVersion, "1.6.0")) { - const serialPortCount = (data.byteLength - (4 * 4)) / 2; - for (let i = 0; i < serialPortCount; i++) { - const serialPort = { - identifier: data.readU8(), - scenario: data.readU8(), - }; - FC.SERIAL_CONFIG.ports.push(serialPort); - } - FC.SERIAL_CONFIG.mspBaudRate = data.readU32(); - FC.SERIAL_CONFIG.cliBaudRate = data.readU32(); - FC.SERIAL_CONFIG.gpsBaudRate = data.readU32(); - FC.SERIAL_CONFIG.gpsPassthroughBaudRate = data.readU32(); - } else { - const bytesPerPort = 1 + 2 + (1 * 4); + const bytesPerPort = 1 + 2 + (1 * 4); - const serialPortCount = data.byteLength / bytesPerPort; - for (let i = 0; i < serialPortCount; i++) { - const serialPort = { - identifier: data.readU8(), - functions: self.serialPortFunctionMaskToFunctions(data.readU16()), - msp_baudrate: self.BAUD_RATES[data.readU8()], - gps_baudrate: self.BAUD_RATES[data.readU8()], - telemetry_baudrate: self.BAUD_RATES[data.readU8()], - blackbox_baudrate: self.BAUD_RATES[data.readU8()], - }; + const serialPortCount = data.byteLength / bytesPerPort; + for (let i = 0; i < serialPortCount; i++) { + const serialPort = { + identifier: data.readU8(), + functions: self.serialPortFunctionMaskToFunctions(data.readU16()), + msp_baudrate: self.BAUD_RATES[data.readU8()], + gps_baudrate: self.BAUD_RATES[data.readU8()], + telemetry_baudrate: self.BAUD_RATES[data.readU8()], + blackbox_baudrate: self.BAUD_RATES[data.readU8()], + }; - FC.SERIAL_CONFIG.ports.push(serialPort); - } + FC.SERIAL_CONFIG.ports.push(serialPort); } break; @@ -1095,49 +951,33 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.RX_CONFIG.spektrum_sat_bind = data.readU8(); FC.RX_CONFIG.rx_min_usec = data.readU16(); FC.RX_CONFIG.rx_max_usec = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - FC.RX_CONFIG.rcInterpolation = data.readU8(); - FC.RX_CONFIG.rcInterpolationInterval = data.readU8(); - FC.RX_CONFIG.airModeActivateThreshold = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - FC.RX_CONFIG.rxSpiProtocol = data.readU8(); - FC.RX_CONFIG.rxSpiId = data.readU32(); - FC.RX_CONFIG.rxSpiRfChannelCount = data.readU8(); - FC.RX_CONFIG.fpvCamAngleDegrees = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - FC.RX_CONFIG.rcInterpolationChannels = data.readU8(); - FC.RX_CONFIG.rcSmoothingType = data.readU8(); - FC.RX_CONFIG.rcSmoothingSetpointCutoff = data.readU8(); - FC.RX_CONFIG.rcSmoothingFeedforwardCutoff = data.readU8(); - FC.RX_CONFIG.rcSmoothingInputType = data.readU8(); - FC.RX_CONFIG.rcSmoothingDerivativeType = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.RX_CONFIG.usbCdcHidType = data.readU8(); - FC.RX_CONFIG.rcSmoothingAutoFactor = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.RX_CONFIG.rcSmoothingMode = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - const elrsUidLength = 6; - FC.RX_CONFIG.elrsUid = []; - for (let i = 0; i < elrsUidLength; i++) { - FC.RX_CONFIG.elrsUid.push(data.readU8()); - } - } - } - } - } - } else { - FC.RX_CONFIG.rxSpiProtocol = 0; - FC.RX_CONFIG.rxSpiId = 0; - FC.RX_CONFIG.rxSpiRfChannelCount = 0; - FC.RX_CONFIG.fpvCamAngleDegrees = 0; - } - } else { - FC.RX_CONFIG.rcInterpolation = 0; - FC.RX_CONFIG.rcInterpolationInterval = 0; - FC.RX_CONFIG.airModeActivateThreshold = 0; + FC.RX_CONFIG.rcInterpolation = data.readU8(); + FC.RX_CONFIG.rcInterpolationInterval = data.readU8(); + FC.RX_CONFIG.airModeActivateThreshold = data.readU16(); + FC.RX_CONFIG.rxSpiProtocol = data.readU8(); + FC.RX_CONFIG.rxSpiId = data.readU32(); + FC.RX_CONFIG.rxSpiRfChannelCount = data.readU8(); + FC.RX_CONFIG.fpvCamAngleDegrees = data.readU8(); + FC.RX_CONFIG.rcInterpolationChannels = data.readU8(); + FC.RX_CONFIG.rcSmoothingType = data.readU8(); + FC.RX_CONFIG.rcSmoothingSetpointCutoff = data.readU8(); + FC.RX_CONFIG.rcSmoothingFeedforwardCutoff = data.readU8(); + FC.RX_CONFIG.rcSmoothingInputType = data.readU8(); + FC.RX_CONFIG.rcSmoothingDerivativeType = data.readU8(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + FC.RX_CONFIG.usbCdcHidType = data.readU8(); + FC.RX_CONFIG.rcSmoothingAutoFactor = data.readU8(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + FC.RX_CONFIG.rcSmoothingMode = data.readU8(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + const elrsUidLength = 6; + FC.RX_CONFIG.elrsUid = []; + for (let i = 0; i < elrsUidLength; i++) { + FC.RX_CONFIG.elrsUid.push(data.readU8()); + } } - break; @@ -1145,11 +985,9 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.FAILSAFE_CONFIG.failsafe_delay = data.readU8(); FC.FAILSAFE_CONFIG.failsafe_off_delay = data.readU8(); FC.FAILSAFE_CONFIG.failsafe_throttle = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - FC.FAILSAFE_CONFIG.failsafe_switch_mode = data.readU8(); - FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay = data.readU16(); - FC.FAILSAFE_CONFIG.failsafe_procedure = data.readU8(); - } + FC.FAILSAFE_CONFIG.failsafe_switch_mode = data.readU8(); + FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay = data.readU16(); + FC.FAILSAFE_CONFIG.failsafe_procedure = data.readU8(); break; case MSPCodes.MSP_RXFAIL_CONFIG: @@ -1171,80 +1009,59 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.PID_ADVANCED_CONFIG.use_unsyncedPwm = data.readU8(); FC.PID_ADVANCED_CONFIG.fast_pwm_protocol = EscProtocols.ReorderPwmProtocols(FC.CONFIG.apiVersion, data.readU8()); FC.PID_ADVANCED_CONFIG.motor_pwm_rate = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - FC.PID_ADVANCED_CONFIG.digitalIdlePercent = data.readU16() / 100; - - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0")) { - let gyroUse32kHz = data.readU8(); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.PID_ADVANCED_CONFIG.gyroUse32kHz = gyroUse32kHz; - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.PID_ADVANCED_CONFIG.motorPwmInversion = data.readU8(); - FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); // We don't want to double up on storing this state - FC.PID_ADVANCED_CONFIG.gyroHighFsr = data.readU8(); - FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold = data.readU8(); - FC.PID_ADVANCED_CONFIG.gyroCalibDuration = data.readU16(); - FC.PID_ADVANCED_CONFIG.gyroOffsetYaw = data.readU16(); - FC.PID_ADVANCED_CONFIG.gyroCheckOverflow = data.readU8(); - FC.PID_ADVANCED_CONFIG.debugMode = data.readU8(); - FC.PID_ADVANCED_CONFIG.debugModeCount = data.readU8(); - } - } + FC.PID_ADVANCED_CONFIG.digitalIdlePercent = data.readU16() / 100; + data.readU8(); // gyroUse32Khz is not supported + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + FC.PID_ADVANCED_CONFIG.motorPwmInversion = data.readU8(); + FC.SENSOR_ALIGNMENT.gyro_to_use = data.readU8(); // We don't want to double up on storing this state + FC.PID_ADVANCED_CONFIG.gyroHighFsr = data.readU8(); + FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold = data.readU8(); + FC.PID_ADVANCED_CONFIG.gyroCalibDuration = data.readU16(); + FC.PID_ADVANCED_CONFIG.gyroOffsetYaw = data.readU16(); + FC.PID_ADVANCED_CONFIG.gyroCheckOverflow = data.readU8(); + FC.PID_ADVANCED_CONFIG.debugMode = data.readU8(); + FC.PID_ADVANCED_CONFIG.debugModeCount = data.readU8(); } break; case MSPCodes.MSP_FILTER_CONFIG: FC.FILTER_CONFIG.gyro_lowpass_hz = data.readU8(); FC.FILTER_CONFIG.dterm_lowpass_hz = data.readU16(); FC.FILTER_CONFIG.yaw_lowpass_hz = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - FC.FILTER_CONFIG.gyro_notch_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_notch_cutoff = data.readU16(); - FC.FILTER_CONFIG.dterm_notch_hz = data.readU16(); - FC.FILTER_CONFIG.dterm_notch_cutoff = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.21.0")) { - FC.FILTER_CONFIG.gyro_notch2_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_notch2_cutoff = data.readU16(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.FILTER_CONFIG.dterm_lowpass_type = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.FILTER_CONFIG.gyro_hardware_lpf = data.readU8(); - let gyro_32khz_hardware_lpf = data.readU8(); - FC.FILTER_CONFIG.gyro_lowpass_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_lowpass2_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_lowpass_type = data.readU8(); - FC.FILTER_CONFIG.gyro_lowpass2_type = data.readU8(); - FC.FILTER_CONFIG.dterm_lowpass2_hz = data.readU16(); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.FILTER_CONFIG.gyro_32khz_hardware_lpf = gyro_32khz_hardware_lpf; - } else { - FC.FILTER_CONFIG.gyro_32khz_hardware_lpf = 0; + FC.FILTER_CONFIG.gyro_notch_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_notch_cutoff = data.readU16(); + FC.FILTER_CONFIG.dterm_notch_hz = data.readU16(); + FC.FILTER_CONFIG.dterm_notch_cutoff = data.readU16(); + FC.FILTER_CONFIG.gyro_notch2_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_notch2_cutoff = data.readU16(); + FC.FILTER_CONFIG.dterm_lowpass_type = data.readU8(); + FC.FILTER_CONFIG.gyro_hardware_lpf = data.readU8(); + data.readU8(); // gyro_32khz_hardware_lpf not used + FC.FILTER_CONFIG.gyro_lowpass_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_lowpass2_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_lowpass_type = data.readU8(); + FC.FILTER_CONFIG.gyro_lowpass2_type = data.readU8(); + FC.FILTER_CONFIG.dterm_lowpass2_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_32khz_hardware_lpf = 0; + FC.FILTER_CONFIG.dterm_lowpass2_type = data.readU8(); + FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz = data.readU16(); + FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz = data.readU16(); + FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz = data.readU16(); + FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz = data.readU16(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + FC.FILTER_CONFIG.dyn_notch_range = data.readU8(); + FC.FILTER_CONFIG.dyn_notch_width_percent = data.readU8(); + FC.FILTER_CONFIG.dyn_notch_q = data.readU16(); + FC.FILTER_CONFIG.dyn_notch_min_hz = data.readU16(); - FC.FILTER_CONFIG.dterm_lowpass2_type = data.readU8(); - FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz = data.readU16(); - FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz = data.readU16(); - FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz = data.readU16(); - FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.FILTER_CONFIG.dyn_notch_range = data.readU8(); - FC.FILTER_CONFIG.dyn_notch_width_percent = data.readU8(); - FC.FILTER_CONFIG.dyn_notch_q = data.readU16(); - FC.FILTER_CONFIG.dyn_notch_min_hz = data.readU16(); - - FC.FILTER_CONFIG.gyro_rpm_notch_harmonics = data.readU8(); - FC.FILTER_CONFIG.gyro_rpm_notch_min_hz = data.readU8(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.FILTER_CONFIG.dyn_notch_max_hz = data.readU16(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.FILTER_CONFIG.dyn_lpf_curve_expo = data.readU8(); - FC.FILTER_CONFIG.dyn_notch_count = data.readU8(); - } - } - } + FC.FILTER_CONFIG.gyro_rpm_notch_harmonics = data.readU8(); + FC.FILTER_CONFIG.gyro_rpm_notch_min_hz = data.readU8(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + FC.FILTER_CONFIG.dyn_notch_max_hz = data.readU16(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + FC.FILTER_CONFIG.dyn_lpf_curve_expo = data.readU8(); + FC.FILTER_CONFIG.dyn_notch_count = data.readU8(); } break; case MSPCodes.MSP_SET_PID_ADVANCED: @@ -1252,93 +1069,69 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.ADVANCED_TUNING_ACTIVE = { ...FC.ADVANCED_TUNING }; break; case MSPCodes.MSP_PID_ADVANCED: - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - FC.ADVANCED_TUNING.rollPitchItermIgnoreRate = data.readU16(); - FC.ADVANCED_TUNING.yawItermIgnoreRate = data.readU16(); - FC.ADVANCED_TUNING.yaw_p_limit = data.readU16(); - FC.ADVANCED_TUNING.deltaMethod = data.readU8(); - FC.ADVANCED_TUNING.vbatPidCompensation = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - FC.ADVANCED_TUNING.feedforwardTransition = data.readU8(); - } else { - FC.ADVANCED_TUNING.dtermSetpointTransition = data.readU8(); - } - FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU8(); - FC.ADVANCED_TUNING.toleranceBand = data.readU8(); - FC.ADVANCED_TUNING.toleranceBandReduction = data.readU8(); - FC.ADVANCED_TUNING.itermThrottleGain = data.readU8(); - FC.ADVANCED_TUNING.pidMaxVelocity = data.readU16(); - FC.ADVANCED_TUNING.pidMaxVelocityYaw = data.readU16(); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - FC.ADVANCED_TUNING.levelAngleLimit = data.readU8(); - FC.ADVANCED_TUNING.levelSensitivity = data.readU8(); + FC.ADVANCED_TUNING.rollPitchItermIgnoreRate = data.readU16(); + FC.ADVANCED_TUNING.yawItermIgnoreRate = data.readU16(); + FC.ADVANCED_TUNING.yaw_p_limit = data.readU16(); + FC.ADVANCED_TUNING.deltaMethod = data.readU8(); + FC.ADVANCED_TUNING.vbatPidCompensation = data.readU8(); + FC.ADVANCED_TUNING.feedforwardTransition = data.readU8(); + FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU8(); + FC.ADVANCED_TUNING.toleranceBand = data.readU8(); + FC.ADVANCED_TUNING.toleranceBandReduction = data.readU8(); + FC.ADVANCED_TUNING.itermThrottleGain = data.readU8(); + FC.ADVANCED_TUNING.pidMaxVelocity = data.readU16(); + FC.ADVANCED_TUNING.pidMaxVelocityYaw = data.readU16(); + FC.ADVANCED_TUNING.levelAngleLimit = data.readU8(); + FC.ADVANCED_TUNING.levelSensitivity = data.readU8(); + FC.ADVANCED_TUNING.itermThrottleThreshold = data.readU16(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.ADVANCED_TUNING.antiGravityGain = data.readU16(); + } else { + FC.ADVANCED_TUNING.itermAcceleratorGain = data.readU16(); + } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.ADVANCED_TUNING.itermThrottleThreshold = data.readU16(); + FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU16(); + FC.ADVANCED_TUNING.itermRotation = data.readU8(); + FC.ADVANCED_TUNING.smartFeedforward = data.readU8(); + FC.ADVANCED_TUNING.itermRelax = data.readU8(); + FC.ADVANCED_TUNING.itermRelaxType = data.readU8(); + FC.ADVANCED_TUNING.absoluteControlGain = data.readU8(); + FC.ADVANCED_TUNING.throttleBoost = data.readU8(); + FC.ADVANCED_TUNING.acroTrainerAngleLimit = data.readU8(); + FC.ADVANCED_TUNING.feedforwardRoll = data.readU16(); + FC.ADVANCED_TUNING.feedforwardPitch = data.readU16(); + FC.ADVANCED_TUNING.feedforwardYaw = data.readU16(); + FC.ADVANCED_TUNING.antiGravityMode = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.ADVANCED_TUNING.antiGravityGain = data.readU16(); - } else { - FC.ADVANCED_TUNING.itermAcceleratorGain = data.readU16(); - } + FC.ADVANCED_TUNING.dMinRoll = data.readU8(); + FC.ADVANCED_TUNING.dMinPitch = data.readU8(); + FC.ADVANCED_TUNING.dMinYaw = data.readU8(); + FC.ADVANCED_TUNING.dMinGain = data.readU8(); + FC.ADVANCED_TUNING.dMinAdvance = data.readU8(); + FC.ADVANCED_TUNING.useIntegratedYaw = data.readU8(); + FC.ADVANCED_TUNING.integratedYawRelax = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.ADVANCED_TUNING.dtermSetpointWeight = data.readU16(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - FC.ADVANCED_TUNING.itermRotation = data.readU8(); - FC.ADVANCED_TUNING.smartFeedforward = data.readU8(); - FC.ADVANCED_TUNING.itermRelax = data.readU8(); - FC.ADVANCED_TUNING.itermRelaxType = data.readU8(); - FC.ADVANCED_TUNING.absoluteControlGain = data.readU8(); - FC.ADVANCED_TUNING.throttleBoost = data.readU8(); - FC.ADVANCED_TUNING.acroTrainerAngleLimit = data.readU8(); - FC.ADVANCED_TUNING.feedforwardRoll = data.readU16(); - FC.ADVANCED_TUNING.feedforwardPitch = data.readU16(); - FC.ADVANCED_TUNING.feedforwardYaw = data.readU16(); - FC.ADVANCED_TUNING.antiGravityMode = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.ADVANCED_TUNING.dMinRoll = data.readU8(); - FC.ADVANCED_TUNING.dMinPitch = data.readU8(); - FC.ADVANCED_TUNING.dMinYaw = data.readU8(); - FC.ADVANCED_TUNING.dMinGain = data.readU8(); - FC.ADVANCED_TUNING.dMinAdvance = data.readU8(); - FC.ADVANCED_TUNING.useIntegratedYaw = data.readU8(); - FC.ADVANCED_TUNING.integratedYawRelax = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - FC.ADVANCED_TUNING.itermRelaxCutoff = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - FC.ADVANCED_TUNING.motorOutputLimit = data.readU8(); - FC.ADVANCED_TUNING.autoProfileCellCount = data.read8(); - FC.ADVANCED_TUNING.idleMinRpm = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.ADVANCED_TUNING.feedforward_averaging = data.readU8(); - FC.ADVANCED_TUNING.feedforward_smooth_factor = data.readU8(); - FC.ADVANCED_TUNING.feedforward_boost = data.readU8(); - FC.ADVANCED_TUNING.feedforward_max_rate_limit = data.readU8(); - FC.ADVANCED_TUNING.feedforward_jitter_factor = data.readU8(); - FC.ADVANCED_TUNING.vbat_sag_compensation = data.readU8(); - FC.ADVANCED_TUNING.thrustLinearization = data.readU8(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.ADVANCED_TUNING.tpaMode = data.readU8(); - FC.ADVANCED_TUNING.tpaRate = parseFloat((data.readU8() / 100).toFixed(2)); - FC.ADVANCED_TUNING.tpaBreakpoint = data.readU16(); - } - } - } - } - } - } - } - } - } - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + FC.ADVANCED_TUNING.itermRelaxCutoff = data.readU8(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + FC.ADVANCED_TUNING.motorOutputLimit = data.readU8(); + FC.ADVANCED_TUNING.autoProfileCellCount = data.read8(); + FC.ADVANCED_TUNING.idleMinRpm = data.readU8(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + FC.ADVANCED_TUNING.feedforward_averaging = data.readU8(); + FC.ADVANCED_TUNING.feedforward_smooth_factor = data.readU8(); + FC.ADVANCED_TUNING.feedforward_boost = data.readU8(); + FC.ADVANCED_TUNING.feedforward_max_rate_limit = data.readU8(); + FC.ADVANCED_TUNING.feedforward_jitter_factor = data.readU8(); + FC.ADVANCED_TUNING.vbat_sag_compensation = data.readU8(); + FC.ADVANCED_TUNING.thrustLinearization = data.readU8(); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.ADVANCED_TUNING.tpaMode = data.readU8(); + FC.ADVANCED_TUNING.tpaRate = parseFloat((data.readU8() / 100).toFixed(2)); + FC.ADVANCED_TUNING.tpaBreakpoint = data.readU16(); } FC.ADVANCED_TUNING_ACTIVE = { ...FC.ADVANCED_TUNING }; break; @@ -1351,88 +1144,50 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_LED_STRIP_CONFIG: FC.LED_STRIP = []; - let ledCount = data.byteLength / 7; // v1.4.0 and below incorrectly reported 4 bytes per led. - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - ledCount = data.byteLength / 4; - } - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - // According to betaflight/src/main/msp/msp.c - // API 1.41 - add indicator for advanced profile support and the current profile selection - // 0 = basic ledstrip available - // 1 = advanced ledstrip available - // Following byte is the current LED profile - ledCount = (data.byteLength - 2) / 4; - } + // According to betaflight/src/main/msp/msp.c + // API 1.41 - add indicator for advanced profile support and the current profile selection + // 0 = basic ledstrip available + // 1 = advanced ledstrip available + // Following byte is the current LED profile + let ledCount = (data.byteLength - 2) / 4; + for (let i = 0; i < ledCount; i++) { - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - const directionMask = data.readU16(); + const mask = data.readU32(); - const directions = []; - for (let directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { - if (bit_check(directionMask, directionLetterIndex)) { - directions.push(ledDirectionLetters[directionLetterIndex]); - } + const functionId = (mask >> 8) & 0xF; + const functions = []; + for (let baseFunctionLetterIndex = 0; baseFunctionLetterIndex < ledBaseFunctionLetters.length; baseFunctionLetterIndex++) { + if (functionId == baseFunctionLetterIndex) { + functions.push(ledBaseFunctionLetters[baseFunctionLetterIndex]); + break; } - - const functionMask = data.readU16(); - - const functions = []; - for (let functionLetterIndex = 0; functionLetterIndex < ledFunctionLetters.length; functionLetterIndex++) { - if (bit_check(functionMask, functionLetterIndex)) { - functions.push(ledFunctionLetters[functionLetterIndex]); - } - } - - const led = { - directions: directions, - functions: functions, - x: data.readU8(), - y: data.readU8(), - color: data.readU8(), - }; - - FC.LED_STRIP.push(led); - } else { - const mask = data.readU32(); - - const functionId = (mask >> 8) & 0xF; - const functions = []; - for (let baseFunctionLetterIndex = 0; baseFunctionLetterIndex < ledBaseFunctionLetters.length; baseFunctionLetterIndex++) { - if (functionId == baseFunctionLetterIndex) { - functions.push(ledBaseFunctionLetters[baseFunctionLetterIndex]); - break; - } - } - - const overlayMask = (mask >> 12) & 0x3F; - for (let overlayLetterIndex = 0; overlayLetterIndex < ledOverlayLetters.length; overlayLetterIndex++) { - if (bit_check(overlayMask, overlayLetterIndex)) { - functions.push(ledOverlayLetters[overlayLetterIndex]); - } - } - - const directionMask = (mask >> 22) & 0x3F; - const directions = []; - for (let directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { - if (bit_check(directionMask, directionLetterIndex)) { - directions.push(ledDirectionLetters[directionLetterIndex]); - } - } - const led = { - y: (mask) & 0xF, - x: (mask >> 4) & 0xF, - functions: functions, - color: (mask >> 18) & 0xF, - directions: directions, - parameters: (mask >> 28) & 0xF, - }; - - FC.LED_STRIP.push(led); } + + const overlayMask = (mask >> 12) & 0x3F; + for (let overlayLetterIndex = 0; overlayLetterIndex < ledOverlayLetters.length; overlayLetterIndex++) { + if (bit_check(overlayMask, overlayLetterIndex)) { + functions.push(ledOverlayLetters[overlayLetterIndex]); + } + } + + const directionMask = (mask >> 22) & 0x3F; + const directions = []; + for (let directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { + if (bit_check(directionMask, directionLetterIndex)) { + directions.push(ledDirectionLetters[directionLetterIndex]); + } + } + const led = { + y: (mask) & 0xF, + x: (mask >> 4) & 0xF, + functions: functions, + color: (mask >> 18) & 0xF, + directions: directions, + parameters: (mask >> 28) & 0xF, + }; + + FC.LED_STRIP.push(led); } break; case MSPCodes.MSP_SET_LED_STRIP_CONFIG: @@ -1459,21 +1214,18 @@ MspHelper.prototype.process_data = function(dataHandler) { console.log('Led strip colors saved'); break; case MSPCodes.MSP_LED_STRIP_MODECOLOR: - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { + FC.LED_MODE_COLORS = []; - FC.LED_MODE_COLORS = []; + const colorCount = data.byteLength / 3; - const colorCount = data.byteLength / 3; + for (let i = 0; i < colorCount; i++) { - for (let i = 0; i < colorCount; i++) { - - const modeColor = { - mode: data.readU8(), - direction: data.readU8(), - color: data.readU8(), - }; - FC.LED_MODE_COLORS.push(modeColor); - } + const modeColor = { + mode: data.readU8(), + direction: data.readU8(), + color: data.readU8(), + }; + FC.LED_MODE_COLORS.push(modeColor); } break; case MSPCodes.MSP_SET_LED_STRIP_MODECOLOR: @@ -1518,9 +1270,7 @@ MspHelper.prototype.process_data = function(dataHandler) { FC.BLACKBOX.blackboxDevice = data.readU8(); FC.BLACKBOX.blackboxRateNum = data.readU8(); FC.BLACKBOX.blackboxRateDenom = data.readU8(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.BLACKBOX.blackboxPDenom = data.readU16(); - } + FC.BLACKBOX.blackboxPDenom = data.readU16(); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { FC.BLACKBOX.blackboxSampleRate = data.readU8(); } @@ -1530,37 +1280,26 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_TRANSPONDER_CONFIG: let bytesRemaining = data.byteLength; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - const providerCount = data.readU8(); - bytesRemaining--; + const providerCount = data.readU8(); + bytesRemaining--; - FC.TRANSPONDER.supported = providerCount > 0; - FC.TRANSPONDER.providers = []; + FC.TRANSPONDER.supported = providerCount > 0; + FC.TRANSPONDER.providers = []; - for (let i = 0; i < providerCount; i++) { - const provider = { - id: data.readU8(), - dataLength: data.readU8(), - }; - bytesRemaining -= 2; + for (let i = 0; i < providerCount; i++) { + const provider = { + id: data.readU8(), + dataLength: data.readU8(), + }; + bytesRemaining -= 2; - FC.TRANSPONDER.providers.push(provider); - } - FC.TRANSPONDER.provider = data.readU8(); - bytesRemaining--; - - } else { - FC.TRANSPONDER.supported = (data.readU8() & 1) != 0; - bytesRemaining--; - - // only ILAP was supported prior to 1.33.0 - FC.TRANSPONDER.providers = [{ - id: 1, // ILAP - dataLength: 6, - }]; - FC.TRANSPONDER.provider = FC.TRANSPONDER.providers[0].id; + FC.TRANSPONDER.providers.push(provider); } + FC.TRANSPONDER.provider = data.readU8(); + bytesRemaining--; + FC.TRANSPONDER.data = []; + for (let i = 0; i < bytesRemaining; i++) { FC.TRANSPONDER.data.push(data.readU8()); } @@ -1876,18 +1615,12 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { case MSPCodes.MSP_SET_BEEPER_CONFIG: const beeperDisabledMask = FC.BEEPER_CONFIG.beepers.getDisabledMask(); buffer.push32(beeperDisabledMask); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - buffer.push8(FC.BEEPER_CONFIG.dshotBeaconTone); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - buffer.push32(FC.BEEPER_CONFIG.dshotBeaconConditions.getDisabledMask()); - } + buffer.push8(FC.BEEPER_CONFIG.dshotBeaconTone); + buffer.push32(FC.BEEPER_CONFIG.dshotBeaconConditions.getDisabledMask()); break; case MSPCodes.MSP_SET_MIXER_CONFIG: buffer.push8(FC.MIXER_CONFIG.mixer); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push8(FC.MIXER_CONFIG.reverseMotorDir); - } + buffer.push8(FC.MIXER_CONFIG.reverseMotorDir); break; case MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG: buffer.push16(FC.BOARD_ALIGNMENT_CONFIG.roll) @@ -1906,42 +1639,28 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { break; case MSPCodes.MSP_SET_RC_TUNING: buffer.push8(Math.round(FC.RC_TUNING.RC_RATE * 100)) - .push8(Math.round(FC.RC_TUNING.RC_EXPO * 100)); - if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - buffer.push8(Math.round(FC.RC_TUNING.roll_pitch_rate * 100)); - } else { - buffer.push8(Math.round(FC.RC_TUNING.roll_rate * 100)) - .push8(Math.round(FC.RC_TUNING.pitch_rate * 100)); - } - buffer.push8(Math.round(FC.RC_TUNING.yaw_rate * 100)); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push8(Math.round(FC.RC_TUNING.dynamic_THR_PID * 100)); - } else { + .push8(Math.round(FC.RC_TUNING.RC_EXPO * 100)) + .push8(Math.round(FC.RC_TUNING.roll_rate * 100)) + .push8(Math.round(FC.RC_TUNING.pitch_rate * 100)) + .push8(Math.round(FC.RC_TUNING.yaw_rate * 100)); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { buffer.push8(0); + } else { + buffer.push8(Math.round(FC.RC_TUNING.dynamic_THR_PID * 100)); } buffer.push8(Math.round(FC.RC_TUNING.throttle_MID * 100)); buffer.push8(Math.round(FC.RC_TUNING.throttle_EXPO * 100)); - if (semver.gte(FC.CONFIG.apiVersion, "1.7.0")) { - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push16(FC.RC_TUNING.dynamic_THR_breakpoint); - } else { - buffer.push16(0); - } - } - if (semver.gte(FC.CONFIG.apiVersion, "1.10.0")) { - buffer.push8(Math.round(FC.RC_TUNING.RC_YAW_EXPO * 100)); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - buffer.push8(Math.round(FC.RC_TUNING.rcYawRate * 100)); - } - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - buffer.push8(Math.round(FC.RC_TUNING.rcPitchRate * 100)); - buffer.push8(Math.round(FC.RC_TUNING.RC_PITCH_EXPO * 100)); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.RC_TUNING.throttleLimitType); - buffer.push8(FC.RC_TUNING.throttleLimitPercent); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + buffer.push16(0); + } else { + buffer.push16(FC.RC_TUNING.dynamic_THR_breakpoint); } + buffer.push8(Math.round(FC.RC_TUNING.RC_YAW_EXPO * 100)); + buffer.push8(Math.round(FC.RC_TUNING.rcYawRate * 100)); + buffer.push8(Math.round(FC.RC_TUNING.rcPitchRate * 100)); + buffer.push8(Math.round(FC.RC_TUNING.RC_PITCH_EXPO * 100)); + buffer.push8(FC.RC_TUNING.throttleLimitType); + buffer.push8(FC.RC_TUNING.throttleLimitPercent); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { buffer.push16(FC.RC_TUNING.roll_rate_limit); buffer.push16(FC.RC_TUNING.pitch_rate_limit); @@ -1962,10 +1681,8 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { break; case MSPCodes.MSP_SET_ARMING_CONFIG: buffer.push8(FC.ARMING_CONFIG.auto_disarm_delay) - .push8(FC.ARMING_CONFIG.disarm_kill_switch); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - buffer.push8(FC.ARMING_CONFIG.small_angle); - } + .push8(FC.ARMING_CONFIG.disarm_kill_switch) + .push8(FC.ARMING_CONFIG.small_angle); break; case MSPCodes.MSP_SET_LOOP_TIME: buffer.push16(FC.FC_CONFIG.loopTime); @@ -1999,15 +1716,13 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { break; case MSPCodes.MSP_SET_GPS_CONFIG: buffer.push8(FC.GPS_CONFIG.provider) - .push8(FC.GPS_CONFIG.ublox_sbas); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - buffer.push8(FC.GPS_CONFIG.auto_config) - .push8(FC.GPS_CONFIG.auto_baud); + .push8(FC.GPS_CONFIG.ublox_sbas) + .push8(FC.GPS_CONFIG.auto_config) + .push8(FC.GPS_CONFIG.auto_baud); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push8(FC.GPS_CONFIG.home_point_once) - .push8(FC.GPS_CONFIG.ublox_use_galileo); - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + buffer.push8(FC.GPS_CONFIG.home_point_once) + .push8(FC.GPS_CONFIG.ublox_use_galileo); } break; case MSPCodes.MSP_SET_GPS_RESCUE: @@ -2021,15 +1736,15 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(FC.GPS_RESCUE.sanityChecks) .push8(FC.GPS_RESCUE.minSats); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push16(FC.GPS_RESCUE.ascendRate) - .push16(FC.GPS_RESCUE.descendRate) - .push8(FC.GPS_RESCUE.allowArmingWithoutFix) - .push8(FC.GPS_RESCUE.altitudeMode); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push16(FC.GPS_RESCUE.minRescueDth); - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + buffer.push16(FC.GPS_RESCUE.ascendRate) + .push16(FC.GPS_RESCUE.descendRate) + .push8(FC.GPS_RESCUE.allowArmingWithoutFix) + .push8(FC.GPS_RESCUE.altitudeMode); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + buffer.push16(FC.GPS_RESCUE.minRescueDth); + } break; case MSPCodes.MSP_SET_RSSI_CONFIG: buffer.push8(FC.RSSI_CONFIG.channel); @@ -2040,33 +1755,17 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push8(Math.round(FC.BATTERY_CONFIG.vbatwarningcellvoltage * 10)) .push16(FC.BATTERY_CONFIG.capacity) .push8(FC.BATTERY_CONFIG.voltageMeterSource) - .push8(FC.BATTERY_CONFIG.currentMeterSource); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push16(Math.round(FC.BATTERY_CONFIG.vbatmincellvoltage * 100)) - .push16(Math.round(FC.BATTERY_CONFIG.vbatmaxcellvoltage * 100)) - .push16(Math.round(FC.BATTERY_CONFIG.vbatwarningcellvoltage * 100)); - } + .push8(FC.BATTERY_CONFIG.currentMeterSource) + .push16(Math.round(FC.BATTERY_CONFIG.vbatmincellvoltage * 100)) + .push16(Math.round(FC.BATTERY_CONFIG.vbatmaxcellvoltage * 100)) + .push16(Math.round(FC.BATTERY_CONFIG.vbatwarningcellvoltage * 100)); break; case MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push8(FC.MISC.vbatscale) - .push8(Math.round(FC.MISC.vbatmincellvoltage * 10)) - .push8(Math.round(FC.MISC.vbatmaxcellvoltage * 10)) - .push8(Math.round(FC.MISC.vbatwarningcellvoltage * 10)); - if (semver.gte(FC.CONFIG.apiVersion, "1.23.0")) { - buffer.push8(FC.MISC.batterymetertype); - } - } + // not used break; case MSPCodes.MSP_SET_CURRENT_METER_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push16(FC.BF_CONFIG.currentscale) - .push16(FC.BF_CONFIG.currentoffset) - .push8(FC.BF_CONFIG.currentmetertype) - .push16(FC.BF_CONFIG.batterycapacity); - } + // not used break; - case MSPCodes.MSP_SET_RX_CONFIG: buffer.push8(FC.RX_CONFIG.serialrx_provider) .push16(FC.RX_CONFIG.stick_max) @@ -2074,54 +1773,46 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { .push16(FC.RX_CONFIG.stick_min) .push8(FC.RX_CONFIG.spektrum_sat_bind) .push16(FC.RX_CONFIG.rx_min_usec) - .push16(FC.RX_CONFIG.rx_max_usec); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - buffer.push8(FC.RX_CONFIG.rcInterpolation) - .push8(FC.RX_CONFIG.rcInterpolationInterval) - .push16(FC.RX_CONFIG.airModeActivateThreshold); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - buffer.push8(FC.RX_CONFIG.rxSpiProtocol) - .push32(FC.RX_CONFIG.rxSpiId) - .push8(FC.RX_CONFIG.rxSpiRfChannelCount) - .push8(FC.RX_CONFIG.fpvCamAngleDegrees); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - buffer.push8(FC.RX_CONFIG.rcInterpolationChannels) - .push8(FC.RX_CONFIG.rcSmoothingType) - .push8(FC.RX_CONFIG.rcSmoothingSetpointCutoff) - .push8(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff) - .push8(FC.RX_CONFIG.rcSmoothingInputType) - .push8(FC.RX_CONFIG.rcSmoothingDerivativeType); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.RX_CONFIG.usbCdcHidType) - .push8(FC.RX_CONFIG.rcSmoothingAutoFactor); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push8(FC.RX_CONFIG.rcSmoothingMode); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.RX_CONFIG.elrsUid.forEach((b) => buffer.push8(b)); - } - } - } - } + .push16(FC.RX_CONFIG.rx_max_usec) + .push8(FC.RX_CONFIG.rcInterpolation) + .push8(FC.RX_CONFIG.rcInterpolationInterval) + .push16(FC.RX_CONFIG.airModeActivateThreshold) + .push8(FC.RX_CONFIG.rxSpiProtocol) + .push32(FC.RX_CONFIG.rxSpiId) + .push8(FC.RX_CONFIG.rxSpiRfChannelCount) + .push8(FC.RX_CONFIG.fpvCamAngleDegrees) + .push8(FC.RX_CONFIG.rcInterpolationChannels) + .push8(FC.RX_CONFIG.rcSmoothingType) + .push8(FC.RX_CONFIG.rcSmoothingSetpointCutoff) + .push8(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff) + .push8(FC.RX_CONFIG.rcSmoothingInputType) + .push8(FC.RX_CONFIG.rcSmoothingDerivativeType); + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + buffer.push8(FC.RX_CONFIG.usbCdcHidType) + .push8(FC.RX_CONFIG.rcSmoothingAutoFactor); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + buffer.push8(FC.RX_CONFIG.rcSmoothingMode); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.RX_CONFIG.elrsUid.forEach(b => buffer.push8(b)); } - } break; case MSPCodes.MSP_SET_FAILSAFE_CONFIG: buffer.push8(FC.FAILSAFE_CONFIG.failsafe_delay) .push8(FC.FAILSAFE_CONFIG.failsafe_off_delay) - .push16(FC.FAILSAFE_CONFIG.failsafe_throttle); - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - buffer.push8(FC.FAILSAFE_CONFIG.failsafe_switch_mode) - .push16(FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay) - .push8(FC.FAILSAFE_CONFIG.failsafe_procedure); - } + .push16(FC.FAILSAFE_CONFIG.failsafe_throttle) + .push8(FC.FAILSAFE_CONFIG.failsafe_switch_mode) + .push16(FC.FAILSAFE_CONFIG.failsafe_throttle_low_delay) + .push8(FC.FAILSAFE_CONFIG.failsafe_procedure); break; case MSPCodes.MSP_SET_TRANSPONDER_CONFIG: - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - buffer.push8(FC.TRANSPONDER.provider); // - } + buffer.push8(FC.TRANSPONDER.provider); // + for (let i = 0; i < FC.TRANSPONDER.data.length; i++) { buffer.push8(FC.TRANSPONDER.data[i]); } @@ -2137,28 +1828,17 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { } break; case MSPCodes.MSP_SET_CF_SERIAL_CONFIG: - if (semver.lt(FC.CONFIG.apiVersion, "1.6.0")) { + for (let i = 0; i < FC.SERIAL_CONFIG.ports.length; i++) { + const serialPort = FC.SERIAL_CONFIG.ports[i]; - for (let i = 0; i < FC.SERIAL_CONFIG.ports.length; i++) { - buffer.push8(FC.SERIAL_CONFIG.ports[i].scenario); - } - buffer.push32(FC.SERIAL_CONFIG.mspBaudRate) - .push32(FC.SERIAL_CONFIG.cliBaudRate) - .push32(FC.SERIAL_CONFIG.gpsBaudRate) - .push32(FC.SERIAL_CONFIG.gpsPassthroughBaudRate); - } else { - for (let i = 0; i < FC.SERIAL_CONFIG.ports.length; i++) { - const serialPort = FC.SERIAL_CONFIG.ports[i]; + buffer.push8(serialPort.identifier); - buffer.push8(serialPort.identifier); - - const functionMask = self.serialPortFunctionsToMask(serialPort.functions); - buffer.push16(functionMask) - .push8(self.BAUD_RATES.indexOf(serialPort.msp_baudrate)) - .push8(self.BAUD_RATES.indexOf(serialPort.gps_baudrate)) - .push8(self.BAUD_RATES.indexOf(serialPort.telemetry_baudrate)) - .push8(self.BAUD_RATES.indexOf(serialPort.blackbox_baudrate)); - } + const functionMask = self.serialPortFunctionsToMask(serialPort.functions); + buffer.push16(functionMask) + .push8(self.BAUD_RATES.indexOf(serialPort.msp_baudrate)) + .push8(self.BAUD_RATES.indexOf(serialPort.gps_baudrate)) + .push8(self.BAUD_RATES.indexOf(serialPort.telemetry_baudrate)) + .push8(self.BAUD_RATES.indexOf(serialPort.blackbox_baudrate)); } break; @@ -2183,202 +1863,146 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { buffer.push16(FC.MOTOR_3D_CONFIG.deadband3d_low) .push16(FC.MOTOR_3D_CONFIG.deadband3d_high) .push16(FC.MOTOR_3D_CONFIG.neutral); - if (semver.lt(FC.CONFIG.apiVersion, "1.17.0")) { - buffer.push16(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); - } break; case MSPCodes.MSP_SET_RC_DEADBAND: buffer.push8(FC.RC_DEADBAND_CONFIG.deadband) .push8(FC.RC_DEADBAND_CONFIG.yaw_deadband) - .push8(FC.RC_DEADBAND_CONFIG.alt_hold_deadband); - if (semver.gte(FC.CONFIG.apiVersion, "1.17.0")) { - buffer.push16(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); - } + .push8(FC.RC_DEADBAND_CONFIG.alt_hold_deadband) + .push16(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); break; case MSPCodes.MSP_SET_SENSOR_ALIGNMENT: buffer.push8(FC.SENSOR_ALIGNMENT.align_gyro) .push8(FC.SENSOR_ALIGNMENT.align_acc) - .push8(FC.SENSOR_ALIGNMENT.align_mag); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.SENSOR_ALIGNMENT.gyro_to_use) + .push8(FC.SENSOR_ALIGNMENT.align_mag) + .push8(FC.SENSOR_ALIGNMENT.gyro_to_use) .push8(FC.SENSOR_ALIGNMENT.gyro_1_align) .push8(FC.SENSOR_ALIGNMENT.gyro_2_align); - } break; case MSPCodes.MSP_SET_ADVANCED_CONFIG: buffer.push8(FC.PID_ADVANCED_CONFIG.gyro_sync_denom) .push8(FC.PID_ADVANCED_CONFIG.pid_process_denom) .push8(FC.PID_ADVANCED_CONFIG.use_unsyncedPwm) .push8(EscProtocols.ReorderPwmProtocols(FC.CONFIG.apiVersion, FC.PID_ADVANCED_CONFIG.fast_pwm_protocol)) - .push16(FC.PID_ADVANCED_CONFIG.motor_pwm_rate); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - buffer.push16(FC.PID_ADVANCED_CONFIG.digitalIdlePercent * 100); - - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0")) { - let gyroUse32kHz = 0; - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gyroUse32kHz = FC.PID_ADVANCED_CONFIG.gyroUse32kHz; - } - buffer.push8(gyroUse32kHz); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.PID_ADVANCED_CONFIG.motorPwmInversion) - .push8(FC.SENSOR_ALIGNMENT.gyro_to_use) // We don't want to double up on storing this state - .push8(FC.PID_ADVANCED_CONFIG.gyroHighFsr) - .push8(FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold) - .push16(FC.PID_ADVANCED_CONFIG.gyroCalibDuration) - .push16(FC.PID_ADVANCED_CONFIG.gyroOffsetYaw) - .push8(FC.PID_ADVANCED_CONFIG.gyroCheckOverflow) - .push8(FC.PID_ADVANCED_CONFIG.debugMode); - } + .push16(FC.PID_ADVANCED_CONFIG.motor_pwm_rate) + .push16(FC.PID_ADVANCED_CONFIG.digitalIdlePercent * 100) + .push8(0); // gyroUse32kHz not used + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + buffer.push8(FC.PID_ADVANCED_CONFIG.motorPwmInversion) + .push8(FC.SENSOR_ALIGNMENT.gyro_to_use) // We don't want to double up on storing this state + .push8(FC.PID_ADVANCED_CONFIG.gyroHighFsr) + .push8(FC.PID_ADVANCED_CONFIG.gyroMovementCalibThreshold) + .push16(FC.PID_ADVANCED_CONFIG.gyroCalibDuration) + .push16(FC.PID_ADVANCED_CONFIG.gyroOffsetYaw) + .push8(FC.PID_ADVANCED_CONFIG.gyroCheckOverflow) + .push8(FC.PID_ADVANCED_CONFIG.debugMode); } - } - break; + break; case MSPCodes.MSP_SET_FILTER_CONFIG: buffer.push8(FC.FILTER_CONFIG.gyro_lowpass_hz) .push16(FC.FILTER_CONFIG.dterm_lowpass_hz) - .push16(FC.FILTER_CONFIG.yaw_lowpass_hz); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - buffer.push16(FC.FILTER_CONFIG.gyro_notch_hz) - .push16(FC.FILTER_CONFIG.gyro_notch_cutoff) - .push16(FC.FILTER_CONFIG.dterm_notch_hz) - .push16(FC.FILTER_CONFIG.dterm_notch_cutoff); - if (semver.gte(FC.CONFIG.apiVersion, "1.21.0")) { - buffer.push16(FC.FILTER_CONFIG.gyro_notch2_hz) - .push16(FC.FILTER_CONFIG.gyro_notch2_cutoff); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push8(FC.FILTER_CONFIG.dterm_lowpass_type); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - let gyro_32khz_hardware_lpf = 0; - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gyro_32khz_hardware_lpf = FC.FILTER_CONFIG.gyro_32khz_hardware_lpf; - } - buffer.push8(FC.FILTER_CONFIG.gyro_hardware_lpf) - .push8(gyro_32khz_hardware_lpf) - .push16(FC.FILTER_CONFIG.gyro_lowpass_hz) - .push16(FC.FILTER_CONFIG.gyro_lowpass2_hz) - .push8(FC.FILTER_CONFIG.gyro_lowpass_type) - .push8(FC.FILTER_CONFIG.gyro_lowpass2_type) - .push16(FC.FILTER_CONFIG.dterm_lowpass2_hz); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.FILTER_CONFIG.dterm_lowpass2_type) - .push16(FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz) - .push16(FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz) - .push16(FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz) - .push16(FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.FILTER_CONFIG.dyn_notch_range) - .push8(FC.FILTER_CONFIG.dyn_notch_width_percent) - .push16(FC.FILTER_CONFIG.dyn_notch_q) - .push16(FC.FILTER_CONFIG.dyn_notch_min_hz) - .push8(FC.FILTER_CONFIG.gyro_rpm_notch_harmonics) - .push8(FC.FILTER_CONFIG.gyro_rpm_notch_min_hz); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push16(FC.FILTER_CONFIG.dyn_notch_max_hz); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push8(FC.FILTER_CONFIG.dyn_lpf_curve_expo) - .push8(FC.FILTER_CONFIG.dyn_notch_count); - } + .push16(FC.FILTER_CONFIG.yaw_lowpass_hz) + .push16(FC.FILTER_CONFIG.gyro_notch_hz) + .push16(FC.FILTER_CONFIG.gyro_notch_cutoff) + .push16(FC.FILTER_CONFIG.dterm_notch_hz) + .push16(FC.FILTER_CONFIG.dterm_notch_cutoff) + .push16(FC.FILTER_CONFIG.gyro_notch2_hz) + .push16(FC.FILTER_CONFIG.gyro_notch2_cutoff) + .push8(FC.FILTER_CONFIG.dterm_lowpass_type) + .push8(0) // FC.FILTER_CONFIG.gyro_hardware_lpf not used + .push8(0) // gyro_32khz_hardware_lpf not used + .push16(FC.FILTER_CONFIG.gyro_lowpass_hz) + .push16(FC.FILTER_CONFIG.gyro_lowpass2_hz) + .push8(FC.FILTER_CONFIG.gyro_lowpass_type) + .push8(FC.FILTER_CONFIG.gyro_lowpass2_type) + .push16(FC.FILTER_CONFIG.dterm_lowpass2_hz) + .push8(FC.FILTER_CONFIG.dterm_lowpass2_type) + .push16(FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz) + .push16(FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz) + .push16(FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz) + .push16(FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + buffer.push8(FC.FILTER_CONFIG.dyn_notch_range) + .push8(FC.FILTER_CONFIG.dyn_notch_width_percent) + .push16(FC.FILTER_CONFIG.dyn_notch_q) + .push16(FC.FILTER_CONFIG.dyn_notch_min_hz) + .push8(FC.FILTER_CONFIG.gyro_rpm_notch_harmonics) + .push8(FC.FILTER_CONFIG.gyro_rpm_notch_min_hz); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + buffer.push16(FC.FILTER_CONFIG.dyn_notch_max_hz); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + buffer.push8(FC.FILTER_CONFIG.dyn_lpf_curve_expo) + .push8(FC.FILTER_CONFIG.dyn_notch_count); } break; case MSPCodes.MSP_SET_PID_ADVANCED: - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - buffer.push16(FC.ADVANCED_TUNING.rollPitchItermIgnoreRate) - .push16(FC.ADVANCED_TUNING.yawItermIgnoreRate) - .push16(FC.ADVANCED_TUNING.yaw_p_limit) - .push8(FC.ADVANCED_TUNING.deltaMethod) - .push8(FC.ADVANCED_TUNING.vbatPidCompensation); + buffer.push16(FC.ADVANCED_TUNING.rollPitchItermIgnoreRate) + .push16(FC.ADVANCED_TUNING.yawItermIgnoreRate) + .push16(FC.ADVANCED_TUNING.yaw_p_limit) + .push8(FC.ADVANCED_TUNING.deltaMethod) + .push8(FC.ADVANCED_TUNING.vbatPidCompensation) + .push8(FC.ADVANCED_TUNING.feedforwardTransition) + .push8(Math.min(FC.ADVANCED_TUNING.dtermSetpointWeight, 254)) + .push8(FC.ADVANCED_TUNING.toleranceBand) + .push8(FC.ADVANCED_TUNING.toleranceBandReduction) + .push8(FC.ADVANCED_TUNING.itermThrottleGain) + .push16(FC.ADVANCED_TUNING.pidMaxVelocity) + .push16(FC.ADVANCED_TUNING.pidMaxVelocityYaw) + .push8(FC.ADVANCED_TUNING.levelAngleLimit) + .push8(FC.ADVANCED_TUNING.levelSensitivity) + .push16(FC.ADVANCED_TUNING.itermThrottleThreshold); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - buffer.push8(FC.ADVANCED_TUNING.feedforwardTransition); - } else { - buffer.push8(FC.ADVANCED_TUNING.dtermSetpointTransition); - } - buffer.push8(Math.min(FC.ADVANCED_TUNING.dtermSetpointWeight, 254)) - .push8(FC.ADVANCED_TUNING.toleranceBand) - .push8(FC.ADVANCED_TUNING.toleranceBandReduction) - .push8(FC.ADVANCED_TUNING.itermThrottleGain) - .push16(FC.ADVANCED_TUNING.pidMaxVelocity) - .push16(FC.ADVANCED_TUNING.pidMaxVelocityYaw); - - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - buffer.push8(FC.ADVANCED_TUNING.levelAngleLimit) - .push8(FC.ADVANCED_TUNING.levelSensitivity); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push16(FC.ADVANCED_TUNING.itermThrottleThreshold); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push16(FC.ADVANCED_TUNING.antiGravityGain); - } else { - buffer.push16(FC.ADVANCED_TUNING.itermAcceleratorGain); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - buffer.push16(FC.ADVANCED_TUNING.dtermSetpointWeight); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - buffer.push8(FC.ADVANCED_TUNING.itermRotation) - .push8(FC.ADVANCED_TUNING.smartFeedforward) - .push8(FC.ADVANCED_TUNING.itermRelax) - .push8(FC.ADVANCED_TUNING.itermRelaxType) - .push8(FC.ADVANCED_TUNING.absoluteControlGain) - .push8(FC.ADVANCED_TUNING.throttleBoost) - .push8(FC.ADVANCED_TUNING.acroTrainerAngleLimit) - .push16(FC.ADVANCED_TUNING.feedforwardRoll) - .push16(FC.ADVANCED_TUNING.feedforwardPitch) - .push16(FC.ADVANCED_TUNING.feedforwardYaw) - .push8(FC.ADVANCED_TUNING.antiGravityMode); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - buffer.push8(FC.ADVANCED_TUNING.dMinRoll) - .push8(FC.ADVANCED_TUNING.dMinPitch) - .push8(FC.ADVANCED_TUNING.dMinYaw) - .push8(FC.ADVANCED_TUNING.dMinGain) - .push8(FC.ADVANCED_TUNING.dMinAdvance) - .push8(FC.ADVANCED_TUNING.useIntegratedYaw) - .push8(FC.ADVANCED_TUNING.integratedYawRelax); - - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - buffer.push8(FC.ADVANCED_TUNING.itermRelaxCutoff); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - buffer.push8(FC.ADVANCED_TUNING.motorOutputLimit) - .push8(FC.ADVANCED_TUNING.autoProfileCellCount) - .push8(FC.ADVANCED_TUNING.idleMinRpm); - - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - buffer.push8(FC.ADVANCED_TUNING.feedforward_averaging) - .push8(FC.ADVANCED_TUNING.feedforward_smooth_factor) - .push8(FC.ADVANCED_TUNING.feedforward_boost) - .push8(FC.ADVANCED_TUNING.feedforward_max_rate_limit) - .push8(FC.ADVANCED_TUNING.feedforward_jitter_factor) - .push8(FC.ADVANCED_TUNING.vbat_sag_compensation) - .push8(FC.ADVANCED_TUNING.thrustLinearization); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - buffer.push8(FC.ADVANCED_TUNING.tpaMode); - buffer.push8(Math.round(FC.ADVANCED_TUNING.tpaRate * 100)); - buffer.push16(FC.ADVANCED_TUNING.tpaBreakpoint); - } - } - } - } - } - } - } - } - } - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + buffer.push16(FC.ADVANCED_TUNING.antiGravityGain); + } else { + buffer.push16(FC.ADVANCED_TUNING.itermAcceleratorGain); } + + buffer.push16(FC.ADVANCED_TUNING.dtermSetpointWeight) + .push8(FC.ADVANCED_TUNING.itermRotation) + .push8(FC.ADVANCED_TUNING.smartFeedforward) + .push8(FC.ADVANCED_TUNING.itermRelax) + .push8(FC.ADVANCED_TUNING.itermRelaxType) + .push8(FC.ADVANCED_TUNING.absoluteControlGain) + .push8(FC.ADVANCED_TUNING.throttleBoost) + .push8(FC.ADVANCED_TUNING.acroTrainerAngleLimit) + .push16(FC.ADVANCED_TUNING.feedforwardRoll) + .push16(FC.ADVANCED_TUNING.feedforwardPitch) + .push16(FC.ADVANCED_TUNING.feedforwardYaw) + .push8(FC.ADVANCED_TUNING.antiGravityMode) + .push8(FC.ADVANCED_TUNING.dMinRoll) + .push8(FC.ADVANCED_TUNING.dMinPitch) + .push8(FC.ADVANCED_TUNING.dMinYaw) + .push8(FC.ADVANCED_TUNING.dMinGain) + .push8(FC.ADVANCED_TUNING.dMinAdvance) + .push8(FC.ADVANCED_TUNING.useIntegratedYaw) + .push8(FC.ADVANCED_TUNING.integratedYawRelax); + + if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + buffer.push8(FC.ADVANCED_TUNING.itermRelaxCutoff); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + buffer.push8(FC.ADVANCED_TUNING.motorOutputLimit) + .push8(FC.ADVANCED_TUNING.autoProfileCellCount) + .push8(FC.ADVANCED_TUNING.idleMinRpm); + } + if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + buffer.push8(FC.ADVANCED_TUNING.feedforward_averaging) + .push8(FC.ADVANCED_TUNING.feedforward_smooth_factor) + .push8(FC.ADVANCED_TUNING.feedforward_boost) + .push8(FC.ADVANCED_TUNING.feedforward_max_rate_limit) + .push8(FC.ADVANCED_TUNING.feedforward_jitter_factor) + .push8(FC.ADVANCED_TUNING.vbat_sag_compensation) + .push8(FC.ADVANCED_TUNING.thrustLinearization); + } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + buffer.push8(FC.ADVANCED_TUNING.tpaMode); + buffer.push8(Math.round(FC.ADVANCED_TUNING.tpaRate * 100)); + buffer.push16(FC.ADVANCED_TUNING.tpaBreakpoint); + } break; case MSPCodes.MSP_SET_SENSOR_CONFIG: buffer.push8(FC.SENSOR_CONFIG.acc_hardware) @@ -2420,10 +2044,8 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { case MSPCodes.MSP_SET_BLACKBOX_CONFIG: buffer.push8(FC.BLACKBOX.blackboxDevice) .push8(FC.BLACKBOX.blackboxRateNum) - .push8(FC.BLACKBOX.blackboxRateDenom); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - buffer.push16(FC.BLACKBOX.blackboxPDenom); - } + .push8(FC.BLACKBOX.blackboxRateDenom) + .push16(FC.BLACKBOX.blackboxPDenom); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { buffer.push8(FC.BLACKBOX.blackboxSampleRate); } @@ -2455,39 +2077,29 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) { case MSPCodes.MSP_SET_RTC: const now = new Date(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - const timestamp = now.getTime(); - const secs = timestamp / 1000; - const millis = timestamp % 1000; - buffer.push32(secs); - buffer.push16(millis); - } else { - buffer.push16(now.getUTCFullYear()); - buffer.push8(now.getUTCMonth() + 1); - buffer.push8(now.getUTCDate()); - buffer.push8(now.getUTCHours()); - buffer.push8(now.getUTCMinutes()); - buffer.push8(now.getUTCSeconds()); - } - + const timestamp = now.getTime(); + const secs = timestamp / 1000; + const millis = timestamp % 1000; + buffer.push32(secs); + buffer.push16(millis); break; case MSPCodes.MSP_SET_VTX_CONFIG: buffer.push16(FC.VTX_CONFIG.vtx_frequency) - .push8(FC.VTX_CONFIG.vtx_power) - .push8(FC.VTX_CONFIG.vtx_pit_mode ? 1 : 0) - .push8(FC.VTX_CONFIG.vtx_low_power_disarm); + .push8(FC.VTX_CONFIG.vtx_power) + .push8(FC.VTX_CONFIG.vtx_pit_mode ? 1 : 0) + .push8(FC.VTX_CONFIG.vtx_low_power_disarm); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { buffer.push16(FC.VTX_CONFIG.vtx_pit_mode_frequency) - .push8(FC.VTX_CONFIG.vtx_band) - .push8(FC.VTX_CONFIG.vtx_channel) - .push16(FC.VTX_CONFIG.vtx_frequency) - .push8(FC.VTX_CONFIG.vtx_table_bands) - .push8(FC.VTX_CONFIG.vtx_table_channels) - .push8(FC.VTX_CONFIG.vtx_table_powerlevels) - .push8(FC.VTX_CONFIG.vtx_table_clear ? 1 : 0); + .push8(FC.VTX_CONFIG.vtx_band) + .push8(FC.VTX_CONFIG.vtx_channel) + .push16(FC.VTX_CONFIG.vtx_frequency) + .push8(FC.VTX_CONFIG.vtx_table_bands) + .push8(FC.VTX_CONFIG.vtx_table_channels) + .push8(FC.VTX_CONFIG.vtx_table_powerlevels) + .push8(FC.VTX_CONFIG.vtx_table_clear ? 1 : 0); } break; @@ -2599,14 +2211,10 @@ MspHelper.prototype.setRawRx = function(channels) { MspHelper.prototype.dataflashRead = function(address, blockSize, onDataCallback) { let outData = [address & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - outData = outData.concat([blockSize & 0xFF, (blockSize >> 8) & 0xFF]); - } + outData = outData.concat([blockSize & 0xFF, (blockSize >> 8) & 0xFF]); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - // Allow compression - outData = outData.concat([1]); - } + // Allow compression + outData = outData.concat([1]); MSP.send_message(MSPCodes.MSP_DATAFLASH_READ, outData, false, function(response) { if (!response.crcError) { @@ -2667,63 +2275,31 @@ MspHelper.prototype.sendServoConfigurations = function(onCompleteCallback) { const buffer = []; - if (semver.lt(FC.CONFIG.apiVersion, "1.12.0")) { - // send all in one go - // 1.9.0 had a bug where the MSP input buffer was too small, limit to 8. - for (let i = 0; i < FC.SERVO_CONFIG.length && i < 8; i++) { - buffer.push16(FC.SERVO_CONFIG[i].min) - .push16(FC.SERVO_CONFIG[i].max) - .push16(FC.SERVO_CONFIG[i].middle) - .push8(FC.SERVO_CONFIG[i].rate); - } - nextFunction = send_channel_forwarding; - } else { - // send one at a time, with index + // send one at a time, with index - const servoConfiguration = FC.SERVO_CONFIG[servoIndex]; + const servoConfiguration = FC.SERVO_CONFIG[servoIndex]; - buffer.push8(servoIndex) - .push16(servoConfiguration.min) - .push16(servoConfiguration.max) - .push16(servoConfiguration.middle) - .push8(servoConfiguration.rate); + buffer.push8(servoIndex) + .push16(servoConfiguration.min) + .push16(servoConfiguration.max) + .push16(servoConfiguration.middle) + .push8(servoConfiguration.rate); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - buffer.push8(servoConfiguration.angleAtMin) - .push8(servoConfiguration.angleAtMax); - } - - let out = servoConfiguration.indexOfChannelToForward; - if (out == undefined) { - out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF" - } - buffer.push8(out) - .push32(servoConfiguration.reversedInputSources); - - // prepare for next iteration - servoIndex++; - if (servoIndex == FC.SERVO_CONFIG.length) { - nextFunction = onCompleteCallback; - } + let out = servoConfiguration.indexOfChannelToForward; + if (out == undefined) { + out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF" } + buffer.push8(out) + .push32(servoConfiguration.reversedInputSources); + + // prepare for next iteration + servoIndex++; + if (servoIndex == FC.SERVO_CONFIG.length) { + nextFunction = onCompleteCallback; + } + MSP.send_message(MSPCodes.MSP_SET_SERVO_CONFIGURATION, buffer, false, nextFunction); } - - function send_channel_forwarding() { - const buffer = []; - - for (let i = 0; i < FC.SERVO_CONFIG.length; i++) { - let out = FC.SERVO_CONFIG[i].indexOfChannelToForward; - if (out == undefined) { - out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF" - } - buffer.push8(out); - } - - nextFunction = onCompleteCallback; - - MSP.send_message(MSPCodes.MSP_SET_CHANNEL_FORWARDING, buffer, false, nextFunction); - } }; MspHelper.prototype.sendModeRanges = function(onCompleteCallback) { @@ -2748,12 +2324,10 @@ MspHelper.prototype.sendModeRanges = function(onCompleteCallback) { .push8((modeRange.range.start - 900) / 25) .push8((modeRange.range.end - 900) / 25); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - const modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; + const modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; - buffer.push8(modeRangeExtra.modeLogic) - .push8(modeRangeExtra.linkedTo); - } + buffer.push8(modeRangeExtra.modeLogic) + .push8(modeRangeExtra.linkedTo); // prepare for next iteration modeRangeIndex++; @@ -2879,67 +2453,39 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { buffer.push(ledIndex); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit + let mask = 0; + + mask |= (led.y << 0); + mask |= (led.x << 4); + + for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { + const fnIndex = ledBaseFunctionLetters.indexOf(led.functions[functionLetterIndex]); + if (fnIndex >= 0) { + mask |= (fnIndex << 8); + break; + } } - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - let directionMask = 0; - for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { - const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); - if (bitIndex >= 0) { - directionMask = bit_set(directionMask, bitIndex); - } + for (let overlayLetterIndex = 0; overlayLetterIndex < led.functions.length; overlayLetterIndex++) { + const bitIndex = ledOverlayLetters.indexOf(led.functions[overlayLetterIndex]); + if (bitIndex >= 0) { + mask |= bit_set(mask, bitIndex + 12); } - buffer.push16(directionMask); - - let functionMask = 0; - for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { - const bitIndex = ledFunctionLetters.indexOf(led.functions[functionLetterIndex]); - if (bitIndex >= 0) { - functionMask = bit_set(functionMask, bitIndex); - } - } - buffer.push16(functionMask) - - .push8(led.x) - .push8(led.y) - .push8(led.color); - } else { - let mask = 0; - - mask |= (led.y << 0); - mask |= (led.x << 4); - - for (let functionLetterIndex = 0; functionLetterIndex < led.functions.length; functionLetterIndex++) { - const fnIndex = ledBaseFunctionLetters.indexOf(led.functions[functionLetterIndex]); - if (fnIndex >= 0) { - mask |= (fnIndex << 8); - break; - } - } - - for (let overlayLetterIndex = 0; overlayLetterIndex < led.functions.length; overlayLetterIndex++) { - const bitIndex = ledOverlayLetters.indexOf(led.functions[overlayLetterIndex]); - if (bitIndex >= 0) { - mask |= bit_set(mask, bitIndex + 12); - } - } - - mask |= (led.color << 18); - - for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { - const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); - if (bitIndex >= 0) { - mask |= bit_set(mask, bitIndex + 22); - } - } - - mask |= (0 << 28); // parameters - - buffer.push32(mask); } + mask |= (led.color << 18); + + for (let directionLetterIndex = 0; directionLetterIndex < led.directions.length; directionLetterIndex++) { + const bitIndex = ledDirectionLetters.indexOf(led.directions[directionLetterIndex]); + if (bitIndex >= 0) { + mask |= bit_set(mask, bitIndex + 22); + } + } + + mask |= (0 << 28); // parameters + + buffer.push32(mask); + // prepare for next iteration ledIndex++; if (ledIndex == FC.LED_STRIP.length) { @@ -3056,8 +2602,7 @@ MspHelper.prototype.sendRxFailConfig = function(onCompleteCallback) { }; MspHelper.prototype.setArmingEnabled = function(doEnable, disableRunawayTakeoffPrevention, onCompleteCallback) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37) - && (FC.CONFIG.armingDisabled === doEnable || FC.CONFIG.runawayTakeoffPreventionDisabled !== disableRunawayTakeoffPrevention)) { + if (FC.CONFIG.armingDisabled === doEnable || FC.CONFIG.runawayTakeoffPreventionDisabled !== disableRunawayTakeoffPrevention) { FC.CONFIG.armingDisabled = !doEnable; FC.CONFIG.runawayTakeoffPreventionDisabled = disableRunawayTakeoffPrevention; diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 3bb9fb92..cf848024 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -445,11 +445,7 @@ function processUid() { connectionTimestamp = Date.now(); GUI.log(i18n.getMessage('uniqueDeviceIdReceived', [uniqueDeviceIdentifier])); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - processCraftName(); - } else { - setRtc(); - } + processCraftName(); }); } @@ -471,19 +467,12 @@ async function processCraftName() { } function setRtc() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - MSP.send_message(MSPCodes.MSP_SET_RTC, mspHelper.crunch(MSPCodes.MSP_SET_RTC), false, finishOpen); - } else { - finishOpen(); - } + MSP.send_message(MSPCodes.MSP_SET_RTC, mspHelper.crunch(MSPCodes.MSP_SET_RTC), false, finishOpen); } function finishOpen() { CONFIGURATOR.connectionValid = true; GUI.allowedTabs = GUI.defaultAllowedFCTabsWhenConnected.slice(); - if (semver.lt(FC.CONFIG.apiVersion, "1.4.0")) { - GUI.allowedTabs.splice(GUI.allowedTabs.indexOf('led_strip'), 1); - } if (GUI.isCordova()) { UI_PHONES.reset(); @@ -689,11 +678,7 @@ function have_sensor(sensors_detected, sensor_code) { case 'sonar': return bit_check(sensors_detected, 4); case 'gyro': - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - return bit_check(sensors_detected, 5); - } else { - return true; - } + return bit_check(sensors_detected, 5); } return false; } @@ -704,11 +689,7 @@ function startLiveDataRefreshTimer() { } async function getStatus() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_32)) { - return MSP.promise(MSPCodes.MSP_STATUS_EX); - } else { - return MSP.promise(MSPCodes.MSP_STATUS); - } + return MSP.promise(MSPCodes.MSP_STATUS_EX); } async function update_live_status() { diff --git a/src/js/tabs/adjustments.js b/src/js/tabs/adjustments.js index ffb146bd..6b9e7abb 100644 --- a/src/js/tabs/adjustments.js +++ b/src/js/tabs/adjustments.js @@ -289,38 +289,24 @@ adjustments.cleanup = function (callback) { adjustments.adjust_template = function () { const selectFunction = $('#functionSelectionSelect'); - let elementsNumber; - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - elementsNumber = 31; // OSD Profile Select & LED Profile Select - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - elementsNumber = 29; // PID Audio - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - elementsNumber = 26; // PID Audio - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - elementsNumber = 25; // Horizon Strength - } else { - elementsNumber = 24; // Setpoint transition - } + const elementsNumber = 31; // OSD Profile Select & LED Profile Select for (let i = 0; i < elementsNumber; i++) { selectFunction.append(new Option(i18n.getMessage(`adjustmentsFunction${i}`), i)); } // For 1.40, the D Setpoint has been replaced, so we replace it with the correct values - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - const element22 = selectFunction.find("option[value='22']"); - const element23 = selectFunction.find("option[value='23']"); + const element22 = selectFunction.find("option[value='22']"); + const element23 = selectFunction.find("option[value='23']"); - // Change the "text" - element22.text(i18n.getMessage('adjustmentsFunction22_2')); - element23.text(i18n.getMessage('adjustmentsFunction23_2')); + // Change the "text" + element22.text(i18n.getMessage('adjustmentsFunction22_2')); + element23.text(i18n.getMessage('adjustmentsFunction23_2')); - // Reorder, we insert it with the other FF elements to be coherent... - element22.insertAfter(selectFunction.find("option[value='25']")); - element23.insertAfter(selectFunction.find("option[value='28']")); - } + // Reorder, we insert it with the other FF elements to be coherent... + element22.insertAfter(selectFunction.find("option[value='25']")); + element23.insertAfter(selectFunction.find("option[value='28']")); }; window.TABS.adjustments = adjustments; diff --git a/src/js/tabs/auxiliary.js b/src/js/tabs/auxiliary.js index d80ed11a..3d9a1cc5 100644 --- a/src/js/tabs/auxiliary.js +++ b/src/js/tabs/auxiliary.js @@ -8,8 +8,7 @@ auxiliary.initialize = function (callback) { let prevChannelsValues = null; function get_mode_ranges() { - MSP.send_message(MSPCodes.MSP_MODE_RANGES, false, false, - semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41) ? get_mode_ranges_extra : get_box_ids); + MSP.send_message(MSPCodes.MSP_MODE_RANGES, false, false, get_mode_ranges_extra); } function get_mode_ranges_extra() { @@ -57,7 +56,7 @@ auxiliary.initialize = function (callback) { $(newMode).find('a.addLink').data('modeElement', newMode); // hide link button for ARM - if (modeId == 0 || semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { + if (modeId == 0) { $(newMode).find('.addLink').hide(); } @@ -75,12 +74,11 @@ auxiliary.initialize = function (callback) { logicOption.val(0); logicList.append(logicOption); - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)){ - logicOption = logicOptionTemplate.clone(); - logicOption.text(i18n.getMessage('auxiliaryModeLogicAND')); - logicOption.val(1); - logicList.append(logicOption); - } + logicOption = logicOptionTemplate.clone(); + logicOption.text(i18n.getMessage('auxiliaryModeLogicAND')); + logicOption.val(1); + logicList.append(logicOption); + logicOptionTemplate.val(0); } @@ -265,15 +263,7 @@ auxiliary.initialize = function (callback) { // skip linked modes for now for (let modeRangeIndex = 0; modeRangeIndex < FC.MODE_RANGES.length; modeRangeIndex++) { const modeRange = FC.MODE_RANGES[modeRangeIndex]; - - let modeRangeExtra = { - id: modeRange.id, - modeLogic: 0, - linkedTo: 0, - }; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; - } + const modeRangeExtra = FC.MODE_RANGES_EXTRA[modeRangeIndex]; if (modeRange.id != modeId || modeRangeExtra.id != modeId) { continue; @@ -454,13 +444,11 @@ auxiliary.initialize = function (callback) { if (i == 0) { let armSwitchActive = false; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - if (FC.CONFIG.armingDisableCount > 0) { - // check the highest bit of the armingDisableFlags. This will be the ARMING_DISABLED_ARMSWITCH flag. - const armSwitchMask = 1 << (FC.CONFIG.armingDisableCount - 1); - if ((FC.CONFIG.armingDisableFlags & armSwitchMask) > 0) { - armSwitchActive = true; - } + if (FC.CONFIG.armingDisableCount > 0) { + // check the highest bit of the armingDisableFlags. This will be the ARMING_DISABLED_ARMSWITCH flag. + const armSwitchMask = 1 << (FC.CONFIG.armingDisableCount - 1); + if ((FC.CONFIG.armingDisableFlags & armSwitchMask) > 0) { + armSwitchActive = true; } } diff --git a/src/js/tabs/configuration.js b/src/js/tabs/configuration.js index 517bfb89..e74e84c3 100644 --- a/src/js/tabs/configuration.js +++ b/src/js/tabs/configuration.js @@ -20,27 +20,26 @@ configuration.initialize = function (callback) { function load_config() { Promise .resolve(true) - .then(() => { return MSP.promise(MSPCodes.MSP_FEATURE_CONFIG); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36) ? MSP.promise(MSPCodes.MSP_BEEPER_CONFIG) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33) ? MSP.promise(MSPCodes.MSP_GPS_CONFIG) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_ACC_TRIM); }) - .then(() => { return semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_33) ? MSP.promise(MSPCodes.MSP_MISC) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.8.0") ? MSP.promise(MSPCodes.MSP_ARMING_CONFIG) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.17.0") ? MSP.promise(MSPCodes.MSP_RC_DEADBAND) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.16.0") ? MSP.promise(MSPCodes.MSP_SENSOR_CONFIG) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.15.0") ? MSP.promise(MSPCodes.MSP_SENSOR_ALIGNMENT) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.20.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) + .then(() => MSP.promise(MSPCodes.MSP_FEATURE_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_BEEPER_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_GPS_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_ACC_TRIM)) + .then(() => MSP.promise(MSPCodes.MSP_ARMING_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_RC_DEADBAND)) + .then(() => MSP.promise(MSPCodes.MSP_SENSOR_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_SENSOR_ALIGNMENT)) + .then(() => semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) ? MSP.promise(MSPCodes.MSP_NAME) - : Promise.resolve(true); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) + : Promise.resolve(true)) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME)) - : Promise.resolve(true); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31) ? MSP.promise(MSPCodes.MSP_RX_CONFIG) : true; }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) - ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); }) - .then(() => { return MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG); }) - .then(() => { load_html(); }); + : Promise.resolve(true)) + .then(() => MSP.promise(MSPCodes.MSP_RX_CONFIG)) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) + ? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true)) + .then(() => MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG)) + .then(() => load_html()); } function load_html() { @@ -58,20 +57,14 @@ configuration.initialize = function (callback) { // Dshot Beeper const dshotBeeper_e = $('.tab-configuration .dshotbeeper'); - const dshotBeacon_e = $('.tab-configuration .dshotbeacon'); - const dshotBeeperSwitch = $('#dshotBeeperSwitch'); const dshotBeeperBeaconTone = $('select.dshotBeeperBeaconTone'); const dshotBeaconCondition_e = $('tbody.dshotBeaconConditions'); const dshotBeaconSwitch_e = $('tr.dshotBeaconSwitch'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - for (let i = 1; i <= 5; i++) { - dshotBeeperBeaconTone.append(``); - } - dshotBeeper_e.show(); - } else { - dshotBeeper_e.hide(); + for (let i = 1; i <= 5; i++) { + dshotBeeperBeaconTone.append(``); } + dshotBeeper_e.show(); dshotBeeperBeaconTone.change(function() { FC.BEEPER_CONFIG.dshotBeaconTone = dshotBeeperBeaconTone.val(); @@ -80,41 +73,19 @@ configuration.initialize = function (callback) { dshotBeeperBeaconTone.val(FC.BEEPER_CONFIG.dshotBeaconTone); const template = $('.beepers .beeper-template'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - dshotBeaconSwitch_e.hide(); - FC.BEEPER_CONFIG.dshotBeaconConditions.generateElements(template, dshotBeaconCondition_e); + dshotBeaconSwitch_e.hide(); + FC.BEEPER_CONFIG.dshotBeaconConditions.generateElements(template, dshotBeaconCondition_e); - $('input.condition', dshotBeaconCondition_e).change(function () { - const element = $(this); - FC.BEEPER_CONFIG.dshotBeaconConditions.updateData(element); - }); - } else { - dshotBeaconCondition_e.hide(); - - dshotBeeperSwitch.change(function() { - if ($(this).is(':checked')) { - dshotBeacon_e.show(); - if (dshotBeeperBeaconTone.val() == 0) { - dshotBeeperBeaconTone.val(1).change(); - } - } else { - dshotBeeperBeaconTone.val(0).change(); - dshotBeacon_e.hide(); - } - }); - - dshotBeeperSwitch.prop('checked', FC.BEEPER_CONFIG.dshotBeaconTone !== 0).change(); - } + $('input.condition', dshotBeaconCondition_e).change(function () { + const element = $(this); + FC.BEEPER_CONFIG.dshotBeaconConditions.updateData(element); + }); // Analog Beeper const destination = $('.beepers .beeper-configuration'); const beeper_e = $('.tab-configuration .beepers'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.BEEPER_CONFIG.beepers.generateElements(template, destination); - } else { - beeper_e.hide(); - } + FC.BEEPER_CONFIG.beepers.generateElements(template, destination); // translate to user-selected language i18n.localizePage(); @@ -147,125 +118,117 @@ configuration.initialize = function (callback) { const orientation_gyro_2_align_e = $('select.gyro_2_align'); gyro_align_content_e.hide(); // default value - if (semver.lt(FC.CONFIG.apiVersion, "1.15.0")) { - $('.tab-configuration .sensoralignment').hide(); - } else { - - for (let i = 0; i < alignments.length; i++) { - orientation_gyro_e.append(``); - orientation_acc_e.append(``); - orientation_mag_e.append(``); - } - - orientation_gyro_e.val(FC.SENSOR_ALIGNMENT.align_gyro); - orientation_acc_e.val(FC.SENSOR_ALIGNMENT.align_acc); - orientation_mag_e.val(FC.SENSOR_ALIGNMENT.align_mag); - - orientation_gyro_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.align_gyro) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['GyroAlignment'] = newValue; - - FC.SENSOR_ALIGNMENT.align_gyro = value; - }); - - orientation_acc_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.align_acc) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['AccAlignment'] = newValue; - - FC.SENSOR_ALIGNMENT.align_acc = value; - }); - - orientation_mag_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.align_mag) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['MagAlignment'] = newValue; - - FC.SENSOR_ALIGNMENT.align_mag = value; - }); - - // Multi gyro config - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - - gyro_align_content_e.show(); - legacy_gyro_alignment_e.hide(); - legacy_accel_alignment_e.hide(); - - const GYRO_DETECTION_FLAGS = { - DETECTED_GYRO_1: (1 << 0), - DETECTED_GYRO_2: (1 << 1), - DETECTED_DUAL_GYROS: (1 << 7), - }; - - const detected_gyro_1 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_1) != 0; - const detected_gyro_2 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_2) != 0; - const detected_dual_gyros = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_DUAL_GYROS) != 0; - - if (detected_gyro_1) { - orientation_gyro_to_use_e.append(``); - } - if (detected_gyro_2) { - orientation_gyro_to_use_e.append(``); - } - if (detected_dual_gyros) { - orientation_gyro_to_use_e.append(``); - } - - for (let i = 0; i < alignments.length; i++) { - orientation_gyro_1_align_e.append(``); - orientation_gyro_2_align_e.append(``); - } - - orientation_gyro_to_use_e.val(FC.SENSOR_ALIGNMENT.gyro_to_use); - orientation_gyro_1_align_e.val(FC.SENSOR_ALIGNMENT.gyro_1_align); - orientation_gyro_2_align_e.val(FC.SENSOR_ALIGNMENT.gyro_2_align); - - $('.gyro_alignment_inputs_first').toggle(detected_gyro_1); - $('.gyro_alignment_inputs_second').toggle(detected_gyro_2); - $('.gyro_alignment_inputs_selection').toggle(detected_gyro_1 || detected_gyro_2); - $('.gyro_alignment_inputs_notfound').toggle(!detected_gyro_1 && !detected_gyro_2); - - orientation_gyro_1_align_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.gyro_1_align) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['Gyro1Alignment'] = newValue; - - FC.SENSOR_ALIGNMENT.gyro_1_align = value; - }); - - orientation_gyro_2_align_e.change(function () { - let value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.SENSOR_ALIGNMENT.gyro_2_align) { - newValue = $(this).find('option:selected').text(); - } - self.analyticsChanges['Gyro2Alignment'] = newValue; - - FC.SENSOR_ALIGNMENT.gyro_2_align = value; - }); - } + for (let i = 0; i < alignments.length; i++) { + orientation_gyro_e.append(``); + orientation_acc_e.append(``); + orientation_mag_e.append(``); } + orientation_gyro_e.val(FC.SENSOR_ALIGNMENT.align_gyro); + orientation_acc_e.val(FC.SENSOR_ALIGNMENT.align_acc); + orientation_mag_e.val(FC.SENSOR_ALIGNMENT.align_mag); + + orientation_gyro_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.align_gyro) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['GyroAlignment'] = newValue; + + FC.SENSOR_ALIGNMENT.align_gyro = value; + }); + + orientation_acc_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.align_acc) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['AccAlignment'] = newValue; + + FC.SENSOR_ALIGNMENT.align_acc = value; + }); + + orientation_mag_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.align_mag) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['MagAlignment'] = newValue; + + FC.SENSOR_ALIGNMENT.align_mag = value; + }); + + // Multi gyro config + + gyro_align_content_e.show(); + legacy_gyro_alignment_e.hide(); + legacy_accel_alignment_e.hide(); + + const GYRO_DETECTION_FLAGS = { + DETECTED_GYRO_1: (1 << 0), + DETECTED_GYRO_2: (1 << 1), + DETECTED_DUAL_GYROS: (1 << 7), + }; + + const detected_gyro_1 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_1) != 0; + const detected_gyro_2 = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_GYRO_2) != 0; + const detected_dual_gyros = (FC.SENSOR_ALIGNMENT.gyro_detection_flags & GYRO_DETECTION_FLAGS.DETECTED_DUAL_GYROS) != 0; + + if (detected_gyro_1) { + orientation_gyro_to_use_e.append(``); + } + if (detected_gyro_2) { + orientation_gyro_to_use_e.append(``); + } + if (detected_dual_gyros) { + orientation_gyro_to_use_e.append(``); + } + + for (let i = 0; i < alignments.length; i++) { + orientation_gyro_1_align_e.append(``); + orientation_gyro_2_align_e.append(``); + } + + orientation_gyro_to_use_e.val(FC.SENSOR_ALIGNMENT.gyro_to_use); + orientation_gyro_1_align_e.val(FC.SENSOR_ALIGNMENT.gyro_1_align); + orientation_gyro_2_align_e.val(FC.SENSOR_ALIGNMENT.gyro_2_align); + + $('.gyro_alignment_inputs_first').toggle(detected_gyro_1); + $('.gyro_alignment_inputs_second').toggle(detected_gyro_2); + $('.gyro_alignment_inputs_selection').toggle(detected_gyro_1 || detected_gyro_2); + $('.gyro_alignment_inputs_notfound').toggle(!detected_gyro_1 && !detected_gyro_2); + + orientation_gyro_1_align_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.gyro_1_align) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['Gyro1Alignment'] = newValue; + + FC.SENSOR_ALIGNMENT.gyro_1_align = value; + }); + + orientation_gyro_2_align_e.change(function () { + let value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.SENSOR_ALIGNMENT.gyro_2_align) { + newValue = $(this).find('option:selected').text(); + } + self.analyticsChanges['Gyro2Alignment'] = newValue; + + FC.SENSOR_ALIGNMENT.gyro_2_align = value; + }); + // Gyro and PID update - const gyroUse32kHzElement = $('input[id="gyroUse32kHz"]'); const gyroTextElement = $('input.gyroFrequency'); const gyroSelectElement = $('select.gyroSyncDenom'); const pidSelectElement = $('select.pidProcessDenom'); @@ -288,7 +251,7 @@ configuration.initialize = function (callback) { gyroSelectElement.empty(); - const MAX_DENOM = semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41) ? 32 : 8; + const MAX_DENOM = 8; for (let denom = 1; denom <= MAX_DENOM; denom++) { addDenomOption(gyroSelectElement, denom, gyroBaseFreq); @@ -311,24 +274,12 @@ configuration.initialize = function (callback) { gyroTextElement.val(gyroContent); }; - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gyroUse32kHzElement.prop('checked', FC.PID_ADVANCED_CONFIG.gyroUse32kHz !== 0); + $('div.gyroUse32kHz').hide(); - gyroUse32kHzElement.change(function () { - const gyroBaseFreq = ($(this).is(':checked'))? 32 : 8; - - updateGyroDenom(gyroBaseFreq); - }).change(); - - } else { - - $('div.gyroUse32kHz').hide(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - updateGyroDenomReadOnly(FC.CONFIG.sampleRateHz); - } else { - updateGyroDenom(8); - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + updateGyroDenomReadOnly(FC.CONFIG.sampleRateHz); + } else { + updateGyroDenom(8); } gyroSelectElement.val(FC.PID_ADVANCED_CONFIG.gyro_sync_denom); @@ -343,15 +294,12 @@ configuration.initialize = function (callback) { pidBaseFreq = FC.CONFIG.sampleRateHz / 1000; } else { pidBaseFreq = 8; - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41) && gyroUse32kHzElement.is(':checked')) { - pidBaseFreq = 32; - } - pidBaseFreq = pidBaseFreq / parseInt($(this).val()); + pidBaseFreq /= parseInt($(this).val()); } pidSelectElement.empty(); - const MAX_DENOM = semver.gte(FC.CONFIG.apiVersion, "1.24.0") ? 16 : 8; + const MAX_DENOM = 8; for (let denom = 1; denom <= MAX_DENOM; denom++) { addDenomOption(pidSelectElement, denom, pidBaseFreq); @@ -367,14 +315,6 @@ configuration.initialize = function (callback) { $('input[id="magHardwareSwitch"]').prop('checked', FC.SENSOR_CONFIG.mag_hardware !== 1); // Only show these sections for supported FW - if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) { - $('.selectPidProcessDenom').hide(); - } - - if (semver.lt(FC.CONFIG.apiVersion, "1.16.0")) { - $('.hardwareSelection').hide(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { $('input[name="craftName"]').val(FC.CONFIG.craftName); $('input[name="pilotName"]').val(FC.CONFIG.pilotName); @@ -383,27 +323,15 @@ configuration.initialize = function (callback) { $('.pilotName').hide(); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - $('input[name="fpvCamAngleDegrees"]').val(FC.RX_CONFIG.fpvCamAngleDegrees); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - $('input[name="fpvCamAngleDegrees"]').attr("max", 90); - } - } else { - $('div.fpvCamAngleDegrees').hide(); - } - - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - $('.miscSettings').hide(); - } + $('input[name="fpvCamAngleDegrees"]').val(FC.RX_CONFIG.fpvCamAngleDegrees); + $('input[name="fpvCamAngleDegrees"]').attr("max", 90); // generate GPS const gpsProtocols = [ 'NMEA', 'UBLOX', + 'MSP', ]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - gpsProtocols.push('MSP'); - } const gpsBaudRates = [ '115200', @@ -464,13 +392,8 @@ configuration.initialize = function (callback) { }).prop('checked', FC.GPS_CONFIG.auto_config === 1).change(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - gpsAutoBaudGroup.show(); - gpsAutoConfigGroup.show(); - } else { - gpsAutoBaudGroup.hide(); - gpsAutoConfigGroup.hide(); - } + gpsAutoBaudGroup.show(); + gpsAutoConfigGroup.show(); gpsUbloxGalileoElement.change(function() { FC.GPS_CONFIG.ublox_use_galileo = $(this).is(':checked') ? 1 : 0; @@ -493,15 +416,8 @@ configuration.initialize = function (callback) { gpsBaudrateElement.append(``); } - if (semver.lt(FC.CONFIG.apiVersion, "1.6.0")) { - gpsBaudrateElement.change(function () { - FC.SERIAL_CONFIG.gpsBaudRate = parseInt($(this).val()); - }); - gpsBaudrateElement.val(FC.SERIAL_CONFIG.gpsBaudRate); - } else { - gpsBaudrateElement.prop("disabled", true); - gpsBaudrateElement.parent().hide(); - } + gpsBaudrateElement.prop("disabled", true); + gpsBaudrateElement.parent().hide(); // fill board alignment $('input[name="board_align_roll"]').val(FC.BOARD_ALIGNMENT_CONFIG.roll); @@ -512,10 +428,8 @@ configuration.initialize = function (callback) { $('input[name="roll"]').val(FC.CONFIG.accelerometerTrims[1]); $('input[name="pitch"]').val(FC.CONFIG.accelerometerTrims[0]); - $('._smallAngle').toggle(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)); - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - $('input[id="configurationSmallAngle"]').val(FC.ARMING_CONFIG.small_angle); - } + $('._smallAngle').show(); + $('input[id="configurationSmallAngle"]').val(FC.ARMING_CONFIG.small_angle); // UI hooks @@ -539,10 +453,8 @@ configuration.initialize = function (callback) { }); $('input[id="accHardwareSwitch"]').change(function() { - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - const checked = $(this).is(':checked'); - $('.accelNeeded').toggle(checked); - } + const checked = $(this).is(':checked'); + $('.accelNeeded').toggle(checked); }).change(); $(features_e).filter('select').change(function () { @@ -569,13 +481,9 @@ configuration.initialize = function (callback) { FC.CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val()); // small angle configuration - if(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - FC.ARMING_CONFIG.small_angle = parseInt($('input[id="configurationSmallAngle"]').val()); - } + FC.ARMING_CONFIG.small_angle = parseInt($('input[id="configurationSmallAngle"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.SENSOR_ALIGNMENT.gyro_to_use = parseInt(orientation_gyro_to_use_e.val()); - } + FC.SENSOR_ALIGNMENT.gyro_to_use = parseInt(orientation_gyro_to_use_e.val()); FC.PID_ADVANCED_CONFIG.gyro_sync_denom = parseInt(gyroSelectElement.val()); @@ -589,9 +497,6 @@ configuration.initialize = function (callback) { } FC.PID_ADVANCED_CONFIG.pid_process_denom = value; - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.PID_ADVANCED_CONFIG.gyroUse32kHz = $('input[id="gyroUse32kHz"]').is(':checked') ? 1 : 0; - } FC.RX_CONFIG.fpvCamAngleDegrees = parseInt($('input[name="fpvCamAngleDegrees"]').val()); @@ -599,10 +504,8 @@ configuration.initialize = function (callback) { self.analyticsChanges = {}; // fill some data - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_34)) { - FC.GPS_CONFIG.auto_baud = $('input[name="gps_auto_baud"]').is(':checked') ? 1 : 0; - FC.GPS_CONFIG.auto_config = $('input[name="gps_auto_config"]').is(':checked') ? 1 : 0; - } + FC.GPS_CONFIG.auto_baud = $('input[name="gps_auto_baud"]').is(':checked') ? 1 : 0; + FC.GPS_CONFIG.auto_config = $('input[name="gps_auto_config"]').is(':checked') ? 1 : 0; FC.SENSOR_CONFIG.acc_hardware = $('input[id="accHardwareSwitch"]').is(':checked') ? 0 : 1; FC.SENSOR_CONFIG.baro_hardware = $('input[id="baroHardwareSwitch"]').is(':checked') ? 0 : 1; @@ -621,28 +524,24 @@ configuration.initialize = function (callback) { function save_config() { Promise .resolve(true) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG)); }) - .then(() => { return (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) ? - MSP.promise(MSPCodes.MSP_SET_BEEPER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BEEPER_CONFIG)) : true; }) - .then(() => { return (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_33)) ? - MSP.promise(MSPCodes.MSP_SET_MISC, mspHelper.crunch(MSPCodes.MSP_SET_MISC)) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG)); }) - .then(() => { return (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) ? - MSP.promise(MSPCodes.MSP_SET_GPS_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_GPS_CONFIG)) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_RC_DEADBAND, mspHelper.crunch(MSPCodes.MSP_SET_RC_DEADBAND)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_SENSOR_ALIGNMENT, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_ALIGNMENT)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_ADVANCED_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ADVANCED_CONFIG)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_ACC_TRIM, mspHelper.crunch(MSPCodes.MSP_SET_ACC_TRIM)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG)); }) - .then(() => { return MSP.promise(MSPCodes.MSP_SET_SENSOR_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_CONFIG)); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) + .then(() => MSP.promise(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_BEEPER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BEEPER_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BOARD_ALIGNMENT_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_GPS_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_GPS_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_RC_DEADBAND, mspHelper.crunch(MSPCodes.MSP_SET_RC_DEADBAND))) + .then(() => MSP.promise(MSPCodes.MSP_SET_SENSOR_ALIGNMENT, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_ALIGNMENT))) + .then(() => MSP.promise(MSPCodes.MSP_SET_ADVANCED_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ADVANCED_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_ACC_TRIM, mspHelper.crunch(MSPCodes.MSP_SET_ACC_TRIM))) + .then(() => MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_SET_SENSOR_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_CONFIG))) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.CRAFT_NAME)) - : MSP.promise(MSPCodes.MSP_SET_NAME, mspHelper.crunch(MSPCodes.MSP_SET_NAME)); }) - .then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? - MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); }) - .then(() => { return (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) ? MSP.promise(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG)) : true; }) - .then(() => { return MSP.promise(MSPCodes.MSP_EEPROM_WRITE); }) - .then(() => { reboot(); }); + : MSP.promise(MSPCodes.MSP_SET_NAME, mspHelper.crunch(MSPCodes.MSP_SET_NAME))) + .then(() => semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? + MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true)) + .then(() => MSP.promise(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG))) + .then(() => MSP.promise(MSPCodes.MSP_EEPROM_WRITE)) + .then(() => reboot()); } function reboot() { diff --git a/src/js/tabs/failsafe.js b/src/js/tabs/failsafe.js index 3952f003..02e5f41b 100644 --- a/src/js/tabs/failsafe.js +++ b/src/js/tabs/failsafe.js @@ -17,8 +17,7 @@ failsafe.initialize = function (callback) { } function load_rxfail_config() { - MSP.send_message(MSPCodes.MSP_RXFAIL_CONFIG, false, false, - semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41) ? load_gps_rescue : get_box_names); + MSP.send_message(MSPCodes.MSP_RXFAIL_CONFIG, false, false, load_gps_rescue); } function load_gps_rescue() { @@ -134,37 +133,21 @@ failsafe.initialize = function (callback) { for (let i = 0; i < FC.RXFAIL_CONFIG.length; i++) { if (i < channelNames.length) { - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - fullChannels_e.append(`\ -
\ -
\ - ${channelNames[i]}\ -
\ -
\ - \ -
\ + fullChannels_e.append(`\ +
\ +
\ + ${channelNames[i]}\
\ - `); - } else { - fullChannels_e.append(`\ -
\ -
\ - ${channelNames[i]}\ -
\ -
\ - \ -
\ -
\ +
\ + \
\ - `); - } +
\ +
\ + `); } else { const messageKey = `controlAxisAux${aux_index++}`; fullChannels_e.append(`\ @@ -231,16 +214,8 @@ failsafe.initialize = function (callback) { FC.FEATURE_CONFIG.features.generateElements($('.tab-failsafe .featuresNew')); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - $('tbody.rxFailsafe').hide(); - toggleStage2(true); - } else { - const failsafeFeature = $('input[name="FAILSAFE"]'); - failsafeFeature.change(function () { - toggleStage2($(this).is(':checked')); - }); - toggleStage2(FC.FEATURE_CONFIG.features.isEnabled('FAILSAFE')); - } + $('tbody.rxFailsafe').hide(); + toggleStage2(true); $('input[name="failsafe_throttle"]').val(FC.FAILSAFE_CONFIG.failsafe_throttle); $('input[name="failsafe_off_delay"]').val((FC.FAILSAFE_CONFIG.failsafe_off_delay / 10.0).toFixed(1)); @@ -273,66 +248,45 @@ failsafe.initialize = function (callback) { break; } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - // `failsafe_kill_switch` has been renamed to `failsafe_switch_mode`. - // It is backwards compatible with `failsafe_kill_switch` - $('select[name="failsafe_switch_mode"]').val(FC.FAILSAFE_CONFIG.failsafe_switch_mode); - $('div.kill_switch').hide(); - } - else { - $('input[name="failsafe_kill_switch"]').prop('checked', FC.FAILSAFE_CONFIG.failsafe_switch_mode); - $('div.failsafe_switch').hide(); - } + // `failsafe_kill_switch` has been renamed to `failsafe_switch_mode`. + // It is backwards compatible with `failsafe_kill_switch` + $('select[name="failsafe_switch_mode"]').val(FC.FAILSAFE_CONFIG.failsafe_switch_mode); + $('div.kill_switch').hide(); // The GPS Rescue tab is only available for 1.40 or later, and the parameters for 1.41 - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - // Load GPS Rescue parameters - $('input[name="gps_rescue_angle"]').val(FC.GPS_RESCUE.angle); - $('input[name="gps_rescue_initial_altitude"]').val(FC.GPS_RESCUE.initialAltitudeM); - $('input[name="gps_rescue_descent_distance"]').val(FC.GPS_RESCUE.descentDistanceM); - $('input[name="gps_rescue_ground_speed"]').val((FC.GPS_RESCUE.rescueGroundspeed / 100).toFixed(2)); - $('input[name="gps_rescue_throttle_min"]').val(FC.GPS_RESCUE.throttleMin); - $('input[name="gps_rescue_throttle_max"]').val(FC.GPS_RESCUE.throttleMax); - $('input[name="gps_rescue_throttle_hover"]').val(FC.GPS_RESCUE.throttleHover); - $('input[name="gps_rescue_min_sats"]').val(FC.GPS_RESCUE.minSats); - $('select[name="gps_rescue_sanity_checks"]').val(FC.GPS_RESCUE.sanityChecks); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - $('input[name="gps_rescue_ascend_rate"]').val((FC.GPS_RESCUE.ascendRate / 100).toFixed(2)); - $('input[name="gps_rescue_descend_rate"]').val((FC.GPS_RESCUE.descendRate / 100).toFixed(2)); - $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked', FC.GPS_RESCUE.allowArmingWithoutFix > 0); - $('select[name="gps_rescue_altitude_mode"]').val(FC.GPS_RESCUE.altitudeMode); - } else { - $('input[name="gps_rescue_ascend_rate"]').closest('.number').hide(); - $('input[name="gps_rescue_descend_rate"]').closest('.number').hide(); - $('input[name="gps_rescue_allow_arming_without_fix"]').closest('.number').hide(); - $('select[name="gps_rescue_altitude_mode"]').closest('.number').hide(); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - $('input[name="gps_rescue_min_dth"]').val(FC.GPS_RESCUE.minRescueDth); - } else { - $('input[name="gps_rescue_min_dth"]').closest('.number').hide(); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - $('input[name="gps_rescue_min_dth"]').attr("min", 20); - } - - } else { - // GPS Rescue Parameters not available - $('.pro4 > .proceduresettings').hide(); - } + // Load GPS Rescue parameters + $('input[name="gps_rescue_angle"]').val(FC.GPS_RESCUE.angle); + $('input[name="gps_rescue_initial_altitude"]').val(FC.GPS_RESCUE.initialAltitudeM); + $('input[name="gps_rescue_descent_distance"]').val(FC.GPS_RESCUE.descentDistanceM); + $('input[name="gps_rescue_ground_speed"]').val((FC.GPS_RESCUE.rescueGroundspeed / 100).toFixed(2)); + $('input[name="gps_rescue_throttle_min"]').val(FC.GPS_RESCUE.throttleMin); + $('input[name="gps_rescue_throttle_max"]').val(FC.GPS_RESCUE.throttleMax); + $('input[name="gps_rescue_throttle_hover"]').val(FC.GPS_RESCUE.throttleHover); + $('input[name="gps_rescue_min_sats"]').val(FC.GPS_RESCUE.minSats); + $('select[name="gps_rescue_sanity_checks"]').val(FC.GPS_RESCUE.sanityChecks); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + $('input[name="gps_rescue_ascend_rate"]').val((FC.GPS_RESCUE.ascendRate / 100).toFixed(2)); + $('input[name="gps_rescue_descend_rate"]').val((FC.GPS_RESCUE.descendRate / 100).toFixed(2)); + $('input[name="gps_rescue_allow_arming_without_fix"]').prop('checked', FC.GPS_RESCUE.allowArmingWithoutFix > 0); + $('select[name="gps_rescue_altitude_mode"]').val(FC.GPS_RESCUE.altitudeMode); } else { - // GPS Rescue option not available - $('.pro4').hide(); + $('input[name="gps_rescue_ascend_rate"]').closest('.number').hide(); + $('input[name="gps_rescue_descend_rate"]').closest('.number').hide(); + $('input[name="gps_rescue_allow_arming_without_fix"]').closest('.number').hide(); + $('select[name="gps_rescue_altitude_mode"]').closest('.number').hide(); } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + $('input[name="gps_rescue_min_dth"]').val(FC.GPS_RESCUE.minRescueDth); + } else { + $('input[name="gps_rescue_min_dth"]').closest('.number').hide(); + } - + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + $('input[name="gps_rescue_min_dth"]').attr("min", 20); + } $('a.save').click(function () { // gather data that doesn't have automatic change event bound @@ -355,25 +309,18 @@ failsafe.initialize = function (callback) { FC.FAILSAFE_CONFIG.failsafe_procedure = 2; } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.FAILSAFE_CONFIG.failsafe_switch_mode = $('select[name="failsafe_switch_mode"]').val(); - } - else { - FC.FAILSAFE_CONFIG.failsafe_switch_mode = $('input[name="failsafe_kill_switch"]').is(':checked') ? 1 : 0; - } + FC.FAILSAFE_CONFIG.failsafe_switch_mode = $('select[name="failsafe_switch_mode"]').val(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - // Load GPS Rescue parameters - FC.GPS_RESCUE.angle = $('input[name="gps_rescue_angle"]').val(); - FC.GPS_RESCUE.initialAltitudeM = $('input[name="gps_rescue_initial_altitude"]').val(); - FC.GPS_RESCUE.descentDistanceM = $('input[name="gps_rescue_descent_distance"]').val(); - FC.GPS_RESCUE.rescueGroundspeed = $('input[name="gps_rescue_ground_speed"]').val() * 100; - FC.GPS_RESCUE.throttleMin = $('input[name="gps_rescue_throttle_min"]').val(); - FC.GPS_RESCUE.throttleMax = $('input[name="gps_rescue_throttle_max"]').val(); - FC.GPS_RESCUE.throttleHover = $('input[name="gps_rescue_throttle_hover"]').val(); - FC.GPS_RESCUE.minSats = $('input[name="gps_rescue_min_sats"]').val(); - FC.GPS_RESCUE.sanityChecks = $('select[name="gps_rescue_sanity_checks"]').val(); - } + // Load GPS Rescue parameters + FC.GPS_RESCUE.angle = $('input[name="gps_rescue_angle"]').val(); + FC.GPS_RESCUE.initialAltitudeM = $('input[name="gps_rescue_initial_altitude"]').val(); + FC.GPS_RESCUE.descentDistanceM = $('input[name="gps_rescue_descent_distance"]').val(); + FC.GPS_RESCUE.rescueGroundspeed = $('input[name="gps_rescue_ground_speed"]').val() * 100; + FC.GPS_RESCUE.throttleMin = $('input[name="gps_rescue_throttle_min"]').val(); + FC.GPS_RESCUE.throttleMax = $('input[name="gps_rescue_throttle_max"]').val(); + FC.GPS_RESCUE.throttleHover = $('input[name="gps_rescue_throttle_hover"]').val(); + FC.GPS_RESCUE.minSats = $('input[name="gps_rescue_min_sats"]').val(); + FC.GPS_RESCUE.sanityChecks = $('select[name="gps_rescue_sanity_checks"]').val(); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { FC.GPS_RESCUE.ascendRate = $('input[name="gps_rescue_ascend_rate"]').val() * 100; @@ -395,8 +342,7 @@ failsafe.initialize = function (callback) { } function save_feature_config() { - MSP.send_message(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG), false, - semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41) ? save_gps_rescue : save_to_eeprom); + MSP.send_message(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG), false, save_gps_rescue); } function save_gps_rescue() { diff --git a/src/js/tabs/gps.js b/src/js/tabs/gps.js index 13c45158..578942d1 100644 --- a/src/js/tabs/gps.js +++ b/src/js/tabs/gps.js @@ -54,9 +54,6 @@ gps.initialize = function (callback) { const usedArray = ['gnssUsedUnused', 'gnssUsedUsed']; const healthyArray = ['gnssHealthyUnknown', 'gnssHealthyHealthy', 'gnssHealthyUnhealthy', 'gnssHealthyUnknown']; let alt = FC.GPS_DATA.alt; - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - alt = alt / 10; - } $('.GPS_info td.fix').html((FC.GPS_DATA.fix) ? i18n.getMessage('gpsFixTrue') : i18n.getMessage('gpsFixFalse')); $('.GPS_info td.alt').text(`${alt} m`); diff --git a/src/js/tabs/led_strip.js b/src/js/tabs/led_strip.js index fc956acd..fddfc65c 100644 --- a/src/js/tabs/led_strip.js +++ b/src/js/tabs/led_strip.js @@ -11,19 +11,9 @@ led_strip.initialize = function (callback, scrollPosition) { let selectedModeColor = null; const functionTag = '.function-'; - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - TABS.led_strip.functions = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b']; - TABS.led_strip.baseFuncs = ['c', 'f', 'a', 'b', 'g', 'r']; - TABS.led_strip.overlays = ['t', 's', 'i', 'w']; - } else { - TABS.led_strip.functions = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b', 'l', 'o', 'n']; - TABS.led_strip.baseFuncs = ['c', 'f', 'a', 'l', 's', 'g', 'r']; - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - TABS.led_strip.overlays = ['t', 'o', 'b', 'n', 'i', 'w']; - } else { - TABS.led_strip.overlays = ['t', 'o', 'b', 'v', 'i', 'w']; - } - } + TABS.led_strip.functions = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b', 'l', 'o', 'n']; + TABS.led_strip.baseFuncs = ['c', 'f', 'a', 'l', 's', 'g', 'r']; + TABS.led_strip.overlays = ['t', 'o', 'b', 'v', 'i', 'w']; TABS.led_strip.wireMode = false; @@ -40,10 +30,7 @@ led_strip.initialize = function (callback, scrollPosition) { } function load_led_mode_colors() { - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) - MSP.send_message(MSPCodes.MSP_LED_STRIP_MODECOLOR, false, false, load_html); - else - load_html(); + MSP.send_message(MSPCodes.MSP_LED_STRIP_MODECOLOR, false, false, load_html); } @@ -73,13 +60,7 @@ led_strip.initialize = function (callback, scrollPosition) { const theHTML = []; let theHTMLlength = 0; for (let i = 0; i < 256; i++) { - if (semver.lte(FC.CONFIG.apiVersion, "1.19.0")) { - theHTML[theHTMLlength++] = ('
UD
'); - } else if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - theHTML[theHTMLlength++] = ('
UD
'); - } else { - theHTML[theHTMLlength++] = ('
UD
'); - } + theHTML[theHTMLlength++] = ('
UD
'); } $('.mainGrid').html(theHTML.join('')); @@ -88,31 +69,20 @@ led_strip.initialize = function (callback, scrollPosition) { }); // Aux channel drop-down - if (semver.lte(FC.CONFIG.apiVersion, "1.20.0")) { - $('.auxSelect').hide(); - $('.labelSelect').show(); - } else { - $('.auxSelect').show(); - $('.labelSelect').hide(); + $('.auxSelect').show(); + $('.labelSelect').hide(); - const AuxMode = 7; - const AuxDir = 0; + const AuxMode = 7; + const AuxDir = 0; - $('.auxSelect').val(getModeColor(AuxMode, AuxDir)); + $('.auxSelect').val(getModeColor(AuxMode, AuxDir)); - $('.auxSelect').on('change', function() { - setModeColor(AuxMode, AuxDir, $('.auxSelect').val()); - }); - } + $('.auxSelect').on('change', function() { + setModeColor(AuxMode, AuxDir, $('.auxSelect').val()); + }); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - $('.vtxOverlay').hide(); - $('.landingBlinkOverlay').show(); - } - else { - $('.landingBlinkOverlay').css("visibility", "hidden"); - $('.vtxOverlay').show(); - } + $('.landingBlinkOverlay').css("visibility", "hidden"); + $('.vtxOverlay').show(); // Clear button $('.funcClear').click(function() { @@ -603,10 +573,7 @@ led_strip.initialize = function (callback, scrollPosition) { } function send_led_strip_mode_colors() { - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) - mspHelper.sendLedStripModeColors(save_to_eeprom); - else - save_to_eeprom(); + mspHelper.sendLedStripModeColors(save_to_eeprom); } function save_to_eeprom() { @@ -727,19 +694,17 @@ led_strip.initialize = function (callback, scrollPosition) { // refresh mode color buttons function setModeBackgroundColor(element) { - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - element.find('[class*="mode_color"]').each(function() { - let m = 0; - let d = 0; + element.find('[class*="mode_color"]').each(function() { + let m = 0; + let d = 0; - const match = $(this).attr("class").match(/(^|\s)mode_color-([0-9]+)-([0-9]+)(\s|$)/); - if (match) { - m = Number(match[2]); - d = Number(match[3]); - $(this).css('background-color', HsvToColor(FC.LED_COLORS[getModeColor(m, d)])); - } - }); - } + const match = $(this).attr("class").match(/(^|\s)mode_color-([0-9]+)-([0-9]+)(\s|$)/); + if (match) { + m = Number(match[2]); + d = Number(match[3]); + $(this).css('background-color', HsvToColor(FC.LED_COLORS[getModeColor(m, d)])); + } + }); } function setBackgroundColor(element) { @@ -767,45 +732,31 @@ led_strip.initialize = function (callback, scrollPosition) { } function areOverlaysActive(activeFunction) { - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - switch (activeFunction) { - case "function-c": - case "function-a": - case "function-f": - case "function-g": - return true; - default: - break; - } - } else { - switch (activeFunction) { - case "": - case "function-c": - case "function-a": - case "function-f": - case "function-s": - case "function-l": - case "function-r": - case "function-o": - case "function-g": - return true; - default: - break; - } + switch (activeFunction) { + case "": + case "function-c": + case "function-a": + case "function-f": + case "function-s": + case "function-l": + case "function-r": + case "function-o": + case "function-g": + return true; + default: + break; } return false; } function areBlinkersActive(activeFunction) { - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - switch (activeFunction) { - case "function-c": - case "function-a": - case "function-f": - return true; - default: - break; - } + switch (activeFunction) { + case "function-c": + case "function-a": + case "function-f": + return true; + default: + break; } return false; } @@ -818,26 +769,20 @@ led_strip.initialize = function (callback, scrollPosition) { return false; case "function-r": case "function-b": - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - return false; - } - break; default: return true; } } function isVtxActive(activeFunction) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - switch (activeFunction) { - case "function-v": - case "function-c": - case "function-a": - case "function-f": - return true; - default: - return false; - } + switch (activeFunction) { + case "function-v": + case "function-c": + case "function-a": + case "function-f": + return true; + default: + return false; } } @@ -846,23 +791,12 @@ led_strip.initialize = function (callback, scrollPosition) { const activeFunction = $('select.functionSelect').val(); $('select.functionSelect').addClass(activeFunction); - - if (semver.lte(FC.CONFIG.apiVersion, "1.18.0")) { - // <= 18 - // Hide GPS (Func) - // Hide RSSI (O/L), Blink (Func) - // Hide Battery, RSSI (Func), Larson (O/L), Blink (O/L), Landing (O/L) - $(".extra_functions20").hide(); - $(".mode_colors").hide(); - } else { - // >= 20 - // Show GPS (Func) - // Hide RSSI (O/L), Blink (Func) - // Show Battery, RSSI (Func), Larson (O/L), Blink (O/L), Landing (O/L) - $(".extra_functions20").show(); - $(".mode_colors").show(); - } - + // >= 20 + // Show GPS (Func) + // Hide RSSI (O/L), Blink (Func) + // Show Battery, RSSI (Func), Larson (O/L), Blink (O/L), Landing (O/L) + $(".extra_functions20").show(); + $(".mode_colors").show(); // set color modifiers (check-boxes) visibility $('.overlays').toggle(areOverlaysActive(activeFunction)); @@ -875,67 +809,50 @@ led_strip.initialize = function (callback, scrollPosition) { $('.vtxOverlay').toggle(isVtxActive(activeFunction)); - // set directions visibility - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - switch (activeFunction) { - case "function-r": - $('.indicatorOverlay').hide(); - $('.directions').hide(); - break; - default: - $('.indicatorOverlay').show(); - $('.directions').show(); - break; - } + $('.mode_colors').hide(); + + // set mode colors visibility + + if (activeFunction === "function-f") { + $('.mode_colors').show(); } - $('.mode_colors').hide(); - if (semver.gte(FC.CONFIG.apiVersion, "1.19.0")) { - // set mode colors visibility + // set special colors visibility + $('.special_colors').show(); + $('.mode_color-6-0').hide(); + $('.mode_color-6-1').hide(); + $('.mode_color-6-2').hide(); + $('.mode_color-6-3').hide(); + $('.mode_color-6-4').hide(); + $('.mode_color-6-5').hide(); + $('.mode_color-6-6').hide(); + $('.mode_color-6-7').hide(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - if (activeFunction === "function-f") { - $('.mode_colors').show(); - } - } - - // set special colors visibility - $('.special_colors').show(); - $('.mode_color-6-0').hide(); - $('.mode_color-6-1').hide(); - $('.mode_color-6-2').hide(); - $('.mode_color-6-3').hide(); - $('.mode_color-6-4').hide(); - $('.mode_color-6-5').hide(); - $('.mode_color-6-6').hide(); - $('.mode_color-6-7').hide(); - - switch (activeFunction) { - case "": // none - case "function-f": // Modes & Orientation - case "function-l": // Battery - // $('.mode_color-6-3').show(); // background - $('.special_colors').hide(); - break; - case "function-g": // GPS - $('.mode_color-6-5').show(); // no sats - $('.mode_color-6-6').show(); // no lock - $('.mode_color-6-7').show(); // locked - // $('.mode_color-6-3').show(); // background - break; - case "function-b": // Blink - $('.mode_color-6-4').show(); // blink background - break; - case "function-a": // Arm state - $('.mode_color-6-0').show(); // disarmed - $('.mode_color-6-1').show(); // armed - break; - - case "function-r": // Ring - default: - $('.special_colors').hide(); + switch (activeFunction) { + case "": // none + case "function-f": // Modes & Orientation + case "function-l": // Battery + // $('.mode_color-6-3').show(); // background + $('.special_colors').hide(); break; - } + case "function-g": // GPS + $('.mode_color-6-5').show(); // no sats + $('.mode_color-6-6').show(); // no lock + $('.mode_color-6-7').show(); // locked + // $('.mode_color-6-3').show(); // background + break; + case "function-b": // Blink + $('.mode_color-6-4').show(); // blink background + break; + case "function-a": // Arm state + $('.mode_color-6-0').show(); // disarmed + $('.mode_color-6-1').show(); // armed + break; + + case "function-r": // Ring + default: + $('.special_colors').hide(); + break; } } @@ -966,32 +883,20 @@ led_strip.initialize = function (callback, scrollPosition) { } function unselectOverlays(letter) { - if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - if (letter == 'b' || letter == 'r') { - unselectOverlay(letter, 'i'); - } - if (letter == 'b' || letter == 'r' || letter == 'l' || letter == 'g') { - unselectOverlay(letter, 'w'); - unselectOverlay(letter, 'v'); - unselectOverlay(letter, 't'); - unselectOverlay(letter, 's'); - } - } else { - // MSP 1.20 - if (letter == 'r' || letter == '') { - unselectOverlay(letter, 'o'); - unselectOverlay(letter, 'b'); - unselectOverlay(letter, 'n'); - unselectOverlay(letter, 't'); - } - if (letter == 'l' || letter == 'g' || letter == 's') { - unselectOverlay(letter, 'w'); - unselectOverlay(letter, 'v'); - unselectOverlay(letter, 't'); - unselectOverlay(letter, 'o'); - unselectOverlay(letter, 'b'); - unselectOverlay(letter, 'n'); - } + // MSP 1.20 + if (letter == 'r' || letter == '') { + unselectOverlay(letter, 'o'); + unselectOverlay(letter, 'b'); + unselectOverlay(letter, 'n'); + unselectOverlay(letter, 't'); + } + if (letter == 'l' || letter == 'g' || letter == 's') { + unselectOverlay(letter, 'w'); + unselectOverlay(letter, 'v'); + unselectOverlay(letter, 't'); + unselectOverlay(letter, 'o'); + unselectOverlay(letter, 'b'); + unselectOverlay(letter, 'n'); } } diff --git a/src/js/tabs/motors.js b/src/js/tabs/motors.js index 7b4d0ae8..b6e9344f 100644 --- a/src/js/tabs/motors.js +++ b/src/js/tabs/motors.js @@ -76,9 +76,7 @@ motors.initialize = async function (callback) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { await MSP.promise(MSPCodes.MSP_FILTER_CONFIG); } - if (semver.gte(FC.CONFIG.apiVersion, "1.8.0")) { - await MSP.promise(MSPCodes.MSP_ARMING_CONFIG); - } + await MSP.promise(MSPCodes.MSP_ARMING_CONFIG); load_html(); @@ -1128,10 +1126,6 @@ motors.initialize = async function (callback) { FC.PID_ADVANCED_CONFIG.motor_pwm_rate = parseInt($('input[name="unsyncedpwmfreq"]').val()); FC.PID_ADVANCED_CONFIG.digitalIdlePercent = parseFloat($('input[name="digitalIdlePercent"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.PID_ADVANCED_CONFIG.gyroUse32kHz = $('input[id="gyroUse32kHz"]').is(':checked') ? 1 : 0; - } - await MSP.promise(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG)); await MSP.promise(MSPCodes.MSP_SET_MIXER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_MIXER_CONFIG)); await MSP.promise(MSPCodes.MSP_SET_MOTOR_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_MOTOR_CONFIG)); diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index aaea97fd..11fd87dd 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -70,7 +70,7 @@ onboard_logging.initialize = function (callback) { * * The best we can do on those targets is check the BLACKBOX feature bit to identify support for Blackbox instead. */ - if ((FC.BLACKBOX.supported || FC.DATAFLASH.supported) && (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33) || FC.FEATURE_CONFIG.features.isEnabled('BLACKBOX'))) { + if ((FC.BLACKBOX.supported || FC.DATAFLASH.supported) || FC.FEATURE_CONFIG.features.isEnabled('BLACKBOX')) { blackboxSupport = 'yes'; } else { blackboxSupport = 'no'; @@ -107,12 +107,7 @@ onboard_logging.initialize = function (callback) { $(".tab-onboard_logging a.save-settings").click(function() { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { FC.BLACKBOX.blackboxSampleRate = parseInt(loggingRatesSelect.val(), 10); - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { FC.BLACKBOX.blackboxPDenom = parseInt(loggingRatesSelect.val(), 10); - } else { - const rate = loggingRatesSelect.val().split('/'); - FC.BLACKBOX.blackboxRateNum = parseInt(rate[0], 10); - FC.BLACKBOX.blackboxRateDenom = parseInt(rate[1], 10); } FC.BLACKBOX.blackboxDevice = parseInt(deviceSelect.val(), 10); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { @@ -135,30 +130,24 @@ onboard_logging.initialize = function (callback) { } }).change(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - if ((FC.SDCARD.supported && deviceSelect.val() == 2) || (FC.DATAFLASH.supported && deviceSelect.val() == 1)) { + if ((FC.SDCARD.supported && deviceSelect.val() == 2) || (FC.DATAFLASH.supported && deviceSelect.val() == 1)) { - $(".tab-onboard_logging") - .toggleClass("msc-supported", true); + $(".tab-onboard_logging") + .toggleClass("msc-supported", true); - $('a.onboardLoggingRebootMsc').click(function () { - analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'RebootMsc'); + $('a.onboardLoggingRebootMsc').click(function () { + analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'RebootMsc'); - const buffer = []; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - if (GUI.operating_system === "Linux") { - // Reboot into MSC using UTC time offset instead of user timezone - // Linux seems to expect that the FAT file system timestamps are UTC based - buffer.push(mspHelper.REBOOT_TYPES.MSC_UTC); - } else { - buffer.push(mspHelper.REBOOT_TYPES.MSC); - } - } else { - buffer.push(mspHelper.REBOOT_TYPES.MSC); - } - MSP.send_message(MSPCodes.MSP_SET_REBOOT, buffer, false); - }); - } + const buffer = []; + if (GUI.operating_system === "Linux") { + // Reboot into MSC using UTC time offset instead of user timezone + // Linux seems to expect that the FAT file system timestamps are UTC based + buffer.push(mspHelper.REBOOT_TYPES.MSC_UTC); + } else { + buffer.push(mspHelper.REBOOT_TYPES.MSC); + } + MSP.send_message(MSPCodes.MSP_SET_REBOOT, buffer, false); + }); } update_html(); @@ -170,24 +159,14 @@ onboard_logging.initialize = function (callback) { function populateDevices(deviceSelect) { deviceSelect.empty(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33)) { - deviceSelect.append(``); - if (FC.DATAFLASH.supported) { - deviceSelect.append(``); - } - if (FC.SDCARD.supported) { - deviceSelect.append(``); - } - deviceSelect.append(``); - } else { - deviceSelect.append(``); - if (FC.DATAFLASH.ready) { - deviceSelect.append(``); - } - if (FC.SDCARD.supported) { - deviceSelect.append(``); - } + deviceSelect.append(``); + if (FC.DATAFLASH.supported) { + deviceSelect.append(``); } + if (FC.SDCARD.supported) { + deviceSelect.append(``); + } + deviceSelect.append(``); deviceSelect.val(FC.BLACKBOX.blackboxDevice); } @@ -205,9 +184,6 @@ onboard_logging.initialize = function (callback) { let pidRateBase = 8000; - if (semver.gte(FC.CONFIG.apiVersion, "1.25.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_41) && FC.PID_ADVANCED_CONFIG.gyroUse32kHz !== 0) { - pidRateBase = 32000; - } pidRate = pidRateBase / FC.PID_ADVANCED_CONFIG.gyro_sync_denom / FC.PID_ADVANCED_CONFIG.pid_process_denom; } @@ -223,7 +199,7 @@ onboard_logging.initialize = function (callback) { loggingRatesSelect.append(``); } loggingRatesSelect.val(FC.BLACKBOX.blackboxSampleRate); - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { + } else { loggingRates = [ {text: "Disabled", hz: 0, p_denom: 0}, {text: "500 Hz", hz: 500, p_denom: 16}, @@ -244,36 +220,6 @@ onboard_logging.initialize = function (callback) { loggingRatesSelect.val(FC.BLACKBOX.blackboxPDenom); } - else { - loggingRates = [ - {num: 1, denom: 1}, - {num: 1, denom: 2}, - {num: 1, denom: 3}, - {num: 1, denom: 4}, - {num: 1, denom: 5}, - {num: 1, denom: 6}, - {num: 1, denom: 7}, - {num: 1, denom: 8}, - {num: 1, denom: 16}, - {num: 1, denom: 32}, - ]; - - - for (let i = 0; i < loggingRates.length; i++) { - let loggingRate = Math.round(pidRate / loggingRates[i].denom); - let loggingRateUnit = " Hz"; - if (loggingRate !== Infinity) { - if (gcd(loggingRate, 1000) === 1000) { - loggingRate /= 1000; - loggingRateUnit = " kHz"; - } - } - loggingRatesSelect.append(``); - - } - loggingRatesSelect.val(`${FC.BLACKBOX.blackboxRateNum}/${FC.BLACKBOX.blackboxRateDenom}`); - } } function populateDebugModes(debugModeSelect) { @@ -448,16 +394,14 @@ onboard_logging.initialize = function (callback) { .toggleClass("sdcard-initializing", FC.SDCARD.state === MSP.SDCARD_STATE_CARD_INIT || FC.SDCARD.state === MSP.SDCARD_STATE_FS_INIT) .toggleClass("sdcard-ready", FC.SDCARD.state === MSP.SDCARD_STATE_READY); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - const mscIsReady = dataflashPresent || (FC.SDCARD.state === MSP.SDCARD_STATE_READY); - $(".tab-onboard_logging") - .toggleClass("msc-not-ready", !mscIsReady); + const mscIsReady = dataflashPresent || (FC.SDCARD.state === MSP.SDCARD_STATE_READY); + $(".tab-onboard_logging") + .toggleClass("msc-not-ready", !mscIsReady); - if (!mscIsReady) { - $('a.onboardLoggingRebootMsc').addClass('disabled'); - } else { - $('a.onboardLoggingRebootMsc').removeClass('disabled'); - } + if (!mscIsReady) { + $('a.onboardLoggingRebootMsc').addClass('disabled'); + } else { + $('a.onboardLoggingRebootMsc').removeClass('disabled'); } let loggingStatus; @@ -548,11 +492,7 @@ onboard_logging.initialize = function (callback) { function flash_save_begin() { if (GUI.connected_to) { if (FC.boardHasVcp()) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - self.blockSize = self.VCP_BLOCK_SIZE; - } else { - self.blockSize = self.VCP_BLOCK_SIZE_3_0; - } + self.blockSize = self.VCP_BLOCK_SIZE; } else { self.blockSize = self.BLOCK_SIZE; } diff --git a/src/js/tabs/pid_tuning.js b/src/js/tabs/pid_tuning.js index f1780a14..4dc38360 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -40,48 +40,34 @@ pid_tuning.initialize = function (callback) { const PID_DEFAULT = FC.getPidDefaults(); // requesting MSP_STATUS manually because it contains FC.CONFIG.profile - MSP.promise(MSPCodes.MSP_STATUS).then(function() { - if (semver.gte(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_MIN_SUPPORTED_PID_CONTROLLER_CHANGE)) { - return MSP.promise(MSPCodes.MSP_PID_CONTROLLER); - } - }).then(function() { - return MSP.promise(MSPCodes.MSP_PIDNAMES); - }).then(function() { - return MSP.promise(MSPCodes.MSP_PID); - }).then(function() { - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - return MSP.promise(MSPCodes.MSP_PID_ADVANCED); - } - }).then(function() { - return MSP.promise(MSPCodes.MSP_RC_TUNING); - }).then(function() { - return MSP.promise(MSPCodes.MSP_FILTER_CONFIG); - }).then(function() { - return MSP.promise(MSPCodes.MSP_RC_DEADBAND); - }).then(function() { - return MSP.promise(MSPCodes.MSP_MOTOR_CONFIG); - }).then(function() { - let promise; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - promise = MSP.promise(MSPCodes.MSP_SIMPLIFIED_TUNING); - } + MSP.promise(MSPCodes.MSP_STATUS) + .then(() => MSP.promise(MSPCodes.MSP_PID_CONTROLLER)) + .then(() => MSP.promise(MSPCodes.MSP_PIDNAMES)) + .then(() => MSP.promise(MSPCodes.MSP_PID)) + .then(() => MSP.promise(MSPCodes.MSP_PID_ADVANCED)) + .then(() => MSP.promise(MSPCodes.MSP_RC_TUNING)) + .then(() => MSP.promise(MSPCodes.MSP_FILTER_CONFIG)) + .then(() => MSP.promise(MSPCodes.MSP_RC_DEADBAND)) + .then(() => MSP.promise(MSPCodes.MSP_MOTOR_CONFIG)) + .then(() => { + let promise; + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + promise = MSP.promise(MSPCodes.MSP_SIMPLIFIED_TUNING); + } - return promise; - }).then(function() { - MSP.send_message(MSPCodes.MSP_MIXER_CONFIG, false, false, load_html); - }); + return promise; + }) + .then(() => MSP.send_message(MSPCodes.MSP_MIXER_CONFIG, false, false, load_html)); function load_html() { $('#content').load("./tabs/pid_tuning.html", process_html); } - const vbatpidcompensationIsUsed = semver.gte(FC.CONFIG.apiVersion, "1.16.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44); + const vbatpidcompensationIsUsed = semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44); function pid_and_rc_to_form() { self.setProfile(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - self.setRateProfile(); - } + self.setRateProfile(); // Fill in the data from PIDs array for each pid name FC.PID_NAMES.forEach(function(elementPid, indexPid) { @@ -119,287 +105,208 @@ pid_tuning.initialize = function (callback) { $('.tpa-old input[name="tpa-breakpoint"]').val(FC.RC_TUNING.dynamic_THR_breakpoint); } - if (semver.lt(FC.CONFIG.apiVersion, "1.10.0")) { - $('.pid_tuning input[name="rc_yaw_expo"]').hide(); - $('.pid_tuning input[name="rc_expo"]').attr("rowspan", "3"); - } + $('.pid_tuning input[name="rc_yaw_expo"]').hide(); + $('.pid_tuning input[name="rc_expo"]').attr("rowspan", "3"); $('.vbatpidcompensation').toggle(vbatpidcompensationIsUsed); $('input[id="vbatpidcompensation"]').prop('checked', FC.ADVANCED_TUNING.vbatPidCompensation !== 0); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - $('#pid-tuning .delta select').val(FC.ADVANCED_TUNING.deltaMethod); - } + $('#pid-tuning .delta select').val(FC.ADVANCED_TUNING.deltaMethod); - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - $('.pid_tuning input[name="rc_rate_yaw"]').val(FC.RC_TUNING.rcYawRate.toFixed(2)); - $('.pid_filter input[name="gyroLowpassFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_hz); - $('.pid_filter input[name="dtermLowpassFrequency"]').val(FC.FILTER_CONFIG.dterm_lowpass_hz); - $('.pid_filter input[name="yawLowpassFrequency"]').val(FC.FILTER_CONFIG.yaw_lowpass_hz); - } else { - $('.tab-pid_tuning .subtab-filter').hide(); - $('.tab-pid_tuning .tab-container').hide(); - $('.pid_tuning input[name="rc_rate_yaw"]').hide(); - } + $('.pid_tuning input[name="rc_rate_yaw"]').val(FC.RC_TUNING.rcYawRate.toFixed(2)); + $('.pid_filter input[name="gyroLowpassFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_hz); + $('.pid_filter input[name="dtermLowpassFrequency"]').val(FC.FILTER_CONFIG.dterm_lowpass_hz); + $('.pid_filter input[name="yawLowpassFrequency"]').val(FC.FILTER_CONFIG.yaw_lowpass_hz); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0") - || semver.gte(FC.CONFIG.apiVersion, "1.16.0") && FC.FEATURE_CONFIG.features.isEnabled('SUPEREXPO_RATES')) { + if (FC.FEATURE_CONFIG.features.isEnabled('SUPEREXPO_RATES')) { $('#pid-tuning .rate').text(i18n.getMessage("pidTuningSuperRate")); } else { $('#pid-tuning .rate').text(i18n.getMessage("pidTuningRate")); } - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - $('.pid_filter input[name="gyroNotch1Frequency"]').val(FC.FILTER_CONFIG.gyro_notch_hz); - $('.pid_filter input[name="gyroNotch1Cutoff"]').val(FC.FILTER_CONFIG.gyro_notch_cutoff); - $('.pid_filter input[name="dTermNotchFrequency"]').val(FC.FILTER_CONFIG.dterm_notch_hz); - $('.pid_filter input[name="dTermNotchCutoff"]').val(FC.FILTER_CONFIG.dterm_notch_cutoff); + $('.pid_filter input[name="gyroNotch1Frequency"]').val(FC.FILTER_CONFIG.gyro_notch_hz); + $('.pid_filter input[name="gyroNotch1Cutoff"]').val(FC.FILTER_CONFIG.gyro_notch_cutoff); + $('.pid_filter input[name="dTermNotchFrequency"]').val(FC.FILTER_CONFIG.dterm_notch_hz); + $('.pid_filter input[name="dTermNotchCutoff"]').val(FC.FILTER_CONFIG.dterm_notch_cutoff); - const dtermSetpointTransitionNumberElement = $('input[name="dtermSetpointTransition-number"]'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_38)) { - dtermSetpointTransitionNumberElement.attr('min', 0.00); - } else { - dtermSetpointTransitionNumberElement.attr('min', 0.01); - } + const dtermSetpointTransitionNumberElement = $('input[name="dtermSetpointTransition-number"]'); + dtermSetpointTransitionNumberElement.attr('min', 0.00); + dtermSetpointTransitionNumberElement.val(FC.ADVANCED_TUNING.dtermSetpointTransition / 100); - dtermSetpointTransitionNumberElement.val(FC.ADVANCED_TUNING.dtermSetpointTransition / 100); + $('input[name="dtermSetpoint-number"]').val(FC.ADVANCED_TUNING.dtermSetpointWeight / 100); - $('input[name="dtermSetpoint-number"]').val(FC.ADVANCED_TUNING.dtermSetpointWeight / 100); - } else { - $('.pid_filter .newFilter').hide(); - } + $('.pid_filter input[name="gyroNotch2Frequency"]').val(FC.FILTER_CONFIG.gyro_notch2_hz); + $('.pid_filter input[name="gyroNotch2Cutoff"]').val(FC.FILTER_CONFIG.gyro_notch2_cutoff); - if (semver.gte(FC.CONFIG.apiVersion, "1.21.0")) { - $('.pid_filter input[name="gyroNotch2Frequency"]').val(FC.FILTER_CONFIG.gyro_notch2_hz); - $('.pid_filter input[name="gyroNotch2Cutoff"]').val(FC.FILTER_CONFIG.gyro_notch2_cutoff); - } else { - $('.pid_filter .gyroNotch2').hide(); - } + $('.pid_tuning input[name="angleLimit"]').val(FC.ADVANCED_TUNING.levelAngleLimit); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - $('.pid_tuning input[name="angleLimit"]').val(FC.ADVANCED_TUNING.levelAngleLimit); - - if (semver.lte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - $('.pid_tuning input[name="sensitivity"]').val(FC.ADVANCED_TUNING.levelSensitivity); - } else { - $('.pid_tuning input[name="sensitivity"]').hide(); - $('.pid_tuning .levelSensitivityHeader').empty(); - } - } else { - $('.pid_sensitivity').hide(); - } + $('.pid_tuning input[name="sensitivity"]').hide(); + $('.pid_tuning .levelSensitivityHeader').empty(); const antiGravitySwitch = $('#antiGravitySwitch'); const antiGravityGain = $('.antigravity input[name="itermAcceleratorGain"]'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - $('.pid_filter select[name="dtermLowpassType"]').val(FC.FILTER_CONFIG.dterm_lowpass_type); + $('.pid_filter select[name="dtermLowpassType"]').val(FC.FILTER_CONFIG.dterm_lowpass_type); - const ITERM_ACCELERATOR_GAIN_OFF = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0 : 1000; + const ITERM_ACCELERATOR_GAIN_OFF = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? 0 : 1000; + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + // we keep the same name in html - just switching variable. + antiGravityGain.val(FC.ADVANCED_TUNING.antiGravityGain / 10); + antiGravitySwitch.prop('checked', FC.ADVANCED_TUNING.antiGravityGain !== ITERM_ACCELERATOR_GAIN_OFF); + } else { + $('.antigravity input[name="itermThrottleThreshold"]').val(FC.ADVANCED_TUNING.itermThrottleThreshold); + antiGravityGain.val(FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); + antiGravitySwitch.prop('checked', FC.ADVANCED_TUNING.itermAcceleratorGain !== ITERM_ACCELERATOR_GAIN_OFF); + } + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + antiGravityGain.attr("min", "0.1"); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - // we keep the same name in html - just switching variable. - antiGravityGain.val(FC.ADVANCED_TUNING.antiGravityGain / 10); - antiGravitySwitch.prop('checked', FC.ADVANCED_TUNING.antiGravityGain !== ITERM_ACCELERATOR_GAIN_OFF); - } else { - $('.antigravity input[name="itermThrottleThreshold"]').val(FC.ADVANCED_TUNING.itermThrottleThreshold); - antiGravityGain.val(FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); - antiGravitySwitch.prop('checked', FC.ADVANCED_TUNING.itermAcceleratorGain !== ITERM_ACCELERATOR_GAIN_OFF); + antiGravityGain.attr({ "min": "0.1", "max": "25.0", "step": "0.1" }); } + } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - antiGravityGain.attr("min", "0.1"); + antiGravitySwitch.on("change", function() { + if (antiGravitySwitch.is(':checked')) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - antiGravityGain.attr({ "min": "0.1", "max": "25.0", "step": "0.1" }); - } - } - - antiGravitySwitch.on("change", function() { - if (antiGravitySwitch.is(':checked')) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - antiGravityGain.val(Number.parseFloat(FC.ADVANCED_TUNING.antiGravityGain / 10 || 8).toFixed(1)); - } else { - const DEFAULT_ACCELERATOR_GAIN = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43) ? 3.5 : 1.1; - - if (FC.ADVANCED_TUNING.itermAcceleratorGain === ITERM_ACCELERATOR_GAIN_OFF) { - antiGravityGain.val(DEFAULT_ACCELERATOR_GAIN); - } else { - const itermAcceleratorGain = (FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); - antiGravityGain.val(itermAcceleratorGain); - } - } - - $('.antigravity .suboption').show(); - $('.antigravity .antiGravityThres').toggle(semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) && FC.ADVANCED_TUNING.itermAcceleratorGain === 0); - $('.antigravity .antiGravityMode').toggle(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40) && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)); + antiGravityGain.val(Number.parseFloat(FC.ADVANCED_TUNING.antiGravityGain / 10 || 8).toFixed(1)); } else { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - antiGravityGain.val(ITERM_ACCELERATOR_GAIN_OFF / 1000); - } else { - $('.antigravity select[id="antiGravityMode"]').val(0); - antiGravityGain.val(ITERM_ACCELERATOR_GAIN_OFF); - } + const DEFAULT_ACCELERATOR_GAIN = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43) ? 3.5 : 1.1; - $('.antigravity .suboption').hide(); + if (FC.ADVANCED_TUNING.itermAcceleratorGain === ITERM_ACCELERATOR_GAIN_OFF) { + antiGravityGain.val(DEFAULT_ACCELERATOR_GAIN); + } else { + const itermAcceleratorGain = (FC.ADVANCED_TUNING.itermAcceleratorGain / 1000); + antiGravityGain.val(itermAcceleratorGain); + } } - }); - antiGravitySwitch.trigger("change"); - } else { - $('.dtermLowpassType').hide(); - $('.antigravity').hide(); - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - $('.pid_tuning input[name="rc_rate_pitch"]').val(FC.RC_TUNING.rcPitchRate.toFixed(2)); - $('.pid_tuning input[name="rc_pitch_expo"]').val(FC.RC_TUNING.RC_PITCH_EXPO.toFixed(2)); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - - $('.pid_filter input[name="gyroLowpass2Frequency"]').val(FC.FILTER_CONFIG.gyro_lowpass2_hz); - $('.pid_filter select[name="gyroLowpassType"]').val(FC.FILTER_CONFIG.gyro_lowpass_type); - $('.pid_filter select[name="gyroLowpass2Type"]').val(FC.FILTER_CONFIG.gyro_lowpass2_type); - $('.pid_filter input[name="dtermLowpass2Frequency"]').val(FC.FILTER_CONFIG.dterm_lowpass2_hz); - $('.pid_filter select[name="dtermLowpass2Type"]').val(FC.FILTER_CONFIG.dterm_lowpass2_type); - - // We load it again because the limits are now bigger than in 1.16.0 - $('.pid_filter input[name="gyroLowpassFrequency"]').attr("max","16000"); - $('.pid_filter input[name="gyroLowpassFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_hz); - //removes 5th column which is Feedforward - $('#pid_main .pid_titlebar2 th').attr('colspan', 4); - } else { - $('.gyroLowpass2').hide(); - $('.gyroLowpass2Type').hide(); - $('.dtermLowpass2').hide(); - $('#pid_main .pid_titlebar2 th').attr('colspan', 4); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - - // I Term Rotation - $('input[id="itermrotation"]').prop('checked', FC.ADVANCED_TUNING.itermRotation !== 0); - - // Smart Feed Forward - $('input[id="smartfeedforward"]').prop('checked', FC.ADVANCED_TUNING.smartFeedforward !== 0); - - // I Term Relax - const itermRelaxCheck = $('input[id="itermrelax"]'); - - itermRelaxCheck.prop('checked', FC.ADVANCED_TUNING.itermRelax !== 0); - $('select[id="itermrelaxAxes"]').val(FC.ADVANCED_TUNING.itermRelax > 0 ? FC.ADVANCED_TUNING.itermRelax : 1); - $('select[id="itermrelaxType"]').val(FC.ADVANCED_TUNING.itermRelaxType); - $('input[name="itermRelaxCutoff"]').val(FC.ADVANCED_TUNING.itermRelaxCutoff); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - $('.itermrelax input[name="itermRelaxCutoff"]').attr("max","50"); - } - - itermRelaxCheck.change(function() { - const checked = $(this).is(':checked'); - - if (checked) { - $('.itermrelax .suboption').show(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - $('.itermRelaxCutoff').show(); - } else { - $('.itermRelaxCutoff').hide(); - } + $('.antigravity .suboption').show(); + $('.antigravity .antiGravityThres').toggle(semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) && FC.ADVANCED_TUNING.itermAcceleratorGain === 0); + $('.antigravity .antiGravityMode').toggle(semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)); + } else { + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + antiGravityGain.val(ITERM_ACCELERATOR_GAIN_OFF / 1000); } else { - $('.itermrelax .suboption').hide(); + $('.antigravity select[id="antiGravityMode"]').val(0); + antiGravityGain.val(ITERM_ACCELERATOR_GAIN_OFF); } - }); - itermRelaxCheck.change(); - // Absolute Control - const absoluteControlGainNumberElement = $('input[name="absoluteControlGain-number"]'); - absoluteControlGainNumberElement.val(FC.ADVANCED_TUNING.absoluteControlGain).trigger('input'); - - // Throttle Boost - const throttleBoostNumberElement = $('input[name="throttleBoost-number"]'); - throttleBoostNumberElement.val(FC.ADVANCED_TUNING.throttleBoost).trigger('input'); - - // Acro Trainer - const acroTrainerAngleLimitNumberElement = $('input[name="acroTrainerAngleLimit-number"]'); - acroTrainerAngleLimitNumberElement.val(FC.ADVANCED_TUNING.acroTrainerAngleLimit).trigger('input'); - - // Yaw D - $('.pid_tuning .YAW input[name="d"]').val(FC.PIDS[2][2]); // PID Yaw D - - // Feedforward - $('.pid_tuning .ROLL input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardRoll); - $('.pid_tuning .PITCH input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardPitch); - $('.pid_tuning .YAW input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardYaw); - $('#pid_main .pid_titlebar2 th').attr('colspan', 5); - - const feedforwardTransitionNumberElement = $('input[name="feedforwardTransition-number"]'); - feedforwardTransitionNumberElement.val(Number.parseFloat(FC.ADVANCED_TUNING.feedforwardTransition / 100).toFixed(2)); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40) && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - // AntiGravity Mode - const antiGravityModeSelect = $('.antigravity select[id="antiGravityMode"]'); - - antiGravityModeSelect.on('change', function () { - const antiGravityModeValue = antiGravityModeSelect.val(); - - // Smooth removes threshold - $('.antiGravityThres').toggle(antiGravityModeValue !== 0); - }); - - antiGravityModeSelect.val(FC.ADVANCED_TUNING.antiGravityMode).trigger('change'); + $('.antigravity .suboption').hide(); } + }); + antiGravitySwitch.trigger("change"); - } else { - $('.itermrotation').hide(); - $('.smartfeedforward').hide(); - $('.itermrelax').hide(); - $('.absoluteControlGain').hide(); - $('.throttleBoost').hide(); - $('.acroTrainerAngleLimit').hide(); + $('.pid_tuning input[name="rc_rate_pitch"]').val(FC.RC_TUNING.rcPitchRate.toFixed(2)); + $('.pid_tuning input[name="rc_pitch_expo"]').val(FC.RC_TUNING.RC_PITCH_EXPO.toFixed(2)); - $('.pid_tuning .YAW input[name="d"]').hide(); - // Feedforward column - $('#pid_main tr :nth-child(6)').hide(); + $('.pid_filter input[name="gyroLowpass2Frequency"]').val(FC.FILTER_CONFIG.gyro_lowpass2_hz); + $('.pid_filter select[name="gyroLowpassType"]').val(FC.FILTER_CONFIG.gyro_lowpass_type); + $('.pid_filter select[name="gyroLowpass2Type"]').val(FC.FILTER_CONFIG.gyro_lowpass2_type); + $('.pid_filter input[name="dtermLowpass2Frequency"]').val(FC.FILTER_CONFIG.dterm_lowpass2_hz); + $('.pid_filter select[name="dtermLowpass2Type"]').val(FC.FILTER_CONFIG.dterm_lowpass2_type); - $('#pid-tuning .feedforwardGroup').hide(); + // We load it again because the limits are now bigger than in 1.16.0 + $('.pid_filter input[name="gyroLowpassFrequency"]').attr("max","16000"); + $('.pid_filter input[name="gyroLowpassFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_hz); + //removes 5th column which is Feedforward + $('#pid_main .pid_titlebar2 th').attr('colspan', 4); + + // I Term Rotation + $('input[id="itermrotation"]').prop('checked', FC.ADVANCED_TUNING.itermRotation !== 0); + + // Smart Feed Forward + $('input[id="smartfeedforward"]').prop('checked', FC.ADVANCED_TUNING.smartFeedforward !== 0); + + // I Term Relax + const itermRelaxCheck = $('input[id="itermrelax"]'); + + itermRelaxCheck.prop('checked', FC.ADVANCED_TUNING.itermRelax !== 0); + $('select[id="itermrelaxAxes"]').val(FC.ADVANCED_TUNING.itermRelax > 0 ? FC.ADVANCED_TUNING.itermRelax : 1); + $('select[id="itermrelaxType"]').val(FC.ADVANCED_TUNING.itermRelaxType); + $('input[name="itermRelaxCutoff"]').val(FC.ADVANCED_TUNING.itermRelaxCutoff); + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + $('.itermrelax input[name="itermRelaxCutoff"]').attr("max","50"); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - $('select[id="throttleLimitType"]').val(FC.RC_TUNING.throttleLimitType); - $('.throttle_limit input[name="throttleLimitPercent"]').val(FC.RC_TUNING.throttleLimitPercent); + itermRelaxCheck.change(function() { + const checked = $(this).is(':checked'); - $('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz); - $('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz); - $('.pid_filter select[name="gyroLowpassDynType"]').val(FC.FILTER_CONFIG.gyro_lowpass_type); + if (checked) { + $('.itermrelax .suboption').show(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + $('.itermRelaxCutoff').show(); + } else { + $('.itermRelaxCutoff').hide(); + } + } else { + $('.itermrelax .suboption').hide(); + } + }); + itermRelaxCheck.change(); - $('.pid_filter input[name="dtermLowpassDynMinFrequency"]').val(FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz); - $('.pid_filter input[name="dtermLowpassDynMaxFrequency"]').val(FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz); - $('.pid_filter select[name="dtermLowpassDynType"]').val(FC.FILTER_CONFIG.dterm_lowpass_type); + // Absolute Control + const absoluteControlGainNumberElement = $('input[name="absoluteControlGain-number"]'); + absoluteControlGainNumberElement.val(FC.ADVANCED_TUNING.absoluteControlGain).trigger('input'); - $('.pid_tuning input[name="dMinRoll"]').val(FC.ADVANCED_TUNING.dMinRoll); - $('.pid_tuning input[name="dMinPitch"]').val(FC.ADVANCED_TUNING.dMinPitch); - $('.pid_tuning input[name="dMinYaw"]').val(FC.ADVANCED_TUNING.dMinYaw); - $('.dminGroup input[name="dMinGain"]').val(FC.ADVANCED_TUNING.dMinGain); - $('.dminGroup input[name="dMinAdvance"]').val(FC.ADVANCED_TUNING.dMinAdvance); + // Throttle Boost + const throttleBoostNumberElement = $('input[name="throttleBoost-number"]'); + throttleBoostNumberElement.val(FC.ADVANCED_TUNING.throttleBoost).trigger('input'); - $('input[id="useIntegratedYaw"]').prop('checked', FC.ADVANCED_TUNING.useIntegratedYaw !== 0); - //dmin column - $('#pid_main .pid_titlebar2 th').attr('colspan', 6); - } else { - $('.throttle_limit').hide(); + // Acro Trainer + const acroTrainerAngleLimitNumberElement = $('input[name="acroTrainerAngleLimit-number"]'); + acroTrainerAngleLimitNumberElement.val(FC.ADVANCED_TUNING.acroTrainerAngleLimit).trigger('input'); - $('.gyroLowpassDynLegacy').hide(); - $('.dtermLowpassDynLegacy').hide(); - $('.dtermLowpass2TypeGroup').hide(); + // Yaw D + $('.pid_tuning .YAW input[name="d"]').val(FC.PIDS[2][2]); // PID Yaw D - $('.dminGroup').hide(); - $('.dMinDisabledNote').hide(); - //dmin column - $('#pid_main tr :nth-child(5)').hide(); + // Feedforward + $('.pid_tuning .ROLL input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardRoll); + $('.pid_tuning .PITCH input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardPitch); + $('.pid_tuning .YAW input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardYaw); + $('#pid_main .pid_titlebar2 th').attr('colspan', 5); - $('.integratedYaw').hide(); + const feedforwardTransitionNumberElement = $('input[name="feedforwardTransition-number"]'); + feedforwardTransitionNumberElement.val(Number.parseFloat(FC.ADVANCED_TUNING.feedforwardTransition / 100).toFixed(2)); + + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + // AntiGravity Mode + const antiGravityModeSelect = $('.antigravity select[id="antiGravityMode"]'); + + antiGravityModeSelect.on('change', function () { + const antiGravityModeValue = antiGravityModeSelect.val(); + + // Smooth removes threshold + $('.antiGravityThres').toggle(antiGravityModeValue !== 0); + }); + + antiGravityModeSelect.val(FC.ADVANCED_TUNING.antiGravityMode).trigger('change'); } + $('select[id="throttleLimitType"]').val(FC.RC_TUNING.throttleLimitType); + $('.throttle_limit input[name="throttleLimitPercent"]').val(FC.RC_TUNING.throttleLimitPercent); + + $('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz); + $('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').val(FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz); + $('.pid_filter select[name="gyroLowpassDynType"]').val(FC.FILTER_CONFIG.gyro_lowpass_type); + + $('.pid_filter input[name="dtermLowpassDynMinFrequency"]').val(FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz); + $('.pid_filter input[name="dtermLowpassDynMaxFrequency"]').val(FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz); + $('.pid_filter select[name="dtermLowpassDynType"]').val(FC.FILTER_CONFIG.dterm_lowpass_type); + + $('.pid_tuning input[name="dMinRoll"]').val(FC.ADVANCED_TUNING.dMinRoll); + $('.pid_tuning input[name="dMinPitch"]').val(FC.ADVANCED_TUNING.dMinPitch); + $('.pid_tuning input[name="dMinYaw"]').val(FC.ADVANCED_TUNING.dMinYaw); + $('.dminGroup input[name="dMinGain"]').val(FC.ADVANCED_TUNING.dMinGain); + $('.dminGroup input[name="dMinAdvance"]').val(FC.ADVANCED_TUNING.dMinAdvance); + + $('input[id="useIntegratedYaw"]').prop('checked', FC.ADVANCED_TUNING.useIntegratedYaw !== 0); + //dmin column + $('#pid_main .pid_titlebar2 th').attr('colspan', 6); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { $('.smartfeedforward').hide(); @@ -623,14 +530,10 @@ pid_tuning.initialize = function (callback) { $('.vbatSagCompensation').hide(); $('.thrustLinearization').hide(); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - $('.pid_tuning .ROLL input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardRoll > 0 ? FC.ADVANCED_TUNING.feedforwardRoll : PID_DEFAULT[4]); - $('.pid_tuning .PITCH input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardPitch > 0 ? FC.ADVANCED_TUNING.feedforwardPitch : PID_DEFAULT[9]); - $('.pid_tuning .YAW input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardYaw > 0 ? FC.ADVANCED_TUNING.feedforwardYaw : PID_DEFAULT[14]); - $('span.feedforwardOption').hide(); - } else { - $('.feedforwardGroup').hide(); - } + $('.pid_tuning .ROLL input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardRoll > 0 ? FC.ADVANCED_TUNING.feedforwardRoll : PID_DEFAULT[4]); + $('.pid_tuning .PITCH input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardPitch > 0 ? FC.ADVANCED_TUNING.feedforwardPitch : PID_DEFAULT[9]); + $('.pid_tuning .YAW input[name="f"]').val(FC.ADVANCED_TUNING.feedforwardYaw > 0 ? FC.ADVANCED_TUNING.feedforwardYaw : PID_DEFAULT[14]); + $('span.feedforwardOption').hide(); } $('input[id="useIntegratedYaw"]').change(function() { @@ -712,54 +615,52 @@ pid_tuning.initialize = function (callback) { }).change(); // dMinSwitch toggle - renamed to Dynamic Damping and disabled in 4.3 - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - const dMinSwitch = $('#dMinSwitch'); + const dMinSwitch = $('#dMinSwitch'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - const box = document.getElementById('dMinSwitch'); - if (box.parentNode) { - box.parentNode.removeChild(box); - } - $('.dMinDisabledNote').hide(); - } else { - dMinSwitch.prop('checked', FC.ADVANCED_TUNING.dMinRoll > 0 || FC.ADVANCED_TUNING.dMinPitch > 0 || FC.ADVANCED_TUNING.dMinYaw > 0); - - dMinSwitch.on('change', function() { - const checked = $(this).is(':checked'); - - if (checked) { - if ($('.pid_tuning input[name="dMinRoll"]').val() == 0 && $('.pid_tuning input[name="dMinPitch"]').val() == 0 && $('.pid_tuning input[name="dMinYaw"]').val() == 0) { - // when enabling dmin set its value based on 0.57x of actual dmax, dmin is limited to 100 - $('.pid_tuning input[name="dMinRoll"]').val(Math.min(Math.round($('.pid_tuning .ROLL input[name="d"]').val() * 0.57), 100)); - $('.pid_tuning input[name="dMinPitch"]').val(Math.min(Math.round($('.pid_tuning .PITCH input[name="d"]').val() * 0.57), 100)); - $('.pid_tuning input[name="dMinYaw"]').val(Math.min(Math.round($('.pid_tuning .YAW input[name="d"]').val() * 0.57), 100)); - if (semver.eq(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - $('.pid_tuning input[name="dMinRoll"]').val(Math.min(Math.round($('.pid_tuning .ROLL input[name="d"]').val() * 0.65), 100)); - $('.pid_tuning input[name="dMinPitch"]').val(Math.min(Math.round($('.pid_tuning .PITCH input[name="d"]').val() * 0.65), 100)); - $('.pid_tuning input[name="dMinYaw"]').val(Math.min(Math.round($('.pid_tuning .YAW input[name="d"]').val() * 0.65), 100)); - } - } else { - $('.pid_tuning input[name="dMinRoll"]').val(FC.ADVANCED_TUNING.dMinRoll); - $('.pid_tuning input[name="dMinPitch"]').val(FC.ADVANCED_TUNING.dMinPitch); - $('.pid_tuning input[name="dMinYaw"]').val(FC.ADVANCED_TUNING.dMinYaw); - } - $('.dMinDisabledNote').hide(); - $('.dminGroup .suboption').show(); - $('#pid_main tr :nth-child(5)').show(); - $('#pid_main .pid_titlebar2 th').attr('colspan', 6); - $('.derivativeText').text(i18n.getMessage("pidTuningDMax")); - } else { - $('.dMinDisabledNote').show(); - $('.dminGroup .suboption').hide(); - $('#pid_main tr :nth-child(5)').hide(); - $('#pid_main .pid_titlebar2 th').attr('colspan', 5); - $('.derivativeText').text(i18n.getMessage("pidTuningDerivative")); - $('.pid_tuning input[name="dMinRoll"]').val(0); - $('.pid_tuning input[name="dMinPitch"]').val(0); - $('.pid_tuning input[name="dMinYaw"]').val(0); - } - }).trigger('change'); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + const box = document.getElementById('dMinSwitch'); + if (box.parentNode) { + box.parentNode.removeChild(box); } + $('.dMinDisabledNote').hide(); + } else { + dMinSwitch.prop('checked', FC.ADVANCED_TUNING.dMinRoll > 0 || FC.ADVANCED_TUNING.dMinPitch > 0 || FC.ADVANCED_TUNING.dMinYaw > 0); + + dMinSwitch.on('change', function() { + const checked = $(this).is(':checked'); + + if (checked) { + if ($('.pid_tuning input[name="dMinRoll"]').val() == 0 && $('.pid_tuning input[name="dMinPitch"]').val() == 0 && $('.pid_tuning input[name="dMinYaw"]').val() == 0) { + // when enabling dmin set its value based on 0.57x of actual dmax, dmin is limited to 100 + $('.pid_tuning input[name="dMinRoll"]').val(Math.min(Math.round($('.pid_tuning .ROLL input[name="d"]').val() * 0.57), 100)); + $('.pid_tuning input[name="dMinPitch"]').val(Math.min(Math.round($('.pid_tuning .PITCH input[name="d"]').val() * 0.57), 100)); + $('.pid_tuning input[name="dMinYaw"]').val(Math.min(Math.round($('.pid_tuning .YAW input[name="d"]').val() * 0.57), 100)); + if (semver.eq(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + $('.pid_tuning input[name="dMinRoll"]').val(Math.min(Math.round($('.pid_tuning .ROLL input[name="d"]').val() * 0.65), 100)); + $('.pid_tuning input[name="dMinPitch"]').val(Math.min(Math.round($('.pid_tuning .PITCH input[name="d"]').val() * 0.65), 100)); + $('.pid_tuning input[name="dMinYaw"]').val(Math.min(Math.round($('.pid_tuning .YAW input[name="d"]').val() * 0.65), 100)); + } + } else { + $('.pid_tuning input[name="dMinRoll"]').val(FC.ADVANCED_TUNING.dMinRoll); + $('.pid_tuning input[name="dMinPitch"]').val(FC.ADVANCED_TUNING.dMinPitch); + $('.pid_tuning input[name="dMinYaw"]').val(FC.ADVANCED_TUNING.dMinYaw); + } + $('.dMinDisabledNote').hide(); + $('.dminGroup .suboption').show(); + $('#pid_main tr :nth-child(5)').show(); + $('#pid_main .pid_titlebar2 th').attr('colspan', 6); + $('.derivativeText').text(i18n.getMessage("pidTuningDMax")); + } else { + $('.dMinDisabledNote').show(); + $('.dminGroup .suboption').hide(); + $('#pid_main tr :nth-child(5)').hide(); + $('#pid_main .pid_titlebar2 th').attr('colspan', 5); + $('.derivativeText').text(i18n.getMessage("pidTuningDerivative")); + $('.pid_tuning input[name="dMinRoll"]').val(0); + $('.pid_tuning input[name="dMinPitch"]').val(0); + $('.pid_tuning input[name="dMinYaw"]').val(0); + } + }).trigger('change'); } $('input[id="gyroNotch1Enabled"]').change(function() { @@ -1211,102 +1112,82 @@ pid_tuning.initialize = function (callback) { FC.ADVANCED_TUNING.vbatPidCompensation = value; } - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - FC.ADVANCED_TUNING.deltaMethod = $('#pid-tuning .delta select').val(); - } + FC.ADVANCED_TUNING.deltaMethod = $('#pid-tuning .delta select').val(); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - FC.ADVANCED_TUNING.dtermSetpointTransition = parseInt($('input[name="dtermSetpointTransition-number"]').val() * 100); - FC.ADVANCED_TUNING.dtermSetpointWeight = parseInt($('input[name="dtermSetpoint-number"]').val() * 100); + FC.ADVANCED_TUNING.dtermSetpointTransition = parseInt($('input[name="dtermSetpointTransition-number"]').val() * 100); + FC.ADVANCED_TUNING.dtermSetpointWeight = parseInt($('input[name="dtermSetpoint-number"]').val() * 100); - FC.FILTER_CONFIG.gyro_notch_hz = parseInt($('.pid_filter input[name="gyroNotch1Frequency"]').val()); - FC.FILTER_CONFIG.gyro_notch_cutoff = parseInt($('.pid_filter input[name="gyroNotch1Cutoff"]').val()); - FC.FILTER_CONFIG.dterm_notch_hz = parseInt($('.pid_filter input[name="dTermNotchFrequency"]').val()); - FC.FILTER_CONFIG.dterm_notch_cutoff = parseInt($('.pid_filter input[name="dTermNotchCutoff"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, "1.21.0")) { - FC.FILTER_CONFIG.gyro_notch2_hz = parseInt($('.pid_filter input[name="gyroNotch2Frequency"]').val()); - FC.FILTER_CONFIG.gyro_notch2_cutoff = parseInt($('.pid_filter input[name="gyroNotch2Cutoff"]').val()); - } - } + FC.FILTER_CONFIG.gyro_notch_hz = parseInt($('.pid_filter input[name="gyroNotch1Frequency"]').val()); + FC.FILTER_CONFIG.gyro_notch_cutoff = parseInt($('.pid_filter input[name="gyroNotch1Cutoff"]').val()); + FC.FILTER_CONFIG.dterm_notch_hz = parseInt($('.pid_filter input[name="dTermNotchFrequency"]').val()); + FC.FILTER_CONFIG.dterm_notch_cutoff = parseInt($('.pid_filter input[name="dTermNotchCutoff"]').val()); + FC.FILTER_CONFIG.gyro_notch2_hz = parseInt($('.pid_filter input[name="gyroNotch2Frequency"]').val()); + FC.FILTER_CONFIG.gyro_notch2_cutoff = parseInt($('.pid_filter input[name="gyroNotch2Cutoff"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, "1.24.0")) { - FC.ADVANCED_TUNING.levelAngleLimit = parseInt($('.pid_tuning input[name="angleLimit"]').val()); - - if (semver.lte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.ADVANCED_TUNING.levelSensitivity = parseInt($('.pid_tuning input[name="sensitivity"]').val()); - } - } + FC.ADVANCED_TUNING.levelAngleLimit = parseInt($('.pid_tuning input[name="angleLimit"]').val()); const antiGravityGain = $('.antigravity input[name="itermAcceleratorGain"]'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - FC.FILTER_CONFIG.dterm_lowpass_type = parseInt($('.pid_filter select[name="dtermLowpassType"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - FC.ADVANCED_TUNING.antiGravityGain = parseInt(antiGravityGain.val() * 10); - } else { - FC.ADVANCED_TUNING.itermThrottleThreshold = parseInt($('.antigravity input[name="itermThrottleThreshold"]').val()); - FC.ADVANCED_TUNING.itermAcceleratorGain = parseInt(antiGravityGain.val() * 1000); + FC.FILTER_CONFIG.dterm_lowpass_type = parseInt($('.pid_filter select[name="dtermLowpassType"]').val()); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + FC.ADVANCED_TUNING.antiGravityGain = parseInt(antiGravityGain.val() * 10); + } else { + FC.ADVANCED_TUNING.itermThrottleThreshold = parseInt($('.antigravity input[name="itermThrottleThreshold"]').val()); + FC.ADVANCED_TUNING.itermAcceleratorGain = parseInt(antiGravityGain.val() * 1000); + } + + FC.FILTER_CONFIG.gyro_lowpass2_hz = parseInt($('.pid_filter input[name="gyroLowpass2Frequency"]').val()); + FC.FILTER_CONFIG.gyro_lowpass_type = parseInt($('.pid_filter select[name="gyroLowpassType"]').val()); + FC.FILTER_CONFIG.gyro_lowpass2_type = parseInt($('.pid_filter select[name="gyroLowpass2Type"]').val()); + FC.FILTER_CONFIG.dterm_lowpass2_hz = parseInt($('.pid_filter input[name="dtermLowpass2Frequency"]').val()); + FC.FILTER_CONFIG.dterm_lowpass2_type = parseInt($('.pid_filter select[name="dtermLowpass2Type"]').val()); + + FC.ADVANCED_TUNING.itermRotation = $('input[id="itermrotation"]').is(':checked') ? 1 : 0; + FC.ADVANCED_TUNING.smartFeedforward = $('input[id="smartfeedforward"]').is(':checked') ? 1 : 0; + + FC.ADVANCED_TUNING.itermRelax = $('input[id="itermrelax"]').is(':checked') ? $('select[id="itermrelaxAxes"]').val() : 0; + FC.ADVANCED_TUNING.itermRelaxType = $('select[id="itermrelaxType"]').val(); + FC.ADVANCED_TUNING.itermRelaxCutoff = parseInt($('input[name="itermRelaxCutoff"]').val()); + + FC.ADVANCED_TUNING.absoluteControlGain = $('input[name="absoluteControlGain-number"]').val(); + + FC.ADVANCED_TUNING.throttleBoost = $('input[name="throttleBoost-number"]').val(); + + FC.ADVANCED_TUNING.acroTrainerAngleLimit = $('input[name="acroTrainerAngleLimit-number"]').val(); + + FC.ADVANCED_TUNING.feedforwardRoll = parseInt($('.pid_tuning .ROLL input[name="f"]').val()); + FC.ADVANCED_TUNING.feedforwardPitch = parseInt($('.pid_tuning .PITCH input[name="f"]').val()); + FC.ADVANCED_TUNING.feedforwardYaw = parseInt($('.pid_tuning .YAW input[name="f"]').val()); + + FC.ADVANCED_TUNING.feedforwardTransition = parseInt($('input[name="feedforwardTransition-number"]').val() * 100); + + FC.ADVANCED_TUNING.antiGravityMode = semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) ? $('select[id="antiGravityMode"]').val() : 0; + + FC.RC_TUNING.throttleLimitType = $('select[id="throttleLimitType"]').val(); + FC.RC_TUNING.throttleLimitPercent = parseInt($('.throttle_limit input[name="throttleLimitPercent"]').val()); + + FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz = parseInt($('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val()); + FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz = parseInt($('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').val()); + FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz = parseInt($('.pid_filter input[name="dtermLowpassDynMinFrequency"]').val()); + FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz = parseInt($('.pid_filter input[name="dtermLowpassDynMaxFrequency"]').val()); + + if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + if (FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz > 0 && FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz < FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz ) { + FC.FILTER_CONFIG.gyro_lowpass_type = $('.pid_filter select[name="gyroLowpassDynType"]').val(); + } + if (FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz > 0 && FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz < FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz ) { + FC.FILTER_CONFIG.dterm_lowpass_type = $('.pid_filter select[name="dtermLowpassDynType"]').val(); } } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - FC.FILTER_CONFIG.gyro_lowpass2_hz = parseInt($('.pid_filter input[name="gyroLowpass2Frequency"]').val()); - FC.FILTER_CONFIG.gyro_lowpass_type = parseInt($('.pid_filter select[name="gyroLowpassType"]').val()); - FC.FILTER_CONFIG.gyro_lowpass2_type = parseInt($('.pid_filter select[name="gyroLowpass2Type"]').val()); - FC.FILTER_CONFIG.dterm_lowpass2_hz = parseInt($('.pid_filter input[name="dtermLowpass2Frequency"]').val()); - FC.FILTER_CONFIG.dterm_lowpass2_type = parseInt($('.pid_filter select[name="dtermLowpass2Type"]').val()); - } + FC.ADVANCED_TUNING.dMinRoll = parseInt($('.pid_tuning input[name="dMinRoll"]').val()); + FC.ADVANCED_TUNING.dMinPitch = parseInt($('.pid_tuning input[name="dMinPitch"]').val()); + FC.ADVANCED_TUNING.dMinYaw = parseInt($('.pid_tuning input[name="dMinYaw"]').val()); + FC.ADVANCED_TUNING.dMinGain = parseInt($('.dminGroup input[name="dMinGain"]').val()); + FC.ADVANCED_TUNING.dMinAdvance = parseInt($('.dminGroup input[name="dMinAdvance"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { + FC.ADVANCED_TUNING.useIntegratedYaw = $('input[id="useIntegratedYaw"]').is(':checked') ? 1 : 0; - FC.ADVANCED_TUNING.itermRotation = $('input[id="itermrotation"]').is(':checked') ? 1 : 0; - FC.ADVANCED_TUNING.smartFeedforward = $('input[id="smartfeedforward"]').is(':checked') ? 1 : 0; - - FC.ADVANCED_TUNING.itermRelax = $('input[id="itermrelax"]').is(':checked') ? $('select[id="itermrelaxAxes"]').val() : 0; - FC.ADVANCED_TUNING.itermRelaxType = $('select[id="itermrelaxType"]').val(); - FC.ADVANCED_TUNING.itermRelaxCutoff = parseInt($('input[name="itermRelaxCutoff"]').val()); - - FC.ADVANCED_TUNING.absoluteControlGain = $('input[name="absoluteControlGain-number"]').val(); - - FC.ADVANCED_TUNING.throttleBoost = $('input[name="throttleBoost-number"]').val(); - - FC.ADVANCED_TUNING.acroTrainerAngleLimit = $('input[name="acroTrainerAngleLimit-number"]').val(); - - FC.ADVANCED_TUNING.feedforwardRoll = parseInt($('.pid_tuning .ROLL input[name="f"]').val()); - FC.ADVANCED_TUNING.feedforwardPitch = parseInt($('.pid_tuning .PITCH input[name="f"]').val()); - FC.ADVANCED_TUNING.feedforwardYaw = parseInt($('.pid_tuning .YAW input[name="f"]').val()); - - FC.ADVANCED_TUNING.feedforwardTransition = parseInt($('input[name="feedforwardTransition-number"]').val() * 100); - - FC.ADVANCED_TUNING.antiGravityMode = semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45) ? $('select[id="antiGravityMode"]').val() : 0; - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - FC.RC_TUNING.throttleLimitType = $('select[id="throttleLimitType"]').val(); - FC.RC_TUNING.throttleLimitPercent = parseInt($('.throttle_limit input[name="throttleLimitPercent"]').val()); - - FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz = parseInt($('.pid_filter input[name="gyroLowpassDynMinFrequency"]').val()); - FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz = parseInt($('.pid_filter input[name="gyroLowpassDynMaxFrequency"]').val()); - FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz = parseInt($('.pid_filter input[name="dtermLowpassDynMinFrequency"]').val()); - FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz = parseInt($('.pid_filter input[name="dtermLowpassDynMaxFrequency"]').val()); - - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - if (FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz > 0 && FC.FILTER_CONFIG.gyro_lowpass_dyn_min_hz < FC.FILTER_CONFIG.gyro_lowpass_dyn_max_hz ) { - FC.FILTER_CONFIG.gyro_lowpass_type = $('.pid_filter select[name="gyroLowpassDynType"]').val(); - } - if (FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz > 0 && FC.FILTER_CONFIG.dterm_lowpass_dyn_min_hz < FC.FILTER_CONFIG.dterm_lowpass_dyn_max_hz ) { - FC.FILTER_CONFIG.dterm_lowpass_type = $('.pid_filter select[name="dtermLowpassDynType"]').val(); - } - } - - FC.ADVANCED_TUNING.dMinRoll = parseInt($('.pid_tuning input[name="dMinRoll"]').val()); - FC.ADVANCED_TUNING.dMinPitch = parseInt($('.pid_tuning input[name="dMinPitch"]').val()); - FC.ADVANCED_TUNING.dMinYaw = parseInt($('.pid_tuning input[name="dMinYaw"]').val()); - FC.ADVANCED_TUNING.dMinGain = parseInt($('.dminGroup input[name="dMinGain"]').val()); - FC.ADVANCED_TUNING.dMinAdvance = parseInt($('.dminGroup input[name="dMinAdvance"]').val()); - - FC.ADVANCED_TUNING.useIntegratedYaw = $('input[id="useIntegratedYaw"]').is(':checked') ? 1 : 0; - } if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { FC.FILTER_CONFIG.dyn_notch_range = parseInt($('.pid_filter select[name="dynamicNotchRange"]').val()); @@ -1382,12 +1263,6 @@ pid_tuning.initialize = function (callback) { // Show titles and other elements needed by the PID $(`.needed_by_${elementPid}`).show(); }); - - // Special case - if (semver.lt(FC.CONFIG.apiVersion, "1.24.0")) { - $('#pid_sensitivity').hide(); - } - } function hideUnusedPids() { @@ -1449,17 +1324,12 @@ pid_tuning.initialize = function (callback) { return value; } - let useLegacyCurve = false; - if (!semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - useLegacyCurve = true; - } + const useLegacyCurve = true; self.rateCurve = new RateCurve(useLegacyCurve); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - $('.pid_tuning input[name="sensitivity"]').hide(); - $('.pid_tuning .levelSensitivityHeader').empty(); - } + $('.pid_tuning input[name="sensitivity"]').hide(); + $('.pid_tuning .levelSensitivityHeader').empty(); function printMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo, deadband, limit, maxAngularVelElement) { const maxAngularVel = self.rateCurve.getMaxAngularVel(rate, rcRate, rcExpo, useSuperExpo, deadband, limit).toFixed(0); @@ -1480,13 +1350,7 @@ pid_tuning.initialize = function (callback) { TABS.pid_tuning.isHtmlProcessing = true; FC.FEATURE_CONFIG.features.generateElements($('.tab-pid_tuning .features')); - if (semver.lt(FC.CONFIG.apiVersion, "1.16.0") || semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - $('.tab-pid_tuning .pidTuningSuperexpoRates').hide(); - } - - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - $('input[name="dtermSetpoint-number"]').attr('max', self.SETPOINT_WEIGHT_RANGE_LEGACY); - } + $('.tab-pid_tuning .pidTuningSuperexpoRates').hide(); // translate to user-selected language i18n.localizePage(); @@ -1500,7 +1364,7 @@ pid_tuning.initialize = function (callback) { $('.tab-pid_tuning .tab-container .filter').on('click', () => activateSubtab('filter')); function loadProfilesList() { - const numberOfProfiles = semver.gte(FC.CONFIG.apiVersion, "1.16.0") ? FC.CONFIG.numProfiles : 3; + const numberOfProfiles = FC.CONFIG.numProfiles; const profileElements = []; for (let i = 0; i < numberOfProfiles; i++) { @@ -1512,10 +1376,6 @@ pid_tuning.initialize = function (callback) { function loadRateProfilesList() { let numberOfRateProfiles = 6; - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - numberOfRateProfiles = 3; - } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { numberOfRateProfiles = 4; } @@ -1600,52 +1460,39 @@ pid_tuning.initialize = function (callback) { }); }); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - $('.tab-pid_tuning select[name="rate_profile"]').change(function () { - self.currentRateProfile = parseInt($(this).val()); - self.updating = true; - $(this).prop('disabled', 'true'); - MSP.promise(MSPCodes.MSP_SELECT_SETTING, [self.currentRateProfile + self.RATE_PROFILE_MASK]).then(function () { - self.refresh(function () { - self.updating = false; + $('.tab-pid_tuning select[name="rate_profile"]').change(function () { + self.currentRateProfile = parseInt($(this).val()); + self.updating = true; + $(this).prop('disabled', 'true'); + MSP.promise(MSPCodes.MSP_SELECT_SETTING, [self.currentRateProfile + self.RATE_PROFILE_MASK]).then(function () { + self.refresh(function () { + self.updating = false; - $('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', 'false'); - FC.CONFIG.rateProfile = self.currentRateProfile; - self.currentRates = self.rateCurve.getCurrentRates(); + $('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', 'false'); + FC.CONFIG.rateProfile = self.currentRateProfile; + self.currentRates = self.rateCurve.getCurrentRates(); - GUI.log(i18n.getMessage('pidTuningLoadedRateProfile', [self.currentRateProfile + 1])); - }); + GUI.log(i18n.getMessage('pidTuningLoadedRateProfile', [self.currentRateProfile + 1])); }); }); + }); - const dtermTransitionNumberElement = $('input[name="dtermSetpointTransition-number"]'); - const dtermTransitionWarningElement = $('#pid-tuning .dtermSetpointTransitionWarning'); + const dtermTransitionNumberElement = $('input[name="dtermSetpointTransition-number"]'); + const dtermTransitionWarningElement = $('#pid-tuning .dtermSetpointTransitionWarning'); - function checkUpdateDtermTransitionWarning(value) { - if (value > 0 && value < 0.1) { - dtermTransitionWarningElement.show(); - } else { - dtermTransitionWarningElement.hide(); - } + function checkUpdateDtermTransitionWarning(value) { + if (value > 0 && value < 0.1) { + dtermTransitionWarningElement.show(); + } else { + dtermTransitionWarningElement.hide(); } - checkUpdateDtermTransitionWarning(dtermTransitionNumberElement.val()); - - //Use 'input' event for coupled controls to allow synchronized update - dtermTransitionNumberElement.on('input', function () { - checkUpdateDtermTransitionWarning($(this).val()); - }); - - } else { - $('.tab-pid_tuning .rate_profile').hide(); - - $('#pid-tuning .dtermSetpointTransition').hide(); - $('#pid-tuning .dtermSetpoint').hide(); } + checkUpdateDtermTransitionWarning(dtermTransitionNumberElement.val()); - if (!semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - $('#pid-tuning .delta').hide(); - $('.tab-pid_tuning .note').hide(); - } + //Use 'input' event for coupled controls to allow synchronized update + dtermTransitionNumberElement.on('input', function () { + checkUpdateDtermTransitionWarning($(this).val()); + }); // Add a name to each row of PIDs if empty $('.pid_tuning tr').each(function() { @@ -1664,13 +1511,12 @@ pid_tuning.initialize = function (callback) { const filterTypeValues = []; filterTypeValues.push("PT1"); filterTypeValues.push("BIQUAD"); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - filterTypeValues.push("FIR"); - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { filterTypeValues.push("PT2"); filterTypeValues.push("PT3"); } + return filterTypeValues; } @@ -1728,64 +1574,11 @@ pid_tuning.initialize = function (callback) { activateSubtab(self.activeSubtab); - const pidController_e = $('select[name="controller"]'); + $('.tab-pid_tuning div.controller').hide(); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - let pidControllerList; + self.updatePidControllerParameters(); - - if (semver.lt(FC.CONFIG.apiVersion, "1.14.0")) { - pidControllerList = [ - {name: "MultiWii (Old)"}, - {name: "MultiWii (rewrite)"}, - {name: "LuxFloat"}, - {name: "MultiWii (2.3 - latest)"}, - {name: "MultiWii (2.3 - hybrid)"}, - {name: "Harakiri"}, - ]; - } else if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) { - pidControllerList = [ - {name: ""}, - {name: "Integer"}, - {name: "Float"}, - ]; - } else { - pidControllerList = [ - {name: "Legacy"}, - {name: "Betaflight"}, - ]; - } - - for (let i = 0; i < pidControllerList.length; i++) { - pidController_e.append(``); - } - - if (semver.gte(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_MIN_SUPPORTED_PID_CONTROLLER_CHANGE)) { - pidController_e.val(FC.PID.controller); - - self.updatePidControllerParameters(); - } else { - GUI.log(i18n.getMessage('pidTuningUpgradeFirmwareToChangePidController', [FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_MIN_SUPPORTED_PID_CONTROLLER_CHANGE])); - - pidController_e.empty(); - pidController_e.append(''); - - pidController_e.prop('disabled', true); - } - } else { - $('.tab-pid_tuning div.controller').hide(); - - self.updatePidControllerParameters(); - } - - if (semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - $('.tpa-old .tpa-breakpoint').hide(); - - $('.pid_tuning .roll_rate').hide(); - $('.pid_tuning .pitch_rate').hide(); - } else { - $('.pid_tuning .roll_pitch_rate').hide(); - } + $('.pid_tuning .roll_pitch_rate').hide(); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { $('.tpa-old').hide(); @@ -1793,16 +1586,11 @@ pid_tuning.initialize = function (callback) { $('.tpa').hide(); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - $('.pid_tuning .bracket').hide(); - $('.pid_tuning input[name=rc_rate]').parent().attr('class', 'pid_data'); - $('.pid_tuning input[name=rc_rate]').parent().attr('rowspan', 1); - $('.pid_tuning input[name=rc_expo]').parent().attr('class', 'pid_data'); - $('.pid_tuning input[name=rc_expo]').parent().attr('rowspan', 1); - } else { - $('.pid_tuning input[name=rc_rate_pitch]').parent().hide(); - $('.pid_tuning input[name=rc_pitch_expo]').parent().hide(); - } + $('.pid_tuning .bracket').hide(); + $('.pid_tuning input[name=rc_rate]').parent().attr('class', 'pid_data'); + $('.pid_tuning input[name=rc_rate]').parent().attr('rowspan', 1); + $('.pid_tuning input[name=rc_expo]').parent().attr('class', 'pid_data'); + $('.pid_tuning input[name=rc_expo]').parent().attr('rowspan', 1); if (useLegacyCurve) { $('.new_rates').hide(); @@ -1839,31 +1627,12 @@ pid_tuning.initialize = function (callback) { updateNeeded = true; } - if (targetElement.attr('name') === 'rc_rate' && semver.lt(FC.CONFIG.apiVersion, "1.16.0")) { - self.currentRates.rc_rate_yaw = targetValue; - } - - if (targetElement.attr('name') === 'roll_pitch_rate' && semver.lt(FC.CONFIG.apiVersion, "1.7.0")) { - self.currentRates.roll_rate = targetValue; - self.currentRates.pitch_rate = targetValue; - - updateNeeded = true; - } - if (targetElement.attr('name') === 'SUPEREXPO_RATES') { self.currentRates.superexpo = targetElement.is(':checked'); updateNeeded = true; } - if (targetElement.attr('name') === 'rc_rate' && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - self.currentRates.rc_rate_pitch = targetValue; - } - - if (targetElement.attr('name') === 'rc_expo' && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - self.currentRates.rc_pitch_expo = targetValue; - } - if (targetElement.attr('id') === 'ratesType' && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { self.changeRatesType(targetValue); @@ -2032,73 +1801,67 @@ pid_tuning.initialize = function (callback) { const DIALOG_MODE_RATEPROFILE = 1; let dialogCopyProfileMode; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { + const selectProfile = $('.selectProfile'); + const selectRateProfile = $('.selectRateProfile'); - const selectProfile = $('.selectProfile'); - const selectRateProfile = $('.selectRateProfile'); + $.each(selectProfileValues, function(key, value) { + if (key !== FC.CONFIG.profile) { + selectProfile.append(new Option(value, key)); + } + }); + $.each(selectRateProfileValues, function(key, value) { + if (key !== FC.CONFIG.rateProfile) { + selectRateProfile.append(new Option(value, key)); + } + }); - $.each(selectProfileValues, function(key, value) { - if (key !== FC.CONFIG.profile) { - selectProfile.append(new Option(value, key)); - } - }); - $.each(selectRateProfileValues, function(key, value) { - if (key !== FC.CONFIG.rateProfile) { - selectRateProfile.append(new Option(value, key)); - } - }); + $('.copyprofilebtn').click(function() { + $('.dialogCopyProfile').find('.contentProfile').show(); + $('.dialogCopyProfile').find('.contentRateProfile').hide(); + dialogCopyProfileMode = DIALOG_MODE_PROFILE; + dialogCopyProfile.showModal(); + }); - $('.copyprofilebtn').click(function() { - $('.dialogCopyProfile').find('.contentProfile').show(); - $('.dialogCopyProfile').find('.contentRateProfile').hide(); - dialogCopyProfileMode = DIALOG_MODE_PROFILE; - dialogCopyProfile.showModal(); - }); + $('.copyrateprofilebtn').click(function() { + $('.dialogCopyProfile').find('.contentProfile').hide(); + $('.dialogCopyProfile').find('.contentRateProfile').show(); + dialogCopyProfileMode = DIALOG_MODE_RATEPROFILE; + dialogCopyProfile.showModal(); + }); - $('.copyrateprofilebtn').click(function() { - $('.dialogCopyProfile').find('.contentProfile').hide(); - $('.dialogCopyProfile').find('.contentRateProfile').show(); - dialogCopyProfileMode = DIALOG_MODE_RATEPROFILE; - dialogCopyProfile.showModal(); - }); + $('.dialogCopyProfile-cancelbtn').click(function() { + dialogCopyProfile.close(); + }); - $('.dialogCopyProfile-cancelbtn').click(function() { + $('.dialogCopyProfile-confirmbtn').click(function() { + switch(dialogCopyProfileMode) { + case DIALOG_MODE_PROFILE: + FC.COPY_PROFILE.type = DIALOG_MODE_PROFILE; // 0 = pid profile + FC.COPY_PROFILE.dstProfile = parseInt(selectProfile.val()); + FC.COPY_PROFILE.srcProfile = FC.CONFIG.profile; + + MSP.send_message(MSPCodes.MSP_COPY_PROFILE, mspHelper.crunch(MSPCodes.MSP_COPY_PROFILE), false, close_dialog); + + break; + + case DIALOG_MODE_RATEPROFILE: + FC.COPY_PROFILE.type = DIALOG_MODE_RATEPROFILE; // 1 = rate profile + FC.COPY_PROFILE.dstProfile = parseInt(selectRateProfile.val()); + FC.COPY_PROFILE.srcProfile = FC.CONFIG.rateProfile; + + MSP.send_message(MSPCodes.MSP_COPY_PROFILE, mspHelper.crunch(MSPCodes.MSP_COPY_PROFILE), false, close_dialog); + + break; + + default: + close_dialog(); + break; + } + + function close_dialog() { dialogCopyProfile.close(); - }); - - $('.dialogCopyProfile-confirmbtn').click(function() { - switch(dialogCopyProfileMode) { - case DIALOG_MODE_PROFILE: - FC.COPY_PROFILE.type = DIALOG_MODE_PROFILE; // 0 = pid profile - FC.COPY_PROFILE.dstProfile = parseInt(selectProfile.val()); - FC.COPY_PROFILE.srcProfile = FC.CONFIG.profile; - - MSP.send_message(MSPCodes.MSP_COPY_PROFILE, mspHelper.crunch(MSPCodes.MSP_COPY_PROFILE), false, close_dialog); - - break; - - case DIALOG_MODE_RATEPROFILE: - FC.COPY_PROFILE.type = DIALOG_MODE_RATEPROFILE; // 1 = rate profile - FC.COPY_PROFILE.dstProfile = parseInt(selectRateProfile.val()); - FC.COPY_PROFILE.srcProfile = FC.CONFIG.rateProfile; - - MSP.send_message(MSPCodes.MSP_COPY_PROFILE, mspHelper.crunch(MSPCodes.MSP_COPY_PROFILE), false, close_dialog); - - break; - - default: - close_dialog(); - break; - } - - function close_dialog() { - dialogCopyProfile.close(); - } - }); - } else { - $('.copyprofilebtn').hide(); - $('.copyrateprofilebtn').hide(); - } + } + }); /* * TuningSliders @@ -2454,37 +2217,16 @@ pid_tuning.initialize = function (callback) { $('.tuningHelpSliders').hide(); } - if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) { - $('#pid-tuning .delta select').change(function() { - self.setDirty(true); - }); - } - - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - pidController_e.change(function () { - self.setDirty(true); - - self.updatePidControllerParameters(); - }); - } + $('#pid-tuning .delta select').change(function() { + self.setDirty(true); + }); // update == save. $('a.update').click(function () { form_to_pid_and_rc(); self.updating = true; - Promise.resolve(true) - .then(function () { - let promise; - if (semver.gte(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_MIN_SUPPORTED_PID_CONTROLLER_CHANGE) && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - FC.PID.controller = pidController_e.val(); - promise = MSP.promise(MSPCodes.MSP_SET_PID_CONTROLLER, mspHelper.crunch(MSPCodes.MSP_SET_PID_CONTROLLER)); - } else { - console.log(`Unsupported API version: ${FC.CONFIG.apiVersion}`); - } - return promise; - }) - .then(() => MSP.promise(MSPCodes.MSP_SET_PID, mspHelper.crunch(MSPCodes.MSP_SET_PID))) + MSP.promise(MSPCodes.MSP_SET_PID, mspHelper.crunch(MSPCodes.MSP_SET_PID)) .then(() => MSP.promise(MSPCodes.MSP_SET_PID_ADVANCED, mspHelper.crunch(MSPCodes.MSP_SET_PID_ADVANCED))) .then(() => { self.updatePIDColors(); @@ -2637,9 +2379,7 @@ pid_tuning.setDirty = function (isDirty) { self.dirty = isDirty; $('.tab-pid_tuning select[name="profile"]').prop('disabled', isDirty); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - $('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', isDirty); - } + $('.tab-pid_tuning select[name="rate_profile"]').prop('disabled', isDirty); }; pid_tuning.checkUpdateProfile = function (updateRateProfile) { @@ -2656,9 +2396,7 @@ pid_tuning.checkUpdateProfile = function (updateRateProfile) { } let changedRateProfile = false; - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0") - && updateRateProfile - && self.currentRateProfile !== FC.CONFIG.rateProfile) { + if (updateRateProfile && self.currentRateProfile !== FC.CONFIG.rateProfile) { self.setRateProfile(); changedRateProfile = true; @@ -2711,26 +2449,10 @@ pid_tuning.checkThrottle = function() { }; pid_tuning.updatePidControllerParameters = function () { - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_31) && $('.tab-pid_tuning select[name="controller"]').val() === '0') { - $('.pid_tuning .YAW_JUMP_PREVENTION').show(); - - $('#pid-tuning .delta').show(); - - $('#pid-tuning .dtermSetpointTransition').hide(); - $('#pid-tuning .dtermSetpoint').hide(); - } else { - $('.pid_tuning .YAW_JUMP_PREVENTION').hide(); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - $('#pid-tuning .dtermSetpointTransition').hide(); - $('#pid-tuning .dtermSetpoint').hide(); - } else { - $('#pid-tuning .dtermSetpointTransition').show(); - $('#pid-tuning .dtermSetpoint').show(); - } - - $('#pid-tuning .delta').hide(); - } + $('.pid_tuning .YAW_JUMP_PREVENTION').hide(); + $('#pid-tuning .dtermSetpointTransition').hide(); + $('#pid-tuning .dtermSetpoint').hide(); + $('#pid-tuning .delta').hide(); }; pid_tuning.updateRatesLabels = function() { diff --git a/src/js/tabs/ports.js b/src/js/tabs/ports.js index a9461db4..f06c69aa 100644 --- a/src/js/tabs/ports.js +++ b/src/js/tabs/ports.js @@ -20,39 +20,22 @@ ports.initialize = function (callback) { { name: 'BLACKBOX', groups: ['peripherals'], sharableWith: ['msp'], notSharableWith: ['telemetry'], maxPorts: 1 }, ]; - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - const ltmFunctionRule = {name: 'TELEMETRY_LTM', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['peripherals'], maxPorts: 1}; - functionRules.push(ltmFunctionRule); - } else { - const mspFunctionRule = {name: 'TELEMETRY_MSP', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['peripherals'], maxPorts: 1}; - functionRules.push(mspFunctionRule); - } + const ltmFunctionRule = {name: 'TELEMETRY_LTM', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['peripherals'], maxPorts: 1}; + functionRules.push(ltmFunctionRule); - if (semver.gte(FC.CONFIG.apiVersion, "1.18.0")) { - const mavlinkFunctionRule = {name: 'TELEMETRY_MAVLINK', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['peripherals'], maxPorts: 1}; - functionRules.push(mavlinkFunctionRule); - } + const mavlinkFunctionRule = {name: 'TELEMETRY_MAVLINK', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['peripherals'], maxPorts: 1}; + functionRules.push(mavlinkFunctionRule); - if (semver.gte(FC.CONFIG.apiVersion, "1.27.0")) { - functionRules.push({ name: 'IRC_TRAMP', groups: ['peripherals'], maxPorts: 1 }); - } + functionRules.push({ name: 'IRC_TRAMP', groups: ['peripherals'], maxPorts: 1 }); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - functionRules.push({ name: 'ESC_SENSOR', groups: ['sensors'], maxPorts: 1 }); - functionRules.push({ name: 'TBS_SMARTAUDIO', groups: ['peripherals'], maxPorts: 1 }); - } + functionRules.push({ name: 'ESC_SENSOR', groups: ['sensors'], maxPorts: 1 }); + functionRules.push({ name: 'TBS_SMARTAUDIO', groups: ['peripherals'], maxPorts: 1 }); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_32)) { - functionRules.push({ name: 'TELEMETRY_IBUS', groups: ['telemetry'], maxPorts: 1 }); - } + functionRules.push({ name: 'TELEMETRY_IBUS', groups: ['telemetry'], maxPorts: 1 }); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - functionRules.push({ name: 'RUNCAM_DEVICE_CONTROL', groups: ['peripherals'], maxPorts: 1 }); - } + functionRules.push({ name: 'RUNCAM_DEVICE_CONTROL', groups: ['peripherals'], maxPorts: 1 }); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - functionRules.push({ name: 'LIDAR_TF', groups: ['peripherals'], maxPorts: 1 }); - } + functionRules.push({ name: 'LIDAR_TF', groups: ['peripherals'], maxPorts: 1 }); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { functionRules.push({ name: 'FRSKY_OSD', groups: ['peripherals'], maxPorts: 1 }); @@ -74,12 +57,10 @@ ports.initialize = function (callback) { '115200', '230400', '250000', + '500000', + '1000000', ]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - mspBaudRates = mspBaudRates.concat(['500000', '1000000']); - } - const gpsBaudRates = [ 'AUTO', '9600', @@ -140,12 +121,6 @@ ports.initialize = function (callback) { function update_ui() { self.analyticsChanges = {}; - if (semver.lt(FC.CONFIG.apiVersion, "1.6.0")) { - - $(".tab-ports").removeClass("supported"); - return; - } - $(".tab-ports").addClass("supported"); const VCP_PORT_IDENTIFIER = 20; diff --git a/src/js/tabs/power.js b/src/js/tabs/power.js index 735a84a3..11b05cd8 100644 --- a/src/js/tabs/power.js +++ b/src/js/tabs/power.js @@ -1,4 +1,3 @@ -import semver from 'semver'; import { i18n } from '../localization'; const power = { @@ -54,13 +53,9 @@ power.initialize = function (callback) { $('#content').load("./tabs/power.html", process_html); } - this.supported = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_33); + this.supported = true; - if (!this.supported) { - load_html(); - } else { - load_status(); - } + load_status(); function updateDisplay(voltageDataSource, currentDataSource) { // voltage meters @@ -227,18 +222,16 @@ power.initialize = function (callback) { const elementBatteryConfiguration = templateBatteryConfiguration.clone(); destinationBatteryConfiguration.append(elementBatteryConfiguration); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - $('input[name="mincellvoltage"]').prop('step','0.01'); - $('input[name="maxcellvoltage"]').prop('step','0.01'); - $('input[name="warningcellvoltage"]').prop('step','0.01'); - } + $('input[name="mincellvoltage"]').prop('step','0.01'); + $('input[name="maxcellvoltage"]').prop('step','0.01'); + $('input[name="warningcellvoltage"]').prop('step','0.01'); $('input[name="mincellvoltage"]').val(FC.BATTERY_CONFIG.vbatmincellvoltage); $('input[name="maxcellvoltage"]').val(FC.BATTERY_CONFIG.vbatmaxcellvoltage); $('input[name="warningcellvoltage"]').val(FC.BATTERY_CONFIG.vbatwarningcellvoltage); $('input[name="capacity"]').val(FC.BATTERY_CONFIG.capacity); - const haveFc = (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_35) || (FC.CONFIG.boardType == 0 || FC.CONFIG.boardType == 2)); + const haveFc = FC.CONFIG.boardType === 0 || FC.CONFIG.boardType === 2; const batteryMeterTypes = [ i18n.getMessage('powerBatteryVoltageMeterTypeNone'), @@ -264,10 +257,7 @@ power.initialize = function (callback) { if (haveFc) { currentMeterTypes.push(i18n.getMessage('powerBatteryCurrentMeterTypeVirtual')); currentMeterTypes.push(i18n.getMessage('powerBatteryCurrentMeterTypeEsc')); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - currentMeterTypes.push(i18n.getMessage('powerBatteryCurrentMeterTypeMsp')); - } + currentMeterTypes.push(i18n.getMessage('powerBatteryCurrentMeterTypeMsp')); } let currentMeterType_e = $('select.currentmetersource'); @@ -495,19 +485,11 @@ power.initialize = function (callback) { } function save_voltage_config() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - mspHelper.sendVoltageConfig(save_amperage_config); - } else { - MSP.send_message(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG), false, save_amperage_config); - } + mspHelper.sendVoltageConfig(save_amperage_config); } function save_amperage_config() { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - mspHelper.sendCurrentConfig(save_to_eeprom); - } else { - MSP.send_message(MSPCodes.MSP_SET_CURRENT_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_CURRENT_METER_CONFIG), false, save_to_eeprom); - } + mspHelper.sendCurrentConfig(save_to_eeprom); } function save_to_eeprom() { diff --git a/src/js/tabs/receiver.js b/src/js/tabs/receiver.js index b7b6fc31..13673d6e 100644 --- a/src/js/tabs/receiver.js +++ b/src/js/tabs/receiver.js @@ -58,21 +58,11 @@ receiver.initialize = function (callback) { } function load_rc_configs() { - const nextCallback = load_rx_config; - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - MSP.send_message(MSPCodes.MSP_RC_DEADBAND, false, false, nextCallback); - } else { - nextCallback(); - } + MSP.send_message(MSPCodes.MSP_RC_DEADBAND, false, false, load_rx_config); } function load_rx_config() { - const nextCallback = load_mixer_config; - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - MSP.send_message(MSPCodes.MSP_RX_CONFIG, false, false, nextCallback); - } else { - nextCallback(); - } + MSP.send_message(MSPCodes.MSP_RX_CONFIG, false, false, load_mixer_config); } function load_mixer_config() { @@ -95,32 +85,20 @@ receiver.initialize = function (callback) { // translate to user-selected language i18n.localizePage(); - if (semver.lt(FC.CONFIG.apiVersion, "1.15.0")) { - $('.deadband').hide(); - } else { - $('.deadband input[name="yaw_deadband"]').val(FC.RC_DEADBAND_CONFIG.yaw_deadband); - $('.deadband input[name="deadband"]').val(FC.RC_DEADBAND_CONFIG.deadband); - $('.deadband input[name="3ddeadbandthrottle"]').val(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); - } + $('.deadband input[name="yaw_deadband"]').val(FC.RC_DEADBAND_CONFIG.yaw_deadband); + $('.deadband input[name="deadband"]').val(FC.RC_DEADBAND_CONFIG.deadband); + $('.deadband input[name="3ddeadbandthrottle"]').val(FC.RC_DEADBAND_CONFIG.deadband3d_throttle); - if (semver.lt(FC.CONFIG.apiVersion, "1.15.0")) { - $('.sticks').hide(); - } else { - $('.sticks input[name="stick_min"]').val(FC.RX_CONFIG.stick_min); - $('.sticks input[name="stick_center"]').val(FC.RX_CONFIG.stick_center); - $('.sticks input[name="stick_max"]').val(FC.RX_CONFIG.stick_max); - } + $('.sticks input[name="stick_min"]').val(FC.RX_CONFIG.stick_min); + $('.sticks input[name="stick_center"]').val(FC.RX_CONFIG.stick_center); + $('.sticks input[name="stick_max"]').val(FC.RX_CONFIG.stick_max); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - $('select[name="rcInterpolation-select"]').val(FC.RX_CONFIG.rcInterpolation); - $('input[name="rcInterpolationInterval-number"]').val(FC.RX_CONFIG.rcInterpolationInterval); + $('select[name="rcInterpolation-select"]').val(FC.RX_CONFIG.rcInterpolation); + $('input[name="rcInterpolationInterval-number"]').val(FC.RX_CONFIG.rcInterpolationInterval); - $('select[name="rcInterpolation-select"]').change(function () { - tab.updateRcInterpolationParameters(); - }).change(); - } else { - $('.tab-receiver div.rcInterpolation').hide(); - } + $('select[name="rcInterpolation-select"]').change(function () { + tab.updateRcInterpolationParameters(); + }).change(); // generate bars const bar_names = [ @@ -289,108 +267,96 @@ receiver.initialize = function (callback) { }); } - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) { - const spiRxTypes = [ - 'NRF24_V202_250K', - 'NRF24_V202_1M', - 'NRF24_SYMA_X', - 'NRF24_SYMA_X5C', - 'NRF24_CX10', - 'CX10A', - 'NRF24_H8_3D', - 'NRF24_INAV', - 'FRSKY_D', - ]; + const spiRxTypes = [ + 'NRF24_V202_250K', + 'NRF24_V202_1M', + 'NRF24_SYMA_X', + 'NRF24_SYMA_X5C', + 'NRF24_CX10', + 'CX10A', + 'NRF24_H8_3D', + 'NRF24_INAV', + 'FRSKY_D', + 'FRSKY_X', + 'A7105_FLYSKY', + 'A7105_FLYSKY_2A', + 'NRF24_KN', + 'SFHSS', + 'SPEKTRUM', + 'FRSKY_X_LBT', + ]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_37)) { - spiRxTypes.push( - 'FRSKY_X', - 'A7105_FLYSKY', - 'A7105_FLYSKY_2A', - 'NRF24_KN', - ); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + spiRxTypes.push( + 'REDPINE', + ); + } + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + spiRxTypes.push( + 'FRSKY_X_V2', + 'FRSKY_X_LBT_V2', + 'EXPRESSLRS', + ); + } + + const spiRxElement = $('select.spiRx'); + for (let i = 0; i < spiRxTypes.length; i++) { + spiRxElement.append(``); + } + + spiRxElement.change(function () { + const value = parseInt($(this).val()); + + let newValue = undefined; + if (value !== FC.RX_CONFIG.rxSpiProtocol) { + newValue = $(this).find('option:selected').text(); + updateSaveButton(true); } + tab.analyticsChanges['SPIRXProtocol'] = newValue; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - spiRxTypes.push( - 'SFHSS', - 'SPEKTRUM', - 'FRSKY_X_LBT', - ); - } + FC.RX_CONFIG.rxSpiProtocol = value; + }); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - spiRxTypes.push( - 'REDPINE', - ); - } + // select current serial RX type + spiRxElement.val(FC.RX_CONFIG.rxSpiProtocol); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - spiRxTypes.push( - 'FRSKY_X_V2', - 'FRSKY_X_LBT_V2', - 'EXPRESSLRS', - ); - } - - const spiRxElement = $('select.spiRx'); - for (let i = 0; i < spiRxTypes.length; i++) { - spiRxElement.append(``); - } - - spiRxElement.change(function () { - const value = parseInt($(this).val()); - - let newValue = undefined; - if (value !== FC.RX_CONFIG.rxSpiProtocol) { - newValue = $(this).find('option:selected').text(); - updateSaveButton(true); - } - tab.analyticsChanges['SPIRXProtocol'] = newValue; - - FC.RX_CONFIG.rxSpiProtocol = value; + if (!GUI.isCordova()) { + // Convert to select2 and order alphabetic + spiRxElement.select2({ + sorter(data) { + return data.sort(function(a, b) { + return a.text.localeCompare(b.text); + }); + }, }); + } - // select current serial RX type - spiRxElement.val(FC.RX_CONFIG.rxSpiProtocol); + if (FC.FEATURE_CONFIG.features.isEnabled('RX_SPI') && FC.RX_CONFIG.rxSpiProtocol == 19 && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { + tab.elrsPassphraseEnabled = true; - if (!GUI.isCordova()) { - // Convert to select2 and order alphabetic - spiRxElement.select2({ - sorter(data) { - return data.sort(function(a, b) { - return a.text.localeCompare(b.text); - }); - }, - }); + const elrsUid = $('span.elrsUid'); + const elrsUidString = FC.RX_CONFIG.elrsUid.join(','); + + elrsUid.text(elrsUidString); + + const elrsPassphrase = $('input.elrsPassphrase'); + + const passphraseString = lookup_elrs_passphrase(elrsUidString); + if (passphraseString) { + elrsPassphrase.val(passphraseString); } - - if (FC.FEATURE_CONFIG.features.isEnabled('RX_SPI') && FC.RX_CONFIG.rxSpiProtocol == 19 && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { - tab.elrsPassphraseEnabled = true; - - const elrsUid = $('span.elrsUid'); - const elrsUidString = FC.RX_CONFIG.elrsUid.join(','); - - elrsUid.text(elrsUidString); - - const elrsPassphrase = $('input.elrsPassphrase'); - - const passphraseString = lookup_elrs_passphrase(elrsUidString); - if (passphraseString) { - elrsPassphrase.val(passphraseString); + elrsPassphrase.on('keyup', function() { + const passphrase = elrsPassphrase.val(); + if (passphrase) { + elrsUid.text(elrs_passphrase_to_bytes(passphrase)); + } else { + elrsUid.text("0.0.0.0.0.0"); } - elrsPassphrase.on('keyup', function() { - const passphrase = elrsPassphrase.val(); - if (passphrase) { - elrsUid.text(elrs_passphrase_to_bytes(passphrase)); - } else { - elrsUid.text("0.0.0.0.0.0"); - } - updateSaveButton(true); - }); - } else { - tab.elrsPassphraseEnabled = false; - } + updateSaveButton(true); + }); + } else { + tab.elrsPassphraseEnabled = false; } // UI Hooks @@ -465,14 +431,12 @@ receiver.initialize = function (callback) { function saveConfiguration(boot=false) { - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - FC.RX_CONFIG.stick_max = parseInt($('.sticks input[name="stick_max"]').val()); - FC.RX_CONFIG.stick_center = parseInt($('.sticks input[name="stick_center"]').val()); - FC.RX_CONFIG.stick_min = parseInt($('.sticks input[name="stick_min"]').val()); - FC.RC_DEADBAND_CONFIG.yaw_deadband = parseInt($('.deadband input[name="yaw_deadband"]').val()); - FC.RC_DEADBAND_CONFIG.deadband = parseInt($('.deadband input[name="deadband"]').val()); - FC.RC_DEADBAND_CONFIG.deadband3d_throttle = ($('.deadband input[name="3ddeadbandthrottle"]').val()); - } + FC.RX_CONFIG.stick_max = parseInt($('.sticks input[name="stick_max"]').val()); + FC.RX_CONFIG.stick_center = parseInt($('.sticks input[name="stick_center"]').val()); + FC.RX_CONFIG.stick_min = parseInt($('.sticks input[name="stick_min"]').val()); + FC.RC_DEADBAND_CONFIG.yaw_deadband = parseInt($('.deadband input[name="yaw_deadband"]').val()); + FC.RC_DEADBAND_CONFIG.deadband = parseInt($('.deadband input[name="deadband"]').val()); + FC.RC_DEADBAND_CONFIG.deadband3d_throttle = ($('.deadband input[name="3ddeadbandthrottle"]').val()); // catch rc map rcMapLetters = ['A', 'E', 'R', 'T', '1', '2', '3', '4']; @@ -485,19 +449,14 @@ receiver.initialize = function (callback) { // catch rssi aux FC.RSSI_CONFIG.channel = parseInt($('select[name="rssi_channel"]').val()); + FC.RX_CONFIG.rcInterpolation = parseInt($('select[name="rcInterpolation-select"]').val()); + FC.RX_CONFIG.rcInterpolationInterval = parseInt($('input[name="rcInterpolationInterval-number"]').val()); - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - FC.RX_CONFIG.rcInterpolation = parseInt($('select[name="rcInterpolation-select"]').val()); - FC.RX_CONFIG.rcInterpolationInterval = parseInt($('input[name="rcInterpolationInterval-number"]').val()); - } - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - FC.RX_CONFIG.rcSmoothingSetpointCutoff = parseInt($('input[name="rcSmoothingSetpointHz-number"]').val()); - FC.RX_CONFIG.rcSmoothingFeedforwardCutoff = parseInt($('input[name="rcSmoothingFeedforwardCutoff-number"]').val()); - FC.RX_CONFIG.rcSmoothingDerivativeType = parseInt($('select[name="rcSmoothingFeedforwardType-select"]').val()); - FC.RX_CONFIG.rcInterpolationChannels = parseInt($('select[name="rcSmoothingChannels-select"]').val()); - FC.RX_CONFIG.rcSmoothingInputType = parseInt($('select[name="rcSmoothingSetpointType-select"]').val()); - } + FC.RX_CONFIG.rcSmoothingSetpointCutoff = parseInt($('input[name="rcSmoothingSetpointHz-number"]').val()); + FC.RX_CONFIG.rcSmoothingFeedforwardCutoff = parseInt($('input[name="rcSmoothingFeedforwardCutoff-number"]').val()); + FC.RX_CONFIG.rcSmoothingDerivativeType = parseInt($('select[name="rcSmoothingFeedforwardType-select"]').val()); + FC.RX_CONFIG.rcInterpolationChannels = parseInt($('select[name="rcSmoothingChannels-select"]').val()); + FC.RX_CONFIG.rcSmoothingInputType = parseInt($('select[name="rcSmoothingSetpointType-select"]').val()); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { FC.RX_CONFIG.rcSmoothingAutoFactor = parseInt($('input[name="rcSmoothingAutoFactor-number"]').val()); @@ -521,21 +480,12 @@ receiver.initialize = function (callback) { } function save_rc_configs() { - const nextCallback = save_rx_config; - if (semver.gte(FC.CONFIG.apiVersion, "1.15.0")) { - MSP.send_message(MSPCodes.MSP_SET_RC_DEADBAND, mspHelper.crunch(MSPCodes.MSP_SET_RC_DEADBAND), false, nextCallback); - } else { - nextCallback(); - } + MSP.send_message(MSPCodes.MSP_SET_RC_DEADBAND, mspHelper.crunch(MSPCodes.MSP_SET_RC_DEADBAND), false, save_rx_config); } function save_rx_config() { const nextCallback = (boot) ? save_feature_config : save_to_eeprom; - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - MSP.send_message(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG), false, nextCallback); - } else { - nextCallback(); - } + MSP.send_message(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG), false, nextCallback); } function save_feature_config() { @@ -613,105 +563,92 @@ receiver.initialize = function (callback) { $(".bind_btn").toggle(showBindButton); // RC Smoothing - const smoothingOnOff = ((semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) ? - FC.RX_CONFIG.rcSmoothingMode : FC.RX_CONFIG.rcSmoothingType); + const smoothingOnOff = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44) ? FC.RX_CONFIG.rcSmoothingMode : FC.RX_CONFIG.rcSmoothingType; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - $('.tab-receiver .rcSmoothing').show(); - - const rc_smoothing_protocol_e = $('select[name="rcSmoothing-select"]'); - rc_smoothing_protocol_e.change(function () { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - FC.RX_CONFIG.rcSmoothingMode = parseFloat($(this).val()); - } else { - FC.RX_CONFIG.rcSmoothingType = parseFloat($(this).val()); - } - updateInterpolationView(); - }); - rc_smoothing_protocol_e.val(smoothingOnOff); - - const rcSmoothingNumberElement = $('input[name="rcSmoothingSetpointHz-number"]'); - const rcSmoothingFeedforwardNumberElement = $('input[name="rcSmoothingFeedforwardCutoff-number"]'); - rcSmoothingNumberElement.val(FC.RX_CONFIG.rcSmoothingSetpointCutoff); - rcSmoothingFeedforwardNumberElement.val(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff); - $('.tab-receiver .rcSmoothing-setpoint-cutoff').show(); - $('select[name="rcSmoothing-setpoint-manual-select"]').val("1"); - if (FC.RX_CONFIG.rcSmoothingSetpointCutoff === 0) { - $('.tab-receiver .rcSmoothing-setpoint-cutoff').hide(); - $('select[name="rcSmoothing-setpoint-manual-select"]').val("0"); - } - $('select[name="rcSmoothing-setpoint-manual-select"]').change(function () { - if ($(this).val() === "0") { - rcSmoothingNumberElement.val(0); - $('.tab-receiver .rcSmoothing-setpoint-cutoff').hide(); - } - if ($(this).val() === "1") { - rcSmoothingNumberElement.val(FC.RX_CONFIG.rcSmoothingSetpointCutoff); - $('.tab-receiver .rcSmoothing-setpoint-cutoff').show(); - } - }).change(); - - $('.tab-receiver .rcSmoothing-feedforward-cutoff').show(); - $('select[name="rcSmoothing-feedforward-select"]').val("1"); - if (FC.RX_CONFIG.rcSmoothingFeedforwardCutoff === 0) { - $('select[name="rcSmoothing-feedforward-select"]').val("0"); - $('.tab-receiver .rcSmoothing-feedforward-cutoff').hide(); - } - $('select[name="rcSmoothing-feedforward-select"]').change(function () { - if ($(this).val() === "0") { - $('.tab-receiver .rcSmoothing-feedforward-cutoff').hide(); - rcSmoothingFeedforwardNumberElement.val(0); - } - if ($(this).val() === "1") { - $('.tab-receiver .rcSmoothing-feedforward-cutoff').show(); - rcSmoothingFeedforwardNumberElement.val(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff); - } - }).change(); - - const rcSmoothingFeedforwardType = $('select[name="rcSmoothingFeedforwardType-select"]'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { - rcSmoothingFeedforwardType.append($(``)); - } - - rcSmoothingFeedforwardType.val(FC.RX_CONFIG.rcSmoothingDerivativeType); - const rcSmoothingChannels = $('select[name="rcSmoothingChannels-select"]'); - rcSmoothingChannels.val(FC.RX_CONFIG.rcInterpolationChannels); - const rcSmoothingSetpointType = $('select[name="rcSmoothingSetpointType-select"]'); - rcSmoothingSetpointType.val(FC.RX_CONFIG.rcSmoothingInputType); - - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { - $('select[name="rcSmoothing-setpoint-manual-select"], select[name="rcSmoothing-feedforward-select"]').change(function() { - if ($('select[name="rcSmoothing-setpoint-manual-select"]').val() === "0" || $('select[name="rcSmoothing-feedforward-select"]').val() === "0") { - $('.tab-receiver .rcSmoothing-auto-factor').show(); - } else { - $('.tab-receiver .rcSmoothing-auto-factor').hide(); - } - }); - $('select[name="rcSmoothing-setpoint-manual-select"]').change(); - - const rcSmoothingAutoFactor = $('input[name="rcSmoothingAutoFactor-number"]'); - rcSmoothingAutoFactor.val(FC.RX_CONFIG.rcSmoothingAutoFactor); - } else { - $('.tab-receiver .rcSmoothing-auto-factor').hide(); - } + $('.tab-receiver .rcSmoothing').show(); + const rc_smoothing_protocol_e = $('select[name="rcSmoothing-select"]'); + rc_smoothing_protocol_e.change(function () { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { - $('.receiverRcSmoothingAutoFactorHelp').attr('title', i18n.getMessage("receiverRcSmoothingAutoFactorHelp2")); + FC.RX_CONFIG.rcSmoothingMode = parseFloat($(this).val()); + } else { + FC.RX_CONFIG.rcSmoothingType = parseFloat($(this).val()); } - updateInterpolationView(); - } else { - $('.tab-receiver .rcInterpolation').show(); - $('.tab-receiver .rcSmoothing-feedforward-cutoff').hide(); + }); + rc_smoothing_protocol_e.val(smoothingOnOff); + + const rcSmoothingNumberElement = $('input[name="rcSmoothingSetpointHz-number"]'); + const rcSmoothingFeedforwardNumberElement = $('input[name="rcSmoothingFeedforwardCutoff-number"]'); + rcSmoothingNumberElement.val(FC.RX_CONFIG.rcSmoothingSetpointCutoff); + rcSmoothingFeedforwardNumberElement.val(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff); + $('.tab-receiver .rcSmoothing-setpoint-cutoff').show(); + $('select[name="rcSmoothing-setpoint-manual-select"]').val("1"); + if (FC.RX_CONFIG.rcSmoothingSetpointCutoff === 0) { $('.tab-receiver .rcSmoothing-setpoint-cutoff').hide(); - $('.tab-receiver .rcSmoothing-feedforward-type').hide(); - $('.tab-receiver .rcSmoothing-setpoint-type').hide(); - $('.tab-receiver .rcSmoothing-feedforward-manual').hide(); - $('.tab-receiver .rcSmoothing-setpoint-manual').hide(); - $('.tab-receiver .rc-smoothing-type').hide(); + $('select[name="rcSmoothing-setpoint-manual-select"]').val("0"); + } + $('select[name="rcSmoothing-setpoint-manual-select"]').change(function () { + if ($(this).val() === "0") { + rcSmoothingNumberElement.val(0); + $('.tab-receiver .rcSmoothing-setpoint-cutoff').hide(); + } + if ($(this).val() === "1") { + rcSmoothingNumberElement.val(FC.RX_CONFIG.rcSmoothingSetpointCutoff); + $('.tab-receiver .rcSmoothing-setpoint-cutoff').show(); + } + }).change(); + + $('.tab-receiver .rcSmoothing-feedforward-cutoff').show(); + $('select[name="rcSmoothing-feedforward-select"]').val("1"); + if (FC.RX_CONFIG.rcSmoothingFeedforwardCutoff === 0) { + $('select[name="rcSmoothing-feedforward-select"]').val("0"); + $('.tab-receiver .rcSmoothing-feedforward-cutoff').hide(); + } + $('select[name="rcSmoothing-feedforward-select"]').change(function () { + if ($(this).val() === "0") { + $('.tab-receiver .rcSmoothing-feedforward-cutoff').hide(); + rcSmoothingFeedforwardNumberElement.val(0); + } + if ($(this).val() === "1") { + $('.tab-receiver .rcSmoothing-feedforward-cutoff').show(); + rcSmoothingFeedforwardNumberElement.val(FC.RX_CONFIG.rcSmoothingFeedforwardCutoff); + } + }).change(); + + const rcSmoothingFeedforwardType = $('select[name="rcSmoothingFeedforwardType-select"]'); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { + rcSmoothingFeedforwardType.append($(``)); + } + + rcSmoothingFeedforwardType.val(FC.RX_CONFIG.rcSmoothingDerivativeType); + const rcSmoothingChannels = $('select[name="rcSmoothingChannels-select"]'); + rcSmoothingChannels.val(FC.RX_CONFIG.rcInterpolationChannels); + const rcSmoothingSetpointType = $('select[name="rcSmoothingSetpointType-select"]'); + rcSmoothingSetpointType.val(FC.RX_CONFIG.rcSmoothingInputType); + + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { + $('select[name="rcSmoothing-setpoint-manual-select"], select[name="rcSmoothing-feedforward-select"]').change(function() { + if ($('select[name="rcSmoothing-setpoint-manual-select"]').val() === "0" || $('select[name="rcSmoothing-feedforward-select"]').val() === "0") { + $('.tab-receiver .rcSmoothing-auto-factor').show(); + } else { + $('.tab-receiver .rcSmoothing-auto-factor').hide(); + } + }); + $('select[name="rcSmoothing-setpoint-manual-select"]').change(); + + const rcSmoothingAutoFactor = $('input[name="rcSmoothingAutoFactor-number"]'); + rcSmoothingAutoFactor.val(FC.RX_CONFIG.rcSmoothingAutoFactor); + } else { $('.tab-receiver .rcSmoothing-auto-factor').hide(); } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) { + $('.receiverRcSmoothingAutoFactorHelp').attr('title', i18n.getMessage("receiverRcSmoothingAutoFactorHelp2")); + } + + updateInterpolationView(); + // Only show the MSP control sticks if the MSP Rx feature is enabled $(".sticks_btn").toggle(FC.FEATURE_CONFIG.features.isEnabled('RX_MSP')); @@ -888,15 +825,7 @@ receiver.initModelPreview = function () { this.keepRendering = true; this.model = new Model($('.model_preview'), $('.model_preview canvas')); - let useOldRateCurve = false; - const cleanFlight = FC.CONFIG.flightControllerIdentifier === 'CLFL' && semver.lt(FC.CONFIG.apiVersion, '2.0.0'); - const betaFlight = FC.CONFIG.flightControllerIdentifier === 'BTFL' && semver.lt(FC.CONFIG.flightControllerVersion, '2.8.0'); - - if (cleanFlight || betaFlight) { - useOldRateCurve = true; - } - - this.rateCurve = new RateCurve(useOldRateCurve); + this.rateCurve = new RateCurve(false); this.currentRates = this.rateCurve.getCurrentRates(); $(window).on('resize', $.bind(this.model.resize, this.model)); @@ -946,12 +875,10 @@ receiver.refresh = function (callback) { }; receiver.updateRcInterpolationParameters = function () { - if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) { - if ($('select[name="rcInterpolation-select"]').val() === '3') { - $('.tab-receiver .rc-interpolation-manual').show(); - } else { - $('.tab-receiver .rc-interpolation-manual').hide(); - } + if ($('select[name="rcInterpolation-select"]').val() === '3') { + $('.tab-receiver .rc-interpolation-manual').show(); + } else { + $('.tab-receiver .rc-interpolation-manual').hide(); } }; diff --git a/src/js/tabs/sensors.js b/src/js/tabs/sensors.js index 3f2734ce..bf6fdf63 100644 --- a/src/js/tabs/sensors.js +++ b/src/js/tabs/sensors.js @@ -193,7 +193,7 @@ sensors.initialize = function (callback) { if (!have_sensor(FC.CONFIG.activeSensors, 'mag')) { checkboxes.eq(2).prop('disabled', true); } - if (!(have_sensor(FC.CONFIG.activeSensors, 'baro') || (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40) && have_sensor(FC.CONFIG.activeSensors, 'gps')))) { + if (!(have_sensor(FC.CONFIG.activeSensors, 'baro') || have_sensor(FC.CONFIG.activeSensors, 'gps'))) { checkboxes.eq(3).prop('disabled', true); } if (!have_sensor(FC.CONFIG.activeSensors, 'sonar')) { @@ -241,11 +241,6 @@ sensors.initialize = function (callback) { ConfigStorage.set({'graphs_enabled': _checkboxes}); }); - let altitudeHint_e = $('.tab-sensors #sensorsAltitudeHint'); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - altitudeHint_e.hide(); - } - // Always start with default/empty sensor data array, clean slate all initSensorData(); diff --git a/src/js/tabs/servos.js b/src/js/tabs/servos.js index 6b877e92..21608105 100644 --- a/src/js/tabs/servos.js +++ b/src/js/tabs/servos.js @@ -30,7 +30,7 @@ servos.initialize = function (callback) { function update_ui() { - if (semver.lt(FC.CONFIG.apiVersion, "1.12.0") || FC.SERVO_CONFIG.length === 0) { + if (FC.SERVO_CONFIG.length === 0) { $(".tab-servos").removeClass("supported"); return; diff --git a/src/js/tabs/setup.js b/src/js/tabs/setup.js index 7a119b86..0a86099c 100644 --- a/src/js/tabs/setup.js +++ b/src/js/tabs/setup.js @@ -29,34 +29,6 @@ setup.initialize = function (callback) { // translate to user-selected language i18n.localizePage(); - const backupButton = $('#content .backup'); - const restoreButton = $('#content .restore'); - - backupButton.on('click', () => configuration_backup(() => GUI.log(i18n.getMessage('initialSetupBackupSuccess')))); - - restoreButton.on('click', () => configuration_restore(() => { - // get latest settings - TABS.setup.initialize(); - - GUI.log(i18n.getMessage('initialSetupRestoreSuccess')); - })); - - if (semver.lt(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_MIN_SUPPORTED_BACKUP_RESTORE)) { - backupButton.addClass('disabled'); - restoreButton.addClass('disabled'); - - GUI.log(i18n.getMessage('initialSetupBackupAndRestoreApiVersion', [FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_MIN_SUPPORTED_BACKUP_RESTORE])); - } - - if (CONFIGURATOR.virtualMode) { - // saving and uploading an imaginary config to hardware is a bad idea - backupButton.addClass('disabled'); - } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - restoreButton.addClass('disabled'); - - $('.backupRestore').hide(); - } - // initialize 3D Model self.initModel(); @@ -82,22 +54,18 @@ setup.initialize = function (callback) { $('#arming-disable-flag').attr('title', i18n.getMessage('initialSetupArmingDisableFlagsTooltip')); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { - if (isExpertModeEnabled()) { - $('.initialSetupRebootBootloader').show(); - } else { - $('.initialSetupRebootBootloader').hide(); - } - - $('a.rebootBootloader').click(function () { - const buffer = []; - buffer.push(FC.boardHasFlashBootloader() ? mspHelper.REBOOT_TYPES.BOOTLOADER_FLASH : mspHelper.REBOOT_TYPES.BOOTLOADER); - MSP.send_message(MSPCodes.MSP_SET_REBOOT, buffer, false); - }); + if (isExpertModeEnabled()) { + $('.initialSetupRebootBootloader').show(); } else { $('.initialSetupRebootBootloader').hide(); } + $('a.rebootBootloader').click(function () { + const buffer = []; + buffer.push(FC.boardHasFlashBootloader() ? mspHelper.REBOOT_TYPES.BOOTLOADER_FLASH : mspHelper.REBOOT_TYPES.BOOTLOADER); + MSP.send_message(MSPCodes.MSP_SET_REBOOT, buffer, false); + }); + // UI Hooks $('a.calibrateAccel').click(function () { const _self = $(this); @@ -192,9 +160,7 @@ setup.initialize = function (callback) { pitch_e = $('dd.pitch'), heading_e = $('dd.heading'); - if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_36)) { - arming_disable_flags_e.hide(); - } + arming_disable_flags_e.hide(); // DISARM FLAGS // We add all the arming/disarming flags available, and show/hide them if needed. @@ -219,25 +185,20 @@ setup.initialize = function (callback) { 'MSP', ]; - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_38)) { - disarmFlagElements.splice(disarmFlagElements.indexOf('THROTTLE'), 0, 'RUNAWAY_TAKEOFF'); - } + disarmFlagElements.splice(disarmFlagElements.indexOf('THROTTLE'), 0, 'RUNAWAY_TAKEOFF'); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) { - disarmFlagElements = disarmFlagElements.concat(['PARALYZE', - 'GPS']); - } + disarmFlagElements = disarmFlagElements.concat(['PARALYZE', 'GPS']); + + disarmFlagElements.splice(disarmFlagElements.indexOf('OSD_MENU'), 1); + disarmFlagElements = disarmFlagElements.concat(['RESC']); + disarmFlagElements = disarmFlagElements.concat(['RPMFILTER']); - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { - disarmFlagElements.splice(disarmFlagElements.indexOf('OSD_MENU'), 1); - disarmFlagElements = disarmFlagElements.concat(['RESC']); - disarmFlagElements = disarmFlagElements.concat(['RPMFILTER']); - } if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { disarmFlagElements.splice(disarmFlagElements.indexOf('THROTTLE'), 0, 'CRASH'); disarmFlagElements = disarmFlagElements.concat(['REBOOT_REQD', 'DSHOT_BBANG']); } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_43)) { disarmFlagElements = disarmFlagElements.concat(['NO_ACC_CAL', 'MOTOR_PROTO']); } diff --git a/src/js/tabs/transponder.js b/src/js/tabs/transponder.js index fcc5e902..37c07924 100644 --- a/src/js/tabs/transponder.js +++ b/src/js/tabs/transponder.js @@ -108,14 +108,13 @@ transponder.initialize = function(callback) { }; ///////////////////////////////////////////// - if ( GUI.active_tab != 'transponder' ) { - GUI.active_tab = 'transponder'; - // Disabled on merge into betaflight-configurator - //googleAnalytics.sendAppView('Transponder'); - } + GUI.active_tab = 'transponder'; + // Disabled on merge into betaflight-configurator + //googleAnalytics.sendAppView('Transponder'); + // transponder supported added in MSP API Version 1.16.0 - if ( FC.CONFIG ) { - TABS.transponder.available = semver.gte(FC.CONFIG.apiVersion, "1.16.0"); + if (FC.CONFIG) { + TABS.transponder.available = true; } ////////////// if ( !TABS.transponder.available ) { diff --git a/src/main.html b/src/main.html index 7d6cc806..1cdf5aa5 100644 --- a/src/main.html +++ b/src/main.html @@ -102,7 +102,6 @@ - diff --git a/src/tabs/sensors.html b/src/tabs/sensors.html index 1b3d731c..af3fc2fd 100644 --- a/src/tabs/sensors.html +++ b/src/tabs/sensors.html @@ -49,6 +49,9 @@ + + + diff --git a/src/tabs/setup.html b/src/tabs/setup.html index e28808c4..1aa05956 100644 --- a/src/tabs/setup.html +++ b/src/tabs/setup.html @@ -152,22 +152,6 @@
-
-
-
-
-
-
- -
-
- -
-
- -
-
-